1- use crate :: utils:: {
2- both, count_eq, eq_expr_value, first_line_of_span, get_enclosing_block, get_parent_expr, if_sequence, in_macro,
3- indent_of, parent_node_is_if_expr, reindent_multiline, run_lints, search_same, snippet, snippet_opt,
4- span_lint_and_note, span_lint_and_then, ContainsName , SpanlessEq , SpanlessHash ,
1+ use clippy_utils:: diagnostics:: { span_lint_and_note, span_lint_and_then} ;
2+ use clippy_utils:: source:: { first_line_of_span, indent_of, reindent_multiline, snippet, snippet_opt} ;
3+ use clippy_utils:: {
4+ both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, parent_node_is_if_expr,
5+ run_lints, search_same, ContainsName , SpanlessEq , SpanlessHash ,
56} ;
67use if_chain:: if_chain;
78use rustc_data_structures:: fx:: FxHashSet ;
@@ -141,7 +142,7 @@ declare_clippy_lint! {
141142 /// 42
142143 /// };
143144 /// ```
144- pub SHARED_CODE_IN_IF_BLOCKS ,
145+ pub BRANCHES_SHARING_CODE ,
145146 complexity,
146147 "`if` statement with shared code in all blocks"
147148}
@@ -150,7 +151,7 @@ declare_lint_pass!(CopyAndPaste => [
150151 IFS_SAME_COND ,
151152 SAME_FUNCTIONS_IN_IF_CONDITION ,
152153 IF_SAME_THEN_ELSE ,
153- SHARED_CODE_IN_IF_BLOCKS
154+ BRANCHES_SHARING_CODE
154155] ) ;
155156
156157impl < ' tcx > LateLintPass < ' tcx > for CopyAndPaste {
@@ -173,17 +174,17 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
173174 lint_same_cond ( cx, & conds) ;
174175 lint_same_fns_in_if_cond ( cx, & conds) ;
175176 // Block duplication
176- lint_same_then_else ( cx, & blocks, conds. len ( ) ! = blocks. len ( ) , expr) ;
177+ lint_same_then_else ( cx, & blocks, conds. len ( ) = = blocks. len ( ) , expr) ;
177178 }
178179 }
179180 }
180181}
181182
182- /// Implementation of `SHARED_CODE_IN_IF_BLOCKS ` and `IF_SAME_THEN_ELSE` if the blocks are equal.
183+ /// Implementation of `BRANCHES_SHARING_CODE ` and `IF_SAME_THEN_ELSE` if the blocks are equal.
183184fn lint_same_then_else < ' tcx > (
184185 cx : & LateContext < ' tcx > ,
185186 blocks : & [ & Block < ' tcx > ] ,
186- has_unconditional_else : bool ,
187+ has_conditional_else : bool ,
187188 expr : & ' tcx Expr < ' _ > ,
188189) {
189190 // We only lint ifs with multiple blocks
@@ -195,8 +196,8 @@ fn lint_same_then_else<'tcx>(
195196 let has_expr = blocks[ 0 ] . expr . is_some ( ) ;
196197 let ( start_eq, mut end_eq, expr_eq) = scan_block_for_eq ( cx, blocks) ;
197198
198- // SHARED_CODE_IN_IF_BLOCKS prerequisites
199- if !has_unconditional_else || ( start_eq == 0 && end_eq == 0 && ( has_expr && !expr_eq) ) {
199+ // BRANCHES_SHARING_CODE prerequisites
200+ if has_conditional_else || ( start_eq == 0 && end_eq == 0 && ( has_expr && !expr_eq) ) {
200201 return ;
201202 }
202203
@@ -210,7 +211,7 @@ fn lint_same_then_else<'tcx>(
210211 intravisit:: walk_stmt ( & mut start_walker, stmt) ;
211212 }
212213
213- emit_shared_code_in_if_blocks_lint (
214+ emit_branches_sharing_code_lint (
214215 cx,
215216 start_eq,
216217 0 ,
@@ -277,7 +278,7 @@ fn lint_same_then_else<'tcx>(
277278 } ) ;
278279 }
279280
280- emit_shared_code_in_if_blocks_lint (
281+ emit_branches_sharing_code_lint (
281282 cx,
282283 start_eq,
283284 end_eq,
@@ -298,7 +299,7 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> (usize,
298299 let r_stmts = win[ 1 ] . stmts ;
299300
300301 // `SpanlessEq` now keeps track of the locals and is therefore context sensitive clippy#6752.
301- // The comparison therefor needs to be done in a way that builds the correct context.
302+ // The comparison therefore needs to be done in a way that builds the correct context.
302303 let mut evaluator = SpanlessEq :: new ( cx) ;
303304 let mut evaluator = evaluator. inter_expr ( ) ;
304305
@@ -387,7 +388,7 @@ fn check_for_warn_of_moved_symbol(
387388 } )
388389}
389390
390- fn emit_shared_code_in_if_blocks_lint (
391+ fn emit_branches_sharing_code_lint (
391392 cx : & LateContext < ' tcx > ,
392393 start_stmts : usize ,
393394 end_stmts : usize ,
@@ -472,7 +473,7 @@ fn emit_shared_code_in_if_blocks_lint(
472473 let ( place_str, span, sugg) = suggestions. pop ( ) . unwrap ( ) ;
473474 let msg = format ! ( "all if blocks contain the same code at the {}" , place_str) ;
474475 let help = format ! ( "consider moving the {} statements out like this" , place_str) ;
475- span_lint_and_then ( cx, SHARED_CODE_IN_IF_BLOCKS , span, msg. as_str ( ) , |diag| {
476+ span_lint_and_then ( cx, BRANCHES_SHARING_CODE , span, msg. as_str ( ) , |diag| {
476477 diag. span_suggestion ( span, help. as_str ( ) , sugg, Applicability :: Unspecified ) ;
477478
478479 add_optional_msgs ( diag) ;
@@ -482,7 +483,7 @@ fn emit_shared_code_in_if_blocks_lint(
482483 let ( _, start_span, start_sugg) = suggestions. pop ( ) . unwrap ( ) ;
483484 span_lint_and_then (
484485 cx,
485- SHARED_CODE_IN_IF_BLOCKS ,
486+ BRANCHES_SHARING_CODE ,
486487 start_span,
487488 "all if blocks contain the same code at the start and the end. Here at the start" ,
488489 move |diag| {
0 commit comments