Renaming the lint to branches_sharing_code and fixing typos

This commit is contained in:
xFrednet
2021-04-01 18:30:47 +02:00
parent 7c9e192e05
commit a6f54f5dfd
22 changed files with 71 additions and 69 deletions

View File

@@ -2129,6 +2129,7 @@ Released 2018-09-13
[`borrowed_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box [`borrowed_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box
[`box_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_vec [`box_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_vec
[`boxed_local`]: https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local [`boxed_local`]: https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local
[`branches_sharing_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code
[`builtin_type_shadow`]: https://rust-lang.github.io/rust-clippy/master/index.html#builtin_type_shadow [`builtin_type_shadow`]: https://rust-lang.github.io/rust-clippy/master/index.html#builtin_type_shadow
[`bytes_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#bytes_nth [`bytes_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#bytes_nth
[`cargo_common_metadata`]: https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata [`cargo_common_metadata`]: https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata
@@ -2455,7 +2456,6 @@ Released 2018-09-13
[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse [`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse
[`shadow_same`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_same [`shadow_same`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_same
[`shadow_unrelated`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated [`shadow_unrelated`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated
[`shared_code_in_if_blocks`]: https://rust-lang.github.io/rust-clippy/master/index.html#shared_code_in_if_blocks
[`short_circuit_statement`]: https://rust-lang.github.io/rust-clippy/master/index.html#short_circuit_statement [`short_circuit_statement`]: https://rust-lang.github.io/rust-clippy/master/index.html#short_circuit_statement
[`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq [`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq
[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait [`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait

View File

@@ -1,7 +1,8 @@
use crate::utils::{ use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_then};
both, count_eq, eq_expr_value, first_line_of_span, get_enclosing_block, get_parent_expr, if_sequence, in_macro, use clippy_utils::source::{first_line_of_span, indent_of, reindent_multiline, snippet, snippet_opt};
indent_of, parent_node_is_if_expr, reindent_multiline, run_lints, search_same, snippet, snippet_opt, use clippy_utils::{
span_lint_and_note, span_lint_and_then, ContainsName, SpanlessEq, SpanlessHash, both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, parent_node_is_if_expr,
run_lints, search_same, ContainsName, SpanlessEq, SpanlessHash,
}; };
use if_chain::if_chain; use if_chain::if_chain;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
@@ -141,7 +142,7 @@ declare_clippy_lint! {
/// 42 /// 42
/// }; /// };
/// ``` /// ```
pub SHARED_CODE_IN_IF_BLOCKS, pub BRANCHES_SHARING_CODE,
complexity, complexity,
"`if` statement with shared code in all blocks" "`if` statement with shared code in all blocks"
} }
@@ -150,7 +151,7 @@ declare_lint_pass!(CopyAndPaste => [
IFS_SAME_COND, IFS_SAME_COND,
SAME_FUNCTIONS_IN_IF_CONDITION, SAME_FUNCTIONS_IN_IF_CONDITION,
IF_SAME_THEN_ELSE, IF_SAME_THEN_ELSE,
SHARED_CODE_IN_IF_BLOCKS BRANCHES_SHARING_CODE
]); ]);
impl<'tcx> LateLintPass<'tcx> for CopyAndPaste { impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
@@ -173,17 +174,17 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
lint_same_cond(cx, &conds); lint_same_cond(cx, &conds);
lint_same_fns_in_if_cond(cx, &conds); lint_same_fns_in_if_cond(cx, &conds);
// Block duplication // Block duplication
lint_same_then_else(cx, &blocks, conds.len() != blocks.len(), expr); lint_same_then_else(cx, &blocks, conds.len() == blocks.len(), expr);
} }
} }
} }
} }
/// Implementation of `SHARED_CODE_IN_IF_BLOCKS` and `IF_SAME_THEN_ELSE` if the blocks are equal. /// Implementation of `BRANCHES_SHARING_CODE` and `IF_SAME_THEN_ELSE` if the blocks are equal.
fn lint_same_then_else<'tcx>( fn lint_same_then_else<'tcx>(
cx: &LateContext<'tcx>, cx: &LateContext<'tcx>,
blocks: &[&Block<'tcx>], blocks: &[&Block<'tcx>],
has_unconditional_else: bool, has_conditional_else: bool,
expr: &'tcx Expr<'_>, expr: &'tcx Expr<'_>,
) { ) {
// We only lint ifs with multiple blocks // We only lint ifs with multiple blocks
@@ -195,8 +196,8 @@ fn lint_same_then_else<'tcx>(
let has_expr = blocks[0].expr.is_some(); let has_expr = blocks[0].expr.is_some();
let (start_eq, mut end_eq, expr_eq) = scan_block_for_eq(cx, blocks); let (start_eq, mut end_eq, expr_eq) = scan_block_for_eq(cx, blocks);
// SHARED_CODE_IN_IF_BLOCKS prerequisites // BRANCHES_SHARING_CODE prerequisites
if !has_unconditional_else || (start_eq == 0 && end_eq == 0 && (has_expr && !expr_eq)) { if has_conditional_else || (start_eq == 0 && end_eq == 0 && (has_expr && !expr_eq)) {
return; return;
} }
@@ -210,7 +211,7 @@ fn lint_same_then_else<'tcx>(
intravisit::walk_stmt(&mut start_walker, stmt); intravisit::walk_stmt(&mut start_walker, stmt);
} }
emit_shared_code_in_if_blocks_lint( emit_branches_sharing_code_lint(
cx, cx,
start_eq, start_eq,
0, 0,
@@ -277,7 +278,7 @@ fn lint_same_then_else<'tcx>(
}); });
} }
emit_shared_code_in_if_blocks_lint( emit_branches_sharing_code_lint(
cx, cx,
start_eq, start_eq,
end_eq, end_eq,
@@ -298,7 +299,7 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> (usize,
let r_stmts = win[1].stmts; let r_stmts = win[1].stmts;
// `SpanlessEq` now keeps track of the locals and is therefore context sensitive clippy#6752. // `SpanlessEq` now keeps track of the locals and is therefore context sensitive clippy#6752.
// The comparison therefor needs to be done in a way that builds the correct context. // The comparison therefore needs to be done in a way that builds the correct context.
let mut evaluator = SpanlessEq::new(cx); let mut evaluator = SpanlessEq::new(cx);
let mut evaluator = evaluator.inter_expr(); let mut evaluator = evaluator.inter_expr();
@@ -387,7 +388,7 @@ fn check_for_warn_of_moved_symbol(
}) })
} }
fn emit_shared_code_in_if_blocks_lint( fn emit_branches_sharing_code_lint(
cx: &LateContext<'tcx>, cx: &LateContext<'tcx>,
start_stmts: usize, start_stmts: usize,
end_stmts: usize, end_stmts: usize,
@@ -472,7 +473,7 @@ fn emit_shared_code_in_if_blocks_lint(
let (place_str, span, sugg) = suggestions.pop().unwrap(); let (place_str, span, sugg) = suggestions.pop().unwrap();
let msg = format!("all if blocks contain the same code at the {}", place_str); let msg = format!("all if blocks contain the same code at the {}", place_str);
let help = format!("consider moving the {} statements out like this", place_str); let help = format!("consider moving the {} statements out like this", place_str);
span_lint_and_then(cx, SHARED_CODE_IN_IF_BLOCKS, span, msg.as_str(), |diag| { span_lint_and_then(cx, BRANCHES_SHARING_CODE, span, msg.as_str(), |diag| {
diag.span_suggestion(span, help.as_str(), sugg, Applicability::Unspecified); diag.span_suggestion(span, help.as_str(), sugg, Applicability::Unspecified);
add_optional_msgs(diag); add_optional_msgs(diag);
@@ -482,7 +483,7 @@ fn emit_shared_code_in_if_blocks_lint(
let (_, start_span, start_sugg) = suggestions.pop().unwrap(); let (_, start_span, start_sugg) = suggestions.pop().unwrap();
span_lint_and_then( span_lint_and_then(
cx, cx,
SHARED_CODE_IN_IF_BLOCKS, BRANCHES_SHARING_CODE,
start_span, start_span,
"all if blocks contain the same code at the start and the end. Here at the start", "all if blocks contain the same code at the start and the end. Here at the start",
move |diag| { move |diag| {

View File

@@ -613,10 +613,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&collapsible_if::COLLAPSIBLE_IF, &collapsible_if::COLLAPSIBLE_IF,
&collapsible_match::COLLAPSIBLE_MATCH, &collapsible_match::COLLAPSIBLE_MATCH,
&comparison_chain::COMPARISON_CHAIN, &comparison_chain::COMPARISON_CHAIN,
&copies::BRANCHES_SHARING_CODE,
&copies::IFS_SAME_COND, &copies::IFS_SAME_COND,
&copies::IF_SAME_THEN_ELSE, &copies::IF_SAME_THEN_ELSE,
&copies::SAME_FUNCTIONS_IN_IF_CONDITION, &copies::SAME_FUNCTIONS_IN_IF_CONDITION,
&copies::SHARED_CODE_IN_IF_BLOCKS,
&copy_iterator::COPY_ITERATOR, &copy_iterator::COPY_ITERATOR,
&create_dir::CREATE_DIR, &create_dir::CREATE_DIR,
&dbg_macro::DBG_MACRO, &dbg_macro::DBG_MACRO,
@@ -1483,9 +1483,9 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&collapsible_if::COLLAPSIBLE_IF), LintId::of(&collapsible_if::COLLAPSIBLE_IF),
LintId::of(&collapsible_match::COLLAPSIBLE_MATCH), LintId::of(&collapsible_match::COLLAPSIBLE_MATCH),
LintId::of(&comparison_chain::COMPARISON_CHAIN), LintId::of(&comparison_chain::COMPARISON_CHAIN),
LintId::of(&copies::BRANCHES_SHARING_CODE),
LintId::of(&copies::IFS_SAME_COND), LintId::of(&copies::IFS_SAME_COND),
LintId::of(&copies::IF_SAME_THEN_ELSE), LintId::of(&copies::IF_SAME_THEN_ELSE),
LintId::of(&copies::SHARED_CODE_IN_IF_BLOCKS),
LintId::of(&default::FIELD_REASSIGN_WITH_DEFAULT), LintId::of(&default::FIELD_REASSIGN_WITH_DEFAULT),
LintId::of(&derive::DERIVE_HASH_XOR_EQ), LintId::of(&derive::DERIVE_HASH_XOR_EQ),
LintId::of(&derive::DERIVE_ORD_XOR_PARTIAL_ORD), LintId::of(&derive::DERIVE_ORD_XOR_PARTIAL_ORD),
@@ -1872,6 +1872,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&booleans::NONMINIMAL_BOOL), LintId::of(&booleans::NONMINIMAL_BOOL),
LintId::of(&casts::CHAR_LIT_AS_U8), LintId::of(&casts::CHAR_LIT_AS_U8),
LintId::of(&casts::UNNECESSARY_CAST), LintId::of(&casts::UNNECESSARY_CAST),
LintId::of(&copies::BRANCHES_SHARING_CODE),
LintId::of(&double_comparison::DOUBLE_COMPARISONS), LintId::of(&double_comparison::DOUBLE_COMPARISONS),
LintId::of(&double_parens::DOUBLE_PARENS), LintId::of(&double_parens::DOUBLE_PARENS),
LintId::of(&duration_subsec::DURATION_SUBSEC), LintId::of(&duration_subsec::DURATION_SUBSEC),

View File

@@ -47,7 +47,7 @@ pub mod usage;
pub mod visitors; pub mod visitors;
pub use self::attrs::*; pub use self::attrs::*;
pub use self::hir_utils::{both, eq_expr_value, over, SpanlessEq, SpanlessHash}; pub use self::hir_utils::{both, count_eq, eq_expr_value, over, SpanlessEq, SpanlessHash};
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::hash::BuildHasherDefault; use std::hash::BuildHasherDefault;

View File

@@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
#![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
// This tests the shared_code_in_if_blocks lint at the end of blocks // This tests the branches_sharing_code lint at the end of blocks
fn simple_examples() { fn simple_examples() {
let x = 1; let x = 1;

View File

@@ -1,5 +1,5 @@
error: all if blocks contain the same code at the end error: all if blocks contain the same code at the end
--> $DIR/shared_at_bot.rs:30:5 --> $DIR/shared_at_bottom.rs:30:5
| |
LL | / let result = false; LL | / let result = false;
LL | | println!("Block end!"); LL | | println!("Block end!");
@@ -8,10 +8,10 @@ LL | | };
| |_____^ | |_____^
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/shared_at_bot.rs:2:36 --> $DIR/shared_at_bottom.rs:2:36
| |
LL | #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: The end suggestion probably needs some adjustments to use the expression result correctly = note: The end suggestion probably needs some adjustments to use the expression result correctly
help: consider moving the end statements out like this help: consider moving the end statements out like this
| |
@@ -22,7 +22,7 @@ LL | result;
| |
error: all if blocks contain the same code at the end error: all if blocks contain the same code at the end
--> $DIR/shared_at_bot.rs:48:5 --> $DIR/shared_at_bottom.rs:48:5
| |
LL | / println!("Same end of block"); LL | / println!("Same end of block");
LL | | } LL | | }
@@ -35,7 +35,7 @@ LL | println!("Same end of block");
| |
error: all if blocks contain the same code at the end error: all if blocks contain the same code at the end
--> $DIR/shared_at_bot.rs:65:5 --> $DIR/shared_at_bottom.rs:65:5
| |
LL | / println!( LL | / println!(
LL | | "I'm moveable because I know: `outer_scope_value`: '{}'", LL | | "I'm moveable because I know: `outer_scope_value`: '{}'",
@@ -54,7 +54,7 @@ LL | );
| |
error: all if blocks contain the same code at the end error: all if blocks contain the same code at the end
--> $DIR/shared_at_bot.rs:77:9 --> $DIR/shared_at_bottom.rs:77:9
| |
LL | / println!("Hello World"); LL | / println!("Hello World");
LL | | } LL | | }
@@ -67,7 +67,7 @@ LL | println!("Hello World");
| |
error: all if blocks contain the same code at the end error: all if blocks contain the same code at the end
--> $DIR/shared_at_bot.rs:93:5 --> $DIR/shared_at_bottom.rs:93:5
| |
LL | / let later_used_value = "A string value"; LL | / let later_used_value = "A string value";
LL | | println!("{}", later_used_value); LL | | println!("{}", later_used_value);
@@ -84,7 +84,7 @@ LL | println!("{}", later_used_value);
| |
error: all if blocks contain the same code at the end error: all if blocks contain the same code at the end
--> $DIR/shared_at_bot.rs:106:5 --> $DIR/shared_at_bottom.rs:106:5
| |
LL | / let simple_examples = "I now identify as a &str :)"; LL | / let simple_examples = "I now identify as a &str :)";
LL | | println!("This is the new simple_example: {}", simple_examples); LL | | println!("This is the new simple_example: {}", simple_examples);
@@ -100,7 +100,7 @@ LL | println!("This is the new simple_example: {}", simple_examples);
| |
error: all if blocks contain the same code at the end error: all if blocks contain the same code at the end
--> $DIR/shared_at_bot.rs:171:5 --> $DIR/shared_at_bottom.rs:171:5
| |
LL | / x << 2 LL | / x << 2
LL | | }; LL | | };
@@ -114,7 +114,7 @@ LL | x << 2;
| |
error: all if blocks contain the same code at the end error: all if blocks contain the same code at the end
--> $DIR/shared_at_bot.rs:178:5 --> $DIR/shared_at_bottom.rs:178:5
| |
LL | / x * 4 LL | / x * 4
LL | | } LL | | }
@@ -128,7 +128,7 @@ LL | x * 4
| |
error: all if blocks contain the same code at the end error: all if blocks contain the same code at the end
--> $DIR/shared_at_bot.rs:190:44 --> $DIR/shared_at_bottom.rs:190:44
| |
LL | if x == 17 { b = 1; a = 0x99; } else { a = 0x99; } LL | if x == 17 { b = 1; a = 0x99; } else { a = 0x99; }
| ^^^^^^^^^^^ | ^^^^^^^^^^^

View File

@@ -1,7 +1,7 @@
#![allow(dead_code, clippy::eval_order_dependence)] #![allow(dead_code, clippy::eval_order_dependence)]
#![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
// This tests the shared_code_in_if_blocks lint at the start of blocks // This tests the branches_sharing_code lint at the start of blocks
fn simple_examples() { fn simple_examples() {
let x = 0; let x = 0;

View File

@@ -8,8 +8,8 @@ LL | | println!("Hello World!");
note: the lint level is defined here note: the lint level is defined here
--> $DIR/shared_at_top.rs:2:36 --> $DIR/shared_at_top.rs:2:36
| |
LL | #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider moving the start statements out like this help: consider moving the start statements out like this
| |
LL | println!("Hello World!"); LL | println!("Hello World!");
@@ -106,7 +106,7 @@ LL | | } else {
note: the lint level is defined here note: the lint level is defined here
--> $DIR/shared_at_top.rs:2:9 --> $DIR/shared_at_top.rs:2:9
| |
LL | #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: same as this note: same as this
--> $DIR/shared_at_top.rs:98:12 --> $DIR/shared_at_top.rs:98:12

View File

@@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
#![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
// shared_code_in_if_blocks at the top and bottom of the if blocks // branches_sharing_code at the top and bottom of the if blocks
struct DataPack { struct DataPack {
id: u32, id: u32,

View File

@@ -1,5 +1,5 @@
error: all if blocks contain the same code at the start and the end. Here at the start error: all if blocks contain the same code at the start and the end. Here at the start
--> $DIR/shared_at_top_and_bot.rs:16:5 --> $DIR/shared_at_top_and_bottom.rs:16:5
| |
LL | / if x == 7 { LL | / if x == 7 {
LL | | let t = 7; LL | | let t = 7;
@@ -8,12 +8,12 @@ LL | | let _overlap_end = 2 * t;
| |_________________________________^ | |_________________________________^
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/shared_at_top_and_bot.rs:2:36 --> $DIR/shared_at_top_and_bottom.rs:2:36
| |
LL | #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: and here at the end note: and here at the end
--> $DIR/shared_at_top_and_bot.rs:28:5 --> $DIR/shared_at_top_and_bottom.rs:28:5
| |
LL | / let _u = 9; LL | / let _u = 9;
LL | | } LL | | }
@@ -32,7 +32,7 @@ LL | let _u = 9;
| |
error: all if blocks contain the same code at the start and the end. Here at the start error: all if blocks contain the same code at the start and the end. Here at the start
--> $DIR/shared_at_top_and_bot.rs:32:5 --> $DIR/shared_at_top_and_bottom.rs:32:5
| |
LL | / if x == 99 { LL | / if x == 99 {
LL | | let r = 7; LL | | let r = 7;
@@ -41,7 +41,7 @@ LL | | let _overlap_middle = r * r;
| |____________________________________^ | |____________________________________^
| |
note: and here at the end note: and here at the end
--> $DIR/shared_at_top_and_bot.rs:43:5 --> $DIR/shared_at_top_and_bottom.rs:43:5
| |
LL | / let _overlap_end = r * r * r; LL | / let _overlap_end = r * r * r;
LL | | let z = "end"; LL | | let z = "end";
@@ -63,7 +63,7 @@ LL | let z = "end";
| |
error: all if blocks contain the same code at the start and the end. Here at the start error: all if blocks contain the same code at the start and the end. Here at the start
--> $DIR/shared_at_top_and_bot.rs:61:5 --> $DIR/shared_at_top_and_bottom.rs:61:5
| |
LL | / if (x > 7 && y < 13) || (x + y) % 2 == 1 { LL | / if (x > 7 && y < 13) || (x + y) % 2 == 1 {
LL | | let a = 0xcafe; LL | | let a = 0xcafe;
@@ -72,7 +72,7 @@ LL | | let e_id = gen_id(a, b);
| |________________________________^ | |________________________________^
| |
note: and here at the end note: and here at the end
--> $DIR/shared_at_top_and_bot.rs:81:5 --> $DIR/shared_at_top_and_bottom.rs:81:5
| |
LL | / let pack = DataPack { LL | / let pack = DataPack {
LL | | id: e_id, LL | | id: e_id,
@@ -101,14 +101,14 @@ LL | };
... ...
error: all if blocks contain the same code at the start and the end. Here at the start error: all if blocks contain the same code at the start and the end. Here at the start
--> $DIR/shared_at_top_and_bot.rs:94:5 --> $DIR/shared_at_top_and_bottom.rs:94:5
| |
LL | / let _ = if x == 7 { LL | / let _ = if x == 7 {
LL | | let _ = 19; LL | | let _ = 19;
| |___________________^ | |___________________^
| |
note: and here at the end note: and here at the end
--> $DIR/shared_at_top_and_bot.rs:103:5 --> $DIR/shared_at_top_and_bottom.rs:103:5
| |
LL | / x << 2 LL | / x << 2
LL | | }; LL | | };
@@ -126,14 +126,14 @@ LL | x << 2;
| |
error: all if blocks contain the same code at the start and the end. Here at the start error: all if blocks contain the same code at the start and the end. Here at the start
--> $DIR/shared_at_top_and_bot.rs:106:5 --> $DIR/shared_at_top_and_bottom.rs:106:5
| |
LL | / if x == 9 { LL | / if x == 9 {
LL | | let _ = 17; LL | | let _ = 17;
| |___________________^ | |___________________^
| |
note: and here at the end note: and here at the end
--> $DIR/shared_at_top_and_bot.rs:115:5 --> $DIR/shared_at_top_and_bottom.rs:115:5
| |
LL | / x * 4 LL | / x * 4
LL | | } LL | | }

View File

@@ -1,9 +1,9 @@
#![allow(dead_code, clippy::eval_order_dependence)] #![allow(dead_code, clippy::eval_order_dependence)]
#![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
// This tests the shared_code_in_if_blocks lint at the start of blocks // This tests valid if blocks that shouldn't trigger the lint
// Tests with value references are includes in "shared_code_at_bot.rs" // Tests with value references are includes in "shared_code_at_bottom.rs"
fn valid_examples() { fn valid_examples() {
let x = 2; let x = 2;

View File

@@ -9,7 +9,7 @@ LL | | } else {
note: the lint level is defined here note: the lint level is defined here
--> $DIR/valid_if_blocks.rs:2:9 --> $DIR/valid_if_blocks.rs:2:9
| |
LL | #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: same as this note: same as this
--> $DIR/valid_if_blocks.rs:105:12 --> $DIR/valid_if_blocks.rs:105:12

View File

@@ -1,5 +1,5 @@
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
#![allow(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] #![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
fn test_complex_conditions() { fn test_complex_conditions() {
let x: Result<(), ()> = Ok(()); let x: Result<(), ()> = Ok(());

View File

@@ -1,5 +1,5 @@
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
#![allow(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] #![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
fn test_nested() { fn test_nested() {
fn nested() { fn nested() {

View File

@@ -1,5 +1,5 @@
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
#![allow(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)] #![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
macro_rules! m { macro_rules! m {
($a:expr) => { ($a:expr) => {

View File

@@ -3,7 +3,7 @@
#![allow(clippy::never_loop)] #![allow(clippy::never_loop)]
#![allow(clippy::no_effect)] #![allow(clippy::no_effect)]
#![allow(clippy::unnecessary_operation)] #![allow(clippy::unnecessary_operation)]
#![allow(clippy::shared_code_in_if_blocks)] #![allow(clippy::branches_sharing_code)]
mod basic_expr { mod basic_expr {
fn test() { fn test() {

View File

@@ -6,7 +6,7 @@
clippy::no_effect, clippy::no_effect,
clippy::unused_unit, clippy::unused_unit,
clippy::zero_divided_by_zero, clippy::zero_divided_by_zero,
clippy::shared_code_in_if_blocks clippy::branches_sharing_code
)] )]
struct Foo { struct Foo {

View File

@@ -6,7 +6,7 @@
clippy::ifs_same_cond, clippy::ifs_same_cond,
clippy::needless_return, clippy::needless_return,
clippy::single_element_loop, clippy::single_element_loop,
clippy::shared_code_in_if_blocks clippy::branches_sharing_code
)] )]
fn if_same_then_else2() -> Result<&'static str, ()> { fn if_same_then_else2() -> Result<&'static str, ()> {

View File

@@ -3,7 +3,7 @@
unused_assignments, unused_assignments,
clippy::similar_names, clippy::similar_names,
clippy::blacklisted_name, clippy::blacklisted_name,
clippy::shared_code_in_if_blocks clippy::branches_sharing_code
)] )]
#![warn(clippy::useless_let_if_seq)] #![warn(clippy::useless_let_if_seq)]

View File

@@ -5,7 +5,7 @@
clippy::no_effect, clippy::no_effect,
clippy::if_same_then_else, clippy::if_same_then_else,
clippy::needless_return, clippy::needless_return,
clippy::shared_code_in_if_blocks clippy::branches_sharing_code
)] )]
fn main() { fn main() {

View File

@@ -4,7 +4,7 @@
#![allow( #![allow(
clippy::if_same_then_else, clippy::if_same_then_else,
clippy::single_match, clippy::single_match,
clippy::shared_code_in_if_blocks, clippy::branches_sharing_code,
clippy::needless_bool clippy::needless_bool
)] )]
#![warn(clippy::needless_return)] #![warn(clippy::needless_return)]

View File

@@ -4,7 +4,7 @@
#![allow( #![allow(
clippy::if_same_then_else, clippy::if_same_then_else,
clippy::single_match, clippy::single_match,
clippy::shared_code_in_if_blocks, clippy::branches_sharing_code,
clippy::needless_bool clippy::needless_bool
)] )]
#![warn(clippy::needless_return)] #![warn(clippy::needless_return)]