mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Moving shared_code_in_if_blocks to clippy::complexity and running lintcheck
This commit is contained in:
parent
c74e49eab9
commit
617c65baa9
21 changed files with 180 additions and 84 deletions
|
@ -142,7 +142,7 @@ declare_clippy_lint! {
|
|||
/// };
|
||||
/// ```
|
||||
pub SHARED_CODE_IN_IF_BLOCKS,
|
||||
nursery,
|
||||
complexity,
|
||||
"`if` statement with shared code in all blocks"
|
||||
}
|
||||
|
||||
|
@ -457,11 +457,11 @@ fn emit_shared_code_in_if_blocks_lint(
|
|||
|
||||
let add_optional_msgs = |diag: &mut DiagnosticBuilder<'_>| {
|
||||
if add_expr_note {
|
||||
diag.note("The end suggestion probably needs some adjustments to use the expression result correctly.");
|
||||
diag.note("The end suggestion probably needs some adjustments to use the expression result correctly");
|
||||
}
|
||||
|
||||
if warn_about_moved_symbol {
|
||||
diag.warn("Some moved values might need to be renamed to avoid wrong references.");
|
||||
diag.warn("Some moved values might need to be renamed to avoid wrong references");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1485,6 +1485,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(&comparison_chain::COMPARISON_CHAIN),
|
||||
LintId::of(&copies::IFS_SAME_COND),
|
||||
LintId::of(&copies::IF_SAME_THEN_ELSE),
|
||||
LintId::of(&copies::SHARED_CODE_IN_IF_BLOCKS),
|
||||
LintId::of(&default::FIELD_REASSIGN_WITH_DEFAULT),
|
||||
LintId::of(&derive::DERIVE_HASH_XOR_EQ),
|
||||
LintId::of(&derive::DERIVE_ORD_XOR_PARTIAL_ORD),
|
||||
|
@ -2063,7 +2064,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
|
||||
LintId::of(&attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
|
||||
LintId::of(&cognitive_complexity::COGNITIVE_COMPLEXITY),
|
||||
LintId::of(&copies::SHARED_CODE_IN_IF_BLOCKS),
|
||||
LintId::of(&disallowed_method::DISALLOWED_METHOD),
|
||||
LintId::of(&fallible_impl_from::FALLIBLE_IMPL_FROM),
|
||||
LintId::of(&floating_point_arithmetic::IMPRECISE_FLOPS),
|
||||
|
|
|
@ -96,9 +96,11 @@ impl HirEqInterExpr<'_, '_, '_> {
|
|||
pub fn eq_stmt(&mut self, left: &Stmt<'_>, right: &Stmt<'_>) -> bool {
|
||||
match (&left.kind, &right.kind) {
|
||||
(&StmtKind::Local(ref l), &StmtKind::Local(ref r)) => {
|
||||
self.eq_pat(&l.pat, &r.pat)
|
||||
// eq_pat adds the HirIds to the locals map. We therefor call it last to make sure that
|
||||
// these only get added if the init and type is equal.
|
||||
both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
|
||||
&& both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r))
|
||||
&& both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
|
||||
&& self.eq_pat(&l.pat, &r.pat)
|
||||
},
|
||||
(&StmtKind::Expr(ref l), &StmtKind::Expr(ref r)) | (&StmtKind::Semi(ref l), &StmtKind::Semi(ref r)) => {
|
||||
self.eq_expr(l, r)
|
||||
|
|
|
@ -609,9 +609,9 @@ pub fn get_pat_name(pat: &Pat<'_>) -> Option<Symbol> {
|
|||
}
|
||||
}
|
||||
|
||||
struct ContainsName {
|
||||
name: Symbol,
|
||||
result: bool,
|
||||
pub struct ContainsName {
|
||||
pub name: Symbol,
|
||||
pub result: bool,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for ContainsName {
|
||||
|
@ -1216,6 +1216,8 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>,
|
|||
(conds, blocks)
|
||||
}
|
||||
|
||||
/// This function returns true if the given expression is the `else` or `if else` part of an if
|
||||
/// statement
|
||||
pub fn parent_node_is_if_expr(expr: &Expr<'_>, cx: &LateContext<'_>) -> bool {
|
||||
let map = cx.tcx.hir();
|
||||
let parent_id = map.get_parent_node(expr.hir_id);
|
||||
|
@ -1326,6 +1328,16 @@ pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<DefId> {
|
|||
}
|
||||
}
|
||||
|
||||
/// This function checks if any of the lints in the slice is enabled for the provided `HirId`.
|
||||
/// A lint counts as enabled with any of the levels: `Level::Forbid` | `Level::Deny` | `Level::Warn`
|
||||
///
|
||||
/// ```ignore
|
||||
/// #[deny(clippy::YOUR_AWESOME_LINT)]
|
||||
/// println!("Hello, World!"); // <- Clippy code: run_lints(cx, &[YOUR_AWESOME_LINT], id) == true
|
||||
///
|
||||
/// #[allow(clippy::YOUR_AWESOME_LINT)]
|
||||
/// println!("See you soon!"); // <- Clippy code: run_lints(cx, &[YOUR_AWESOME_LINT], id) == false
|
||||
/// ```
|
||||
pub fn run_lints(cx: &LateContext<'_>, lints: &[&'static Lint], id: HirId) -> bool {
|
||||
lints.iter().any(|lint| {
|
||||
matches!(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
||||
#![allow(clippy::if_same_then_else)]
|
||||
#![allow(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)]
|
||||
|
||||
fn test_nested() {
|
||||
fn nested() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
||||
#![allow(clippy::if_same_then_else)]
|
||||
#![allow(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)]
|
||||
|
||||
macro_rules! m {
|
||||
($a:expr) => {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#![allow(clippy::never_loop)]
|
||||
#![allow(clippy::no_effect)]
|
||||
#![allow(clippy::unnecessary_operation)]
|
||||
#![allow(clippy::shared_code_in_if_blocks)]
|
||||
|
||||
mod basic_expr {
|
||||
fn test() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:10:17
|
||||
--> $DIR/default_numeric_fallback.rs:11:17
|
||||
|
|
||||
LL | let x = 22;
|
||||
| ^^ help: consider adding suffix: `22_i32`
|
||||
|
@ -7,139 +7,139 @@ LL | let x = 22;
|
|||
= note: `-D clippy::default-numeric-fallback` implied by `-D warnings`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:11:18
|
||||
--> $DIR/default_numeric_fallback.rs:12:18
|
||||
|
|
||||
LL | let x = [1, 2, 3];
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:11:21
|
||||
--> $DIR/default_numeric_fallback.rs:12:21
|
||||
|
|
||||
LL | let x = [1, 2, 3];
|
||||
| ^ help: consider adding suffix: `2_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:11:24
|
||||
--> $DIR/default_numeric_fallback.rs:12:24
|
||||
|
|
||||
LL | let x = [1, 2, 3];
|
||||
| ^ help: consider adding suffix: `3_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:12:28
|
||||
--> $DIR/default_numeric_fallback.rs:13:28
|
||||
|
|
||||
LL | let x = if true { (1, 2) } else { (3, 4) };
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:12:31
|
||||
--> $DIR/default_numeric_fallback.rs:13:31
|
||||
|
|
||||
LL | let x = if true { (1, 2) } else { (3, 4) };
|
||||
| ^ help: consider adding suffix: `2_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:12:44
|
||||
--> $DIR/default_numeric_fallback.rs:13:44
|
||||
|
|
||||
LL | let x = if true { (1, 2) } else { (3, 4) };
|
||||
| ^ help: consider adding suffix: `3_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:12:47
|
||||
--> $DIR/default_numeric_fallback.rs:13:47
|
||||
|
|
||||
LL | let x = if true { (1, 2) } else { (3, 4) };
|
||||
| ^ help: consider adding suffix: `4_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:13:23
|
||||
--> $DIR/default_numeric_fallback.rs:14:23
|
||||
|
|
||||
LL | let x = match 1 {
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:14:13
|
||||
--> $DIR/default_numeric_fallback.rs:15:13
|
||||
|
|
||||
LL | 1 => 1,
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:14:18
|
||||
--> $DIR/default_numeric_fallback.rs:15:18
|
||||
|
|
||||
LL | 1 => 1,
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:15:18
|
||||
--> $DIR/default_numeric_fallback.rs:16:18
|
||||
|
|
||||
LL | _ => 2,
|
||||
| ^ help: consider adding suffix: `2_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:19:17
|
||||
--> $DIR/default_numeric_fallback.rs:20:17
|
||||
|
|
||||
LL | let x = 0.12;
|
||||
| ^^^^ help: consider adding suffix: `0.12_f64`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:37:21
|
||||
--> $DIR/default_numeric_fallback.rs:38:21
|
||||
|
|
||||
LL | let y = 1;
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:45:21
|
||||
--> $DIR/default_numeric_fallback.rs:46:21
|
||||
|
|
||||
LL | let y = 1;
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:51:21
|
||||
--> $DIR/default_numeric_fallback.rs:52:21
|
||||
|
|
||||
LL | let y = 1;
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:63:9
|
||||
--> $DIR/default_numeric_fallback.rs:64:9
|
||||
|
|
||||
LL | 1
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:69:27
|
||||
--> $DIR/default_numeric_fallback.rs:70:27
|
||||
|
|
||||
LL | let f = || -> _ { 1 };
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:73:29
|
||||
--> $DIR/default_numeric_fallback.rs:74:29
|
||||
|
|
||||
LL | let f = || -> i32 { 1 };
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:87:21
|
||||
--> $DIR/default_numeric_fallback.rs:88:21
|
||||
|
|
||||
LL | generic_arg(1);
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:90:32
|
||||
--> $DIR/default_numeric_fallback.rs:91:32
|
||||
|
|
||||
LL | let x: _ = generic_arg(1);
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:108:28
|
||||
--> $DIR/default_numeric_fallback.rs:109:28
|
||||
|
|
||||
LL | GenericStruct { x: 1 };
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:111:36
|
||||
--> $DIR/default_numeric_fallback.rs:112:36
|
||||
|
|
||||
LL | let _ = GenericStruct { x: 1 };
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
||||
error: default numeric fallback might occur
|
||||
--> $DIR/default_numeric_fallback.rs:131:23
|
||||
--> $DIR/default_numeric_fallback.rs:132:23
|
||||
|
|
||||
LL | s.generic_arg(1);
|
||||
| ^ help: consider adding suffix: `1_i32`
|
||||
|
|
|
@ -82,5 +82,31 @@ LL | | 42
|
|||
LL | | };
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:95:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | let bar = if true { 42 } else { 43 };
|
||||
LL | |
|
||||
LL | | while foo() {
|
||||
... |
|
||||
LL | | bar + 1;
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:102:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | let bar = if true { 42 } else { 43 };
|
||||
LL | |
|
||||
... |
|
||||
LL | | bar + 1;
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
@ -101,5 +101,25 @@ LL | | Ok("foo")?;
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else2.rs:122:20
|
||||
|
|
||||
LL | } else if true {
|
||||
| ____________________^
|
||||
LL | | let foo = "";
|
||||
LL | | return Ok(&foo[0..]);
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else2.rs:125:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | let foo = "";
|
||||
LL | | return Ok(&foo[0..]);
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
dead_code,
|
||||
clippy::no_effect,
|
||||
clippy::if_same_then_else,
|
||||
clippy::needless_return
|
||||
clippy::needless_return,
|
||||
clippy::shared_code_in_if_blocks
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: this if-then-else expression will always return true
|
||||
--> $DIR/simple.rs:13:5
|
||||
--> $DIR/simple.rs:14:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | true
|
||||
|
@ -11,7 +11,7 @@ LL | | };
|
|||
= note: `-D clippy::needless-bool` implied by `-D warnings`
|
||||
|
||||
error: this if-then-else expression will always return false
|
||||
--> $DIR/simple.rs:18:5
|
||||
--> $DIR/simple.rs:19:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | false
|
||||
|
@ -21,7 +21,7 @@ LL | | };
|
|||
| |_____^
|
||||
|
||||
error: this if-then-else expression will always return true
|
||||
--> $DIR/simple.rs:33:5
|
||||
--> $DIR/simple.rs:34:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | return true;
|
||||
|
@ -31,7 +31,7 @@ LL | | };
|
|||
| |_____^
|
||||
|
||||
error: this if-then-else expression will always return false
|
||||
--> $DIR/simple.rs:41:5
|
||||
--> $DIR/simple.rs:42:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | return false;
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(unused, clippy::needless_bool)]
|
||||
#![allow(clippy::if_same_then_else, clippy::single_match)]
|
||||
#![allow(unused)]
|
||||
#![allow(
|
||||
clippy::if_same_then_else,
|
||||
clippy::single_match,
|
||||
clippy::shared_code_in_if_blocks,
|
||||
clippy::needless_bool
|
||||
)]
|
||||
#![warn(clippy::needless_return)]
|
||||
|
||||
macro_rules! the_answer {
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(unused, clippy::needless_bool)]
|
||||
#![allow(clippy::if_same_then_else, clippy::single_match)]
|
||||
#![allow(unused)]
|
||||
#![allow(
|
||||
clippy::if_same_then_else,
|
||||
clippy::single_match,
|
||||
clippy::shared_code_in_if_blocks,
|
||||
clippy::needless_bool
|
||||
)]
|
||||
#![warn(clippy::needless_return)]
|
||||
|
||||
macro_rules! the_answer {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:18:5
|
||||
--> $DIR/needless_return.rs:23:5
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
@ -7,103 +7,103 @@ LL | return true;
|
|||
= note: `-D clippy::needless-return` implied by `-D warnings`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:22:5
|
||||
--> $DIR/needless_return.rs:27:5
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:27:9
|
||||
--> $DIR/needless_return.rs:32:9
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:29:9
|
||||
--> $DIR/needless_return.rs:34:9
|
||||
|
|
||||
LL | return false;
|
||||
| ^^^^^^^^^^^^^ help: remove `return`: `false`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:35:17
|
||||
--> $DIR/needless_return.rs:40:17
|
||||
|
|
||||
LL | true => return false,
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `false`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:37:13
|
||||
--> $DIR/needless_return.rs:42:13
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:44:9
|
||||
--> $DIR/needless_return.rs:49:9
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:46:16
|
||||
--> $DIR/needless_return.rs:51:16
|
||||
|
|
||||
LL | let _ = || return true;
|
||||
| ^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:54:5
|
||||
--> $DIR/needless_return.rs:59:5
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^^ help: remove `return`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:59:9
|
||||
--> $DIR/needless_return.rs:64:9
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^^ help: remove `return`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:61:9
|
||||
--> $DIR/needless_return.rs:66:9
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^^ help: remove `return`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:68:14
|
||||
--> $DIR/needless_return.rs:73:14
|
||||
|
|
||||
LL | _ => return,
|
||||
| ^^^^^^ help: replace `return` with an empty block: `{}`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:83:9
|
||||
--> $DIR/needless_return.rs:88:9
|
||||
|
|
||||
LL | return String::from("test");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:85:9
|
||||
--> $DIR/needless_return.rs:90:9
|
||||
|
|
||||
LL | return String::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:106:32
|
||||
--> $DIR/needless_return.rs:111:32
|
||||
|
|
||||
LL | bar.unwrap_or_else(|_| return)
|
||||
| ^^^^^^ help: replace `return` with an empty block: `{}`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:111:13
|
||||
--> $DIR/needless_return.rs:116:13
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^^ help: remove `return`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:113:20
|
||||
--> $DIR/needless_return.rs:118:20
|
||||
|
|
||||
LL | let _ = || return;
|
||||
| ^^^^^^ help: replace `return` with an empty block: `{}`
|
||||
|
||||
error: unneeded `return` statement
|
||||
--> $DIR/needless_return.rs:119:32
|
||||
--> $DIR/needless_return.rs:124:32
|
||||
|
|
||||
LL | res.unwrap_or_else(|_| return Foo)
|
||||
| ^^^^^^^^^^ help: remove `return`: `Foo`
|
||||
|
|
|
@ -190,4 +190,20 @@ fn test_suggestion_with_weird_formatting() {
|
|||
if x == 17 { b = 1; a = 0x99; } else { a = 0x99; }
|
||||
}
|
||||
|
||||
fn fp_test() {
|
||||
let x = 17;
|
||||
|
||||
if x == 18 {
|
||||
let y = 19;
|
||||
if y < x {
|
||||
println!("Trigger")
|
||||
}
|
||||
} else {
|
||||
let z = 166;
|
||||
if z < x {
|
||||
println!("Trigger")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -12,7 +12,7 @@ note: the lint level is defined here
|
|||
|
|
||||
LL | #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= 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
|
||||
|
|
||||
LL | }
|
||||
|
@ -75,7 +75,7 @@ LL | | // I'm expecting a note about this
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references.
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references
|
||||
help: consider moving the end statements out like this
|
||||
|
|
||||
LL | }
|
||||
|
@ -91,7 +91,7 @@ LL | | println!("This is the new simple_example: {}", simple_examples);
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references.
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references
|
||||
help: consider moving the end statements out like this
|
||||
|
|
||||
LL | }
|
||||
|
@ -106,7 +106,7 @@ LL | / x << 2
|
|||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
= 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
|
||||
|
|
||||
LL | }
|
||||
|
@ -120,7 +120,7 @@ LL | / x * 4
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= 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
|
||||
|
|
||||
LL | }
|
||||
|
|
|
@ -25,7 +25,7 @@ LL | | println!("The value y was set to: `{}`", y);
|
|||
LL | | let _z = y;
|
||||
| |___________________^
|
||||
|
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references.
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references
|
||||
help: consider moving the start statements out like this
|
||||
|
|
||||
LL | let y = 9;
|
||||
|
@ -55,7 +55,7 @@ LL | | let used_value_name = "Different type";
|
|||
LL | | println!("Str: {}", used_value_name);
|
||||
| |_____________________________________________^
|
||||
|
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references.
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references
|
||||
help: consider moving the start statements out like this
|
||||
|
|
||||
LL | let used_value_name = "Different type";
|
||||
|
@ -71,7 +71,7 @@ LL | | let can_be_overridden = "Move me";
|
|||
LL | | println!("I'm also moveable");
|
||||
| |______________________________________^
|
||||
|
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references.
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references
|
||||
help: consider moving the start statements out like this
|
||||
|
|
||||
LL | let can_be_overridden = "Move me";
|
||||
|
|
|
@ -47,7 +47,7 @@ LL | / let _overlap_end = r * r * r;
|
|||
LL | | let z = "end";
|
||||
LL | | }
|
||||
| |_____^
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references.
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references
|
||||
help: consider moving the start statements out like this
|
||||
|
|
||||
LL | let r = 7;
|
||||
|
@ -82,7 +82,7 @@ LL | | };
|
|||
LL | | process_data(pack);
|
||||
LL | | }
|
||||
| |_____^
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references.
|
||||
= warning: Some moved values might need to be renamed to avoid wrong references
|
||||
help: consider moving the start statements out like this
|
||||
|
|
||||
LL | let a = 0xcafe;
|
||||
|
@ -113,7 +113,7 @@ note: and here at the end
|
|||
LL | / x << 2
|
||||
LL | | };
|
||||
| |_____^
|
||||
= 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 start statements out like this
|
||||
|
|
||||
LL | let _ = 19;
|
||||
|
@ -138,7 +138,7 @@ note: and here at the end
|
|||
LL | / x * 4
|
||||
LL | | }
|
||||
| |_____^
|
||||
= 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 start statements out like this
|
||||
|
|
||||
LL | let _ = 17;
|
||||
|
|
|
@ -91,6 +91,14 @@ fn valid_examples() {
|
|||
let _ = (x, y, z);
|
||||
// I'm so much better than the x == 418 block. Trust me
|
||||
}
|
||||
|
||||
let x = 1;
|
||||
if true {
|
||||
println!("{}", x);
|
||||
} else {
|
||||
let x = 2;
|
||||
println!("{}", x);
|
||||
}
|
||||
}
|
||||
|
||||
/// This makes sure that the `if_same_then_else` masks the `shared_code_in_if_blocks` lint
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: this `if` has identical blocks
|
||||
--> $DIR/valid_if_blocks.rs:102:15
|
||||
--> $DIR/valid_if_blocks.rs:110:15
|
||||
|
|
||||
LL | if x == 0 {
|
||||
| _______________^
|
||||
|
@ -15,7 +15,7 @@ note: the lint level is defined here
|
|||
LL | #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: same as this
|
||||
--> $DIR/valid_if_blocks.rs:106:12
|
||||
--> $DIR/valid_if_blocks.rs:114:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
|
@ -26,19 +26,19 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/valid_if_blocks.rs:113:23
|
||||
--> $DIR/valid_if_blocks.rs:121:23
|
||||
|
|
||||
LL | let _ = if x == 6 { 7 } else { 7 };
|
||||
| ^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/valid_if_blocks.rs:113:34
|
||||
--> $DIR/valid_if_blocks.rs:121:34
|
||||
|
|
||||
LL | let _ = if x == 6 { 7 } else { 7 };
|
||||
| ^^^^^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/valid_if_blocks.rs:119:23
|
||||
--> $DIR/valid_if_blocks.rs:127:23
|
||||
|
|
||||
LL | } else if x == 68 {
|
||||
| _______________________^
|
||||
|
@ -51,7 +51,7 @@ LL | | } else {
|
|||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/valid_if_blocks.rs:128:12
|
||||
--> $DIR/valid_if_blocks.rs:136:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
|
@ -64,7 +64,7 @@ LL | | };
|
|||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/valid_if_blocks.rs:141:23
|
||||
--> $DIR/valid_if_blocks.rs:149:23
|
||||
|
|
||||
LL | } else if x == 68 {
|
||||
| _______________________^
|
||||
|
@ -74,7 +74,7 @@ LL | | } else {
|
|||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/valid_if_blocks.rs:144:12
|
||||
--> $DIR/valid_if_blocks.rs:152:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
|
|
Loading…
Reference in a new issue