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 ,
5
6
} ;
6
7
use if_chain:: if_chain;
7
8
use rustc_data_structures:: fx:: FxHashSet ;
@@ -141,7 +142,7 @@ declare_clippy_lint! {
141
142
/// 42
142
143
/// };
143
144
/// ```
144
- pub SHARED_CODE_IN_IF_BLOCKS ,
145
+ pub BRANCHES_SHARING_CODE ,
145
146
complexity,
146
147
"`if` statement with shared code in all blocks"
147
148
}
@@ -150,7 +151,7 @@ declare_lint_pass!(CopyAndPaste => [
150
151
IFS_SAME_COND ,
151
152
SAME_FUNCTIONS_IN_IF_CONDITION ,
152
153
IF_SAME_THEN_ELSE ,
153
- SHARED_CODE_IN_IF_BLOCKS
154
+ BRANCHES_SHARING_CODE
154
155
] ) ;
155
156
156
157
impl < ' tcx > LateLintPass < ' tcx > for CopyAndPaste {
@@ -173,17 +174,17 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
173
174
lint_same_cond ( cx, & conds) ;
174
175
lint_same_fns_in_if_cond ( cx, & conds) ;
175
176
// 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) ;
177
178
}
178
179
}
179
180
}
180
181
}
181
182
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.
183
184
fn lint_same_then_else < ' tcx > (
184
185
cx : & LateContext < ' tcx > ,
185
186
blocks : & [ & Block < ' tcx > ] ,
186
- has_unconditional_else : bool ,
187
+ has_conditional_else : bool ,
187
188
expr : & ' tcx Expr < ' _ > ,
188
189
) {
189
190
// We only lint ifs with multiple blocks
@@ -195,8 +196,8 @@ fn lint_same_then_else<'tcx>(
195
196
let has_expr = blocks[ 0 ] . expr . is_some ( ) ;
196
197
let ( start_eq, mut end_eq, expr_eq) = scan_block_for_eq ( cx, blocks) ;
197
198
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) ) {
200
201
return ;
201
202
}
202
203
@@ -210,7 +211,7 @@ fn lint_same_then_else<'tcx>(
210
211
intravisit:: walk_stmt ( & mut start_walker, stmt) ;
211
212
}
212
213
213
- emit_shared_code_in_if_blocks_lint (
214
+ emit_branches_sharing_code_lint (
214
215
cx,
215
216
start_eq,
216
217
0 ,
@@ -277,7 +278,7 @@ fn lint_same_then_else<'tcx>(
277
278
} ) ;
278
279
}
279
280
280
- emit_shared_code_in_if_blocks_lint (
281
+ emit_branches_sharing_code_lint (
281
282
cx,
282
283
start_eq,
283
284
end_eq,
@@ -298,7 +299,7 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> (usize,
298
299
let r_stmts = win[ 1 ] . stmts ;
299
300
300
301
// `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.
302
303
let mut evaluator = SpanlessEq :: new ( cx) ;
303
304
let mut evaluator = evaluator. inter_expr ( ) ;
304
305
@@ -387,7 +388,7 @@ fn check_for_warn_of_moved_symbol(
387
388
} )
388
389
}
389
390
390
- fn emit_shared_code_in_if_blocks_lint (
391
+ fn emit_branches_sharing_code_lint (
391
392
cx : & LateContext < ' tcx > ,
392
393
start_stmts : usize ,
393
394
end_stmts : usize ,
@@ -472,7 +473,7 @@ fn emit_shared_code_in_if_blocks_lint(
472
473
let ( place_str, span, sugg) = suggestions. pop ( ) . unwrap ( ) ;
473
474
let msg = format ! ( "all if blocks contain the same code at the {}" , place_str) ;
474
475
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| {
476
477
diag. span_suggestion ( span, help. as_str ( ) , sugg, Applicability :: Unspecified ) ;
477
478
478
479
add_optional_msgs ( diag) ;
@@ -482,7 +483,7 @@ fn emit_shared_code_in_if_blocks_lint(
482
483
let ( _, start_span, start_sugg) = suggestions. pop ( ) . unwrap ( ) ;
483
484
span_lint_and_then (
484
485
cx,
485
- SHARED_CODE_IN_IF_BLOCKS ,
486
+ BRANCHES_SHARING_CODE ,
486
487
start_span,
487
488
"all if blocks contain the same code at the start and the end. Here at the start" ,
488
489
move |diag| {
0 commit comments