From 2abd1f73d93e3e57515121cc98cc14fe6ccb17dd Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Wed, 19 Jul 2017 19:56:32 -0400 Subject: [PATCH] Add lint for digit grouping. --- clippy_lints/src/lib.rs | 5 + clippy_lints/src/literal_digit_grouping.rs | 213 ++++++++++++++++++ clippy_lints/src/misc_early.rs | 2 +- clippy_tests/examples/assign_ops.stderr | 44 ++-- clippy_tests/examples/assign_ops2.stderr | 16 +- .../examples/block_in_if_condition.stderr | 2 +- clippy_tests/examples/bool_comparison.stderr | 8 +- clippy_tests/examples/booleans.stderr | 34 ++- clippy_tests/examples/borrow_box.stderr | 8 +- clippy_tests/examples/cmp_owned.stderr | 10 +- clippy_tests/examples/entry.stderr | 14 +- clippy_tests/examples/eq_op.stderr | 14 +- clippy_tests/examples/eta.stderr | 8 +- clippy_tests/examples/float_cmp.stderr | 16 +- clippy_tests/examples/for_loop.stderr | 26 +-- .../if_let_redundant_pattern_matching.stderr | 8 +- .../examples/inconsistent_digit_grouping.rs | 8 + .../inconsistent_digit_grouping.stderr | 45 ++++ clippy_tests/examples/large_digit_groups.rs | 8 + .../examples/large_digit_groups.stderr | 53 +++++ clippy_tests/examples/len_zero.stderr | 14 +- clippy_tests/examples/let_if_seq.stderr | 8 +- clippy_tests/examples/literals.rs | 4 +- clippy_tests/examples/literals.stderr | 16 +- clippy_tests/examples/matches.stderr | 28 +-- clippy_tests/examples/methods.stderr | 98 ++++---- clippy_tests/examples/needless_bool.stderr | 14 +- .../examples/needless_pass_by_value.stderr | 10 +- clippy_tests/examples/needless_return.stderr | 16 +- clippy_tests/examples/no_effect.stderr | 38 ++-- clippy_tests/examples/precedence.stderr | 18 +- .../examples/redundant_closure_call.stderr | 2 +- clippy_tests/examples/reference.stderr | 22 +- .../examples/short_circuit_statement.stderr | 6 +- clippy_tests/examples/strings.stderr | 18 +- clippy_tests/examples/swap.stderr | 14 +- clippy_tests/examples/toplevel_ref_arg.stderr | 8 +- clippy_tests/examples/unreadable_literal.rs | 8 + .../examples/unreadable_literal.stderr | 37 +++ clippy_tests/examples/vec.stderr | 12 +- clippy_tests/examples/while_loop.stderr | 18 +- 41 files changed, 673 insertions(+), 278 deletions(-) create mode 100644 clippy_lints/src/literal_digit_grouping.rs create mode 100644 clippy_tests/examples/inconsistent_digit_grouping.rs create mode 100644 clippy_tests/examples/inconsistent_digit_grouping.stderr create mode 100644 clippy_tests/examples/large_digit_groups.rs create mode 100644 clippy_tests/examples/large_digit_groups.stderr create mode 100644 clippy_tests/examples/unreadable_literal.rs create mode 100644 clippy_tests/examples/unreadable_literal.stderr diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d7b915fd16d..425fb4670b2 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -101,6 +101,7 @@ pub mod large_enum_variant; pub mod len_zero; pub mod let_if_seq; pub mod lifetimes; +pub mod literal_digit_grouping; pub mod loops; pub mod map_clone; pub mod matches; @@ -316,6 +317,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold)); reg.register_late_lint_pass(box should_assert_eq::ShouldAssertEq); reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue); + reg.register_early_lint_pass(box literal_digit_grouping::LiteralDigitGrouping); reg.register_lint_group("clippy_restrictions", vec![ arithmetic::FLOAT_ARITHMETIC, @@ -418,6 +420,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { let_if_seq::USELESS_LET_IF_SEQ, lifetimes::NEEDLESS_LIFETIMES, lifetimes::UNUSED_LIFETIMES, + literal_digit_grouping::UNREADABLE_LITERAL, + literal_digit_grouping::INCONSISTENT_DIGIT_GROUPING, + literal_digit_grouping::LARGE_DIGIT_GROUPS, loops::EMPTY_LOOP, loops::EXPLICIT_COUNTER_LOOP, loops::EXPLICIT_INTO_ITER_LOOP, diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs new file mode 100644 index 00000000000..1b38c5265a9 --- /dev/null +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -0,0 +1,213 @@ +//! Lints concerned with the grouping of digits with underscores in integral or +//! floating-point literal expressions. + +use rustc::lint::*; +use syntax::ast::*; +use syntax_pos; +use utils::{span_help_and_lint, snippet_opt, in_external_macro}; + +/// **What it does:** Warns if a long integral constant does not contain underscores. +/// +/// **Why is this bad?** Reading long numbers is difficult without separators. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// +/// ```rust +/// 61864918973511 +/// ``` +declare_lint! { + pub UNREADABLE_LITERAL, + Warn, + "long integer literal without underscores" +} + +/// **What it does:** Warns if an integral constant is grouped inconsistently with underscores. +/// +/// **Why is this bad?** Readers may incorrectly interpret inconsistently grouped digits. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// +/// ```rust +/// 618_64_9189_73_511 +/// ``` +declare_lint! { + pub INCONSISTENT_DIGIT_GROUPING, + Warn, + "integer literals with digits grouped inconsistently" +} + +/// **What it does:** Warns if the digits of an integral constant are grouped into groups that +/// are too large. +/// +/// **Why is this bad?** Negatively impacts readability. +/// +/// **Known problems:** None. +/// +/// **Example:** +/// +/// ```rust +/// 6186491_8973511 +/// ``` +declare_lint! { + pub LARGE_DIGIT_GROUPS, + Warn, + "grouping digits into groups that are too large" +} + +#[derive(Copy, Clone)] +pub struct LiteralDigitGrouping; + +impl LintPass for LiteralDigitGrouping { + fn get_lints(&self) -> LintArray { + lint_array!(UNREADABLE_LITERAL, INCONSISTENT_DIGIT_GROUPING, LARGE_DIGIT_GROUPS) + } +} + +impl EarlyLintPass for LiteralDigitGrouping { + fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) { + if in_external_macro(cx, expr.span) { + return; + } + + match expr.node { + ExprKind::Lit(ref lit) => self.check_lit(cx, lit), + _ => (), + } + } +} + +impl LiteralDigitGrouping { + fn check_lit(&self, cx: &EarlyContext, lit: &Lit) { + // Lint integral literals. + if_let_chain! {[ + let LitKind::Int(..) = lit.node, + let Some(src) = snippet_opt(cx, lit.span), + let Some(firstch) = src.chars().next(), + char::to_digit(firstch, 10).is_some() + ], { + let digits = LiteralDigitGrouping::get_digits(&src, false); + + LiteralDigitGrouping::do_lint(digits, cx, &lit.span); + }} + + // Lint floating-point literals. + if_let_chain! {[ + let LitKind::Float(..) = lit.node, + let Some(src) = snippet_opt(cx, lit.span), + let Some(firstch) = src.chars().next(), + char::to_digit(firstch, 10).is_some() + ], { + let digits: Vec<&str> = LiteralDigitGrouping::get_digits(&src, true) + .split_terminator('.') + .collect(); + + // Lint integral and fractional parts separately, and then check consistency of digit + // groups if both pass. + if let Some(integral_group_size) = LiteralDigitGrouping::do_lint(digits[0], cx, &lit.span) { + if digits.len() > 1 { + // Lint the fractional part of literal just like integral part, but reversed. + let fractional_part = &digits[1].chars().rev().collect::(); + if let Some(fractional_group_size) = LiteralDigitGrouping::do_lint(fractional_part, cx, &lit.span) { + let consistent = match (integral_group_size, fractional_group_size) { + // No groups on either side of decimal point - good to go. + (0, 0) => true, + // Integral part has grouped digits, fractional part does not. + (_, 0) => digits[1].len() <= integral_group_size, + // Fractional part has grouped digits, integral part does not. + (0, _) => digits[0].len() <= fractional_group_size, + // Both parts have grouped digits. Groups should be the same size. + (_, _) => integral_group_size == fractional_group_size, + }; + + if !consistent { + span_help_and_lint(cx, INCONSISTENT_DIGIT_GROUPING, lit.span, + "digits grouped inconsistently by underscores", + "consider making each group three or four digits"); + } + } + } + } + }} + } + + /// Returns the digits of an integral or floating-point literal. + fn get_digits(lit: &str, float: bool) -> &str { + // Determine delimiter for radix prefix, if present. + let mb_r = if lit.starts_with("0x") { + Some('x') + } else if lit.starts_with("0b") { + Some('b') + } else if lit.starts_with("0o") { + Some('o') + } else { + None + }; + + let has_suffix = !float && (lit.contains('i') || lit.contains('u')) || float && lit.contains('f'); + + // Grab part of literal between the radix prefix and type suffix. + let mut digits = if let Some(r) = mb_r { + lit.split(|c| c == 'i' || c == 'u' || c == r || (float && c == 'f')).nth(1).unwrap() + } else { + lit.split(|c| c == 'i' || c == 'u' || (float && c == 'f')).next().unwrap() + }; + + // If there was an underscore before type suffix, drop it. + if has_suffix && digits.chars().last().unwrap() == '_' { + digits = digits.split_at(digits.len() - 1).0; + } + + digits + } + + /// Performs lint on `digits` (no decimal point) and returns the group size. `None` is + /// returned when emitting a warning. + fn do_lint(digits: &str, cx: &EarlyContext, span: &syntax_pos::Span) -> Option { + // Grab underscore indices with respect to the units digit. + let underscore_positions: Vec = digits.chars().rev().enumerate() + .filter_map(|(idx, digit)| + if digit == '_' { + Some(idx) + } else { + None + }) + .collect(); + + if underscore_positions.is_empty() { + // Check if literal needs underscores. + if digits.len() > 4 { + span_help_and_lint(cx, UNREADABLE_LITERAL, *span, + "long literal lacking separators", + "consider using underscores to make literal more readable"); + return None; + } else { + return Some(0); + } + } else { + // Check consistency and the sizes of the groups. + let group_size = underscore_positions[0]; + let consistent = underscore_positions + .windows(2) + .all(|ps| ps[1] - ps[0] == group_size + 1) + // number of digits to the left of the last group cannot be bigger than group size. + && (digits.len() - underscore_positions.last().unwrap() <= group_size + 1); + + if !consistent { + span_help_and_lint(cx, INCONSISTENT_DIGIT_GROUPING, *span, + "digits grouped inconsistently by underscores", + "consider making each group three or four digits"); + return None; + } else if group_size > 4 { + span_help_and_lint(cx, LARGE_DIGIT_GROUPS, *span, + "digit groups should be smaller", + "consider using groups of three or four digits"); + return None; + } + return Some(group_size); + } + } +} diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index a34590518e9..1c61011755e 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -108,7 +108,7 @@ declare_lint! { /// **What it does:** Warns if an integral constant literal starts with `0`. /// /// **Why is this bad?** In some languages (including the infamous C language and most of its -/// familly), this marks an octal constant. In Rust however, this is a decimal constant. This could +/// family), this marks an octal constant. In Rust however, this is a decimal constant. This could /// be confusing for both the writer and a reader of the constant. /// /// **Known problems:** None. diff --git a/clippy_tests/examples/assign_ops.stderr b/clippy_tests/examples/assign_ops.stderr index dd36c5cad29..fd88ca612d2 100644 --- a/clippy_tests/examples/assign_ops.stderr +++ b/clippy_tests/examples/assign_ops.stderr @@ -2,7 +2,7 @@ error: assign operation detected --> assign_ops.rs:8:5 | 8 | i += 2; - | ^^^^^^ help: replace it with `i = i + 2` + | ^^^^^^ help: replace it with: `i = i + 2` | = note: `-D assign-ops` implied by `-D warnings` @@ -10,79 +10,79 @@ error: assign operation detected --> assign_ops.rs:9:5 | 9 | i += 2 + 17; - | ^^^^^^^^^^^ help: replace it with `i = i + 2 + 17` + | ^^^^^^^^^^^ help: replace it with: `i = i + 2 + 17` error: assign operation detected --> assign_ops.rs:10:5 | 10 | i -= 6; - | ^^^^^^ help: replace it with `i = i - 6` + | ^^^^^^ help: replace it with: `i = i - 6` error: assign operation detected --> assign_ops.rs:11:5 | 11 | i -= 2 - 1; - | ^^^^^^^^^^ help: replace it with `i = i - (2 - 1)` + | ^^^^^^^^^^ help: replace it with: `i = i - (2 - 1)` error: assign operation detected --> assign_ops.rs:12:5 | 12 | i *= 5; - | ^^^^^^ help: replace it with `i = i * 5` + | ^^^^^^ help: replace it with: `i = i * 5` error: assign operation detected --> assign_ops.rs:13:5 | 13 | i *= 1+5; - | ^^^^^^^^ help: replace it with `i = i * (1+5)` + | ^^^^^^^^ help: replace it with: `i = i * (1+5)` error: assign operation detected --> assign_ops.rs:14:5 | 14 | i /= 32; - | ^^^^^^^ help: replace it with `i = i / 32` + | ^^^^^^^ help: replace it with: `i = i / 32` error: assign operation detected --> assign_ops.rs:15:5 | 15 | i /= 32 | 5; - | ^^^^^^^^^^^ help: replace it with `i = i / (32 | 5)` + | ^^^^^^^^^^^ help: replace it with: `i = i / (32 | 5)` error: assign operation detected --> assign_ops.rs:16:5 | 16 | i /= 32 / 5; - | ^^^^^^^^^^^ help: replace it with `i = i / (32 / 5)` + | ^^^^^^^^^^^ help: replace it with: `i = i / (32 / 5)` error: assign operation detected --> assign_ops.rs:17:5 | 17 | i %= 42; - | ^^^^^^^ help: replace it with `i = i % 42` + | ^^^^^^^ help: replace it with: `i = i % 42` error: assign operation detected --> assign_ops.rs:18:5 | 18 | i >>= i; - | ^^^^^^^ help: replace it with `i = i >> i` + | ^^^^^^^ help: replace it with: `i = i >> i` error: assign operation detected --> assign_ops.rs:19:5 | 19 | i <<= 9 + 6 - 7; - | ^^^^^^^^^^^^^^^ help: replace it with `i = i << (9 + 6 - 7)` + | ^^^^^^^^^^^^^^^ help: replace it with: `i = i << (9 + 6 - 7)` error: assign operation detected --> assign_ops.rs:20:5 | 20 | i += 1 << 5; - | ^^^^^^^^^^^ help: replace it with `i = i + (1 << 5)` + | ^^^^^^^^^^^ help: replace it with: `i = i + (1 << 5)` error: manual implementation of an assign operation --> assign_ops.rs:27:5 | 27 | a = a + 1; - | ^^^^^^^^^ help: replace it with `a += 1` + | ^^^^^^^^^ help: replace it with: `a += 1` | = note: `-D assign-op-pattern` implied by `-D warnings` @@ -90,49 +90,49 @@ error: manual implementation of an assign operation --> assign_ops.rs:28:5 | 28 | a = 1 + a; - | ^^^^^^^^^ help: replace it with `a += 1` + | ^^^^^^^^^ help: replace it with: `a += 1` error: manual implementation of an assign operation --> assign_ops.rs:29:5 | 29 | a = a - 1; - | ^^^^^^^^^ help: replace it with `a -= 1` + | ^^^^^^^^^ help: replace it with: `a -= 1` error: manual implementation of an assign operation --> assign_ops.rs:30:5 | 30 | a = a * 99; - | ^^^^^^^^^^ help: replace it with `a *= 99` + | ^^^^^^^^^^ help: replace it with: `a *= 99` error: manual implementation of an assign operation --> assign_ops.rs:31:5 | 31 | a = 42 * a; - | ^^^^^^^^^^ help: replace it with `a *= 42` + | ^^^^^^^^^^ help: replace it with: `a *= 42` error: manual implementation of an assign operation --> assign_ops.rs:32:5 | 32 | a = a / 2; - | ^^^^^^^^^ help: replace it with `a /= 2` + | ^^^^^^^^^ help: replace it with: `a /= 2` error: manual implementation of an assign operation --> assign_ops.rs:33:5 | 33 | a = a % 5; - | ^^^^^^^^^ help: replace it with `a %= 5` + | ^^^^^^^^^ help: replace it with: `a %= 5` error: manual implementation of an assign operation --> assign_ops.rs:34:5 | 34 | a = a & 1; - | ^^^^^^^^^ help: replace it with `a &= 1` + | ^^^^^^^^^ help: replace it with: `a &= 1` error: manual implementation of an assign operation --> assign_ops.rs:40:5 | 40 | s = s + "bla"; - | ^^^^^^^^^^^^^ help: replace it with `s += "bla"` + | ^^^^^^^^^^^^^ help: replace it with: `s += "bla"` error: aborting due to 22 previous errors diff --git a/clippy_tests/examples/assign_ops2.stderr b/clippy_tests/examples/assign_ops2.stderr index 049e2ab7bf3..2f7642100b2 100644 --- a/clippy_tests/examples/assign_ops2.stderr +++ b/clippy_tests/examples/assign_ops2.stderr @@ -2,7 +2,7 @@ error: variable appears on both sides of an assignment operation --> assign_ops2.rs:8:5 | 8 | a += a + 1; - | ^^^^^^^^^^ help: replace it with `a += 1` + | ^^^^^^^^^^ help: replace it with: `a += 1` | = note: `-D misrefactored-assign-op` implied by `-D warnings` @@ -10,43 +10,43 @@ error: variable appears on both sides of an assignment operation --> assign_ops2.rs:9:5 | 9 | a += 1 + a; - | ^^^^^^^^^^ help: replace it with `a += 1` + | ^^^^^^^^^^ help: replace it with: `a += 1` error: variable appears on both sides of an assignment operation --> assign_ops2.rs:10:5 | 10 | a -= a - 1; - | ^^^^^^^^^^ help: replace it with `a -= 1` + | ^^^^^^^^^^ help: replace it with: `a -= 1` error: variable appears on both sides of an assignment operation --> assign_ops2.rs:11:5 | 11 | a *= a * 99; - | ^^^^^^^^^^^ help: replace it with `a *= 99` + | ^^^^^^^^^^^ help: replace it with: `a *= 99` error: variable appears on both sides of an assignment operation --> assign_ops2.rs:12:5 | 12 | a *= 42 * a; - | ^^^^^^^^^^^ help: replace it with `a *= 42` + | ^^^^^^^^^^^ help: replace it with: `a *= 42` error: variable appears on both sides of an assignment operation --> assign_ops2.rs:13:5 | 13 | a /= a / 2; - | ^^^^^^^^^^ help: replace it with `a /= 2` + | ^^^^^^^^^^ help: replace it with: `a /= 2` error: variable appears on both sides of an assignment operation --> assign_ops2.rs:14:5 | 14 | a %= a % 5; - | ^^^^^^^^^^ help: replace it with `a %= 5` + | ^^^^^^^^^^ help: replace it with: `a %= 5` error: variable appears on both sides of an assignment operation --> assign_ops2.rs:15:5 | 15 | a &= a & 1; - | ^^^^^^^^^^ help: replace it with `a &= 1` + | ^^^^^^^^^^ help: replace it with: `a &= 1` error: aborting due to 8 previous errors diff --git a/clippy_tests/examples/block_in_if_condition.stderr b/clippy_tests/examples/block_in_if_condition.stderr index 77f36ce228c..c7f403ac59e 100644 --- a/clippy_tests/examples/block_in_if_condition.stderr +++ b/clippy_tests/examples/block_in_if_condition.stderr @@ -46,7 +46,7 @@ error: this boolean expression can be simplified --> block_in_if_condition.rs:67:8 | 67 | if true && x == 3 { - | ^^^^^^^^^^^^^^ help: try `x == 3` + | ^^^^^^^^^^^^^^ help: try: `x == 3` | = note: `-D nonminimal-bool` implied by `-D warnings` diff --git a/clippy_tests/examples/bool_comparison.stderr b/clippy_tests/examples/bool_comparison.stderr index 02b80cb965c..b62f2e0c447 100644 --- a/clippy_tests/examples/bool_comparison.stderr +++ b/clippy_tests/examples/bool_comparison.stderr @@ -2,7 +2,7 @@ error: equality checks against true are unnecessary --> bool_comparison.rs:7:8 | 7 | if x == true { "yes" } else { "no" }; - | ^^^^^^^^^ help: try simplifying it as shown: `x` + | ^^^^^^^^^ help: try simplifying it as shown:: `x` | = note: `-D bool-comparison` implied by `-D warnings` @@ -10,19 +10,19 @@ error: equality checks against false can be replaced by a negation --> bool_comparison.rs:8:8 | 8 | if x == false { "yes" } else { "no" }; - | ^^^^^^^^^^ help: try simplifying it as shown: `!x` + | ^^^^^^^^^^ help: try simplifying it as shown:: `!x` error: equality checks against true are unnecessary --> bool_comparison.rs:9:8 | 9 | if true == x { "yes" } else { "no" }; - | ^^^^^^^^^ help: try simplifying it as shown: `x` + | ^^^^^^^^^ help: try simplifying it as shown:: `x` error: equality checks against false can be replaced by a negation --> bool_comparison.rs:10:8 | 10 | if false == x { "yes" } else { "no" }; - | ^^^^^^^^^^ help: try simplifying it as shown: `!x` + | ^^^^^^^^^^ help: try simplifying it as shown:: `!x` error: aborting due to 4 previous errors diff --git a/clippy_tests/examples/booleans.stderr b/clippy_tests/examples/booleans.stderr index 03fa72646a8..85cc8005205 100644 --- a/clippy_tests/examples/booleans.stderr +++ b/clippy_tests/examples/booleans.stderr @@ -2,7 +2,7 @@ error: this boolean expression contains a logic bug --> booleans.rs:12:13 | 12 | let _ = a && b || a; - | ^^^^^^^^^^^ help: it would look like the following `a` + | ^^^^^^^^^^^ help: it would look like the following: `a` | = note: `-D logic-bug` implied by `-D warnings` help: this expression can be optimized out by applying boolean operations to the outer expression @@ -15,7 +15,7 @@ error: this boolean expression can be simplified --> booleans.rs:14:13 | 14 | let _ = !true; - | ^^^^^ help: try `false` + | ^^^^^ help: try: `false` | = note: `-D nonminimal-bool` implied by `-D warnings` @@ -23,19 +23,19 @@ error: this boolean expression can be simplified --> booleans.rs:15:13 | 15 | let _ = !false; - | ^^^^^^ help: try `true` + | ^^^^^^ help: try: `true` error: this boolean expression can be simplified --> booleans.rs:16:13 | 16 | let _ = !!a; - | ^^^ help: try `a` + | ^^^ help: try: `a` error: this boolean expression contains a logic bug --> booleans.rs:17:13 | 17 | let _ = false && a; - | ^^^^^^^^^^ help: it would look like the following `false` + | ^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression --> booleans.rs:17:22 @@ -47,19 +47,31 @@ error: this boolean expression can be simplified --> booleans.rs:18:13 | 18 | let _ = false || a; - | ^^^^^^^^^^ help: try `a` + | ^^^^^^^^^^ help: try: `a` + +error: this boolean expression contains a logic bug + --> booleans.rs:20:13 + | +20 | let _ = cfg!(you_shall_not_not_pass) && a; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: it would look like the following: `false` + | +help: this expression can be optimized out by applying boolean operations to the outer expression + --> booleans.rs:20:45 + | +20 | let _ = cfg!(you_shall_not_not_pass) && a; + | ^ error: this boolean expression can be simplified --> booleans.rs:23:13 | 23 | let _ = !(!a && b); - | ^^^^^^^^^^ help: try `!b || a` + | ^^^^^^^^^^ help: try: `!b || a` error: this boolean expression contains a logic bug --> booleans.rs:33:13 | 33 | let _ = a == b && a != b; - | ^^^^^^^^^^^^^^^^ help: it would look like the following `false` + | ^^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression --> booleans.rs:33:13 @@ -97,7 +109,7 @@ error: this boolean expression contains a logic bug --> booleans.rs:36:13 | 36 | let _ = a < b && a >= b; - | ^^^^^^^^^^^^^^^ help: it would look like the following `false` + | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression --> booleans.rs:36:13 @@ -109,7 +121,7 @@ error: this boolean expression contains a logic bug --> booleans.rs:37:13 | 37 | let _ = a > b && a <= b; - | ^^^^^^^^^^^^^^^ help: it would look like the following `false` + | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression --> booleans.rs:37:13 @@ -130,7 +142,7 @@ help: try 39 | let _ = !(a == b && c == d); | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 13 previous errors +error: aborting due to 14 previous errors To learn more, run the command again with --verbose. diff --git a/clippy_tests/examples/borrow_box.stderr b/clippy_tests/examples/borrow_box.stderr index 90ab28afcd9..e494bdd214e 100644 --- a/clippy_tests/examples/borrow_box.stderr +++ b/clippy_tests/examples/borrow_box.stderr @@ -2,7 +2,7 @@ error: you seem to be trying to use `&Box`. Consider using just `&T` --> borrow_box.rs:9:19 | 9 | pub fn test1(foo: &mut Box) { - | ^^^^^^^^^^^^^^ help: try `&mut bool` + | ^^^^^^^^^^^^^^ help: try: `&mut bool` | note: lint level defined here --> borrow_box.rs:4:9 @@ -14,19 +14,19 @@ error: you seem to be trying to use `&Box`. Consider using just `&T` --> borrow_box.rs:14:14 | 14 | let foo: &Box; - | ^^^^^^^^^^ help: try `&bool` + | ^^^^^^^^^^ help: try: `&bool` error: you seem to be trying to use `&Box`. Consider using just `&T` --> borrow_box.rs:18:10 | 18 | foo: &'a Box - | ^^^^^^^^^^^^^ help: try `&'a bool` + | ^^^^^^^^^^^^^ help: try: `&'a bool` error: you seem to be trying to use `&Box`. Consider using just `&T` --> borrow_box.rs:22:17 | 22 | fn test4(a: &Box); - | ^^^^^^^^^^ help: try `&bool` + | ^^^^^^^^^^ help: try: `&bool` error: aborting due to 4 previous errors diff --git a/clippy_tests/examples/cmp_owned.stderr b/clippy_tests/examples/cmp_owned.stderr index bf7e642914f..067f1e68c6e 100644 --- a/clippy_tests/examples/cmp_owned.stderr +++ b/clippy_tests/examples/cmp_owned.stderr @@ -2,7 +2,7 @@ error: this creates an owned instance just for comparison --> cmp_owned.rs:8:14 | 8 | x != "foo".to_string(); - | ^^^^^^^^^^^^^^^^^ help: try `"foo"` + | ^^^^^^^^^^^^^^^^^ help: try: `"foo"` | = note: `-D cmp-owned` implied by `-D warnings` @@ -10,25 +10,25 @@ error: this creates an owned instance just for comparison --> cmp_owned.rs:10:9 | 10 | "foo".to_string() != x; - | ^^^^^^^^^^^^^^^^^ help: try `"foo"` + | ^^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison --> cmp_owned.rs:17:10 | 17 | x != "foo".to_owned(); - | ^^^^^^^^^^^^^^^^ help: try `"foo"` + | ^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison --> cmp_owned.rs:19:10 | 19 | x != String::from("foo"); - | ^^^^^^^^^^^^^^^^^^^ help: try `"foo"` + | ^^^^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison --> cmp_owned.rs:23:5 | 23 | Foo.to_owned() == Foo; - | ^^^^^^^^^^^^^^ help: try `Foo` + | ^^^^^^^^^^^^^^ help: try: `Foo` error: this creates an owned instance just for comparison --> cmp_owned.rs:30:9 diff --git a/clippy_tests/examples/entry.stderr b/clippy_tests/examples/entry.stderr index de5c22e41a7..dd29d5e14f2 100644 --- a/clippy_tests/examples/entry.stderr +++ b/clippy_tests/examples/entry.stderr @@ -2,7 +2,7 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` --> entry.rs:13:5 | 13 | if !m.contains_key(&k) { m.insert(k, v); } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `m.entry(k).or_insert(v)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `m.entry(k).or_insert(v)` | = note: `-D map-entry` implied by `-D warnings` @@ -10,37 +10,37 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` --> entry.rs:17:5 | 17 | if !m.contains_key(&k) { foo(); m.insert(k, v); } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `m.entry(k)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `m.entry(k)` error: usage of `contains_key` followed by `insert` on a `HashMap` --> entry.rs:21:5 | 21 | if !m.contains_key(&k) { m.insert(k, v) } else { None }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `m.entry(k)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `m.entry(k)` error: usage of `contains_key` followed by `insert` on a `HashMap` --> entry.rs:25:5 | 25 | if m.contains_key(&k) { None } else { m.insert(k, v) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `m.entry(k)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `m.entry(k)` error: usage of `contains_key` followed by `insert` on a `HashMap` --> entry.rs:29:5 | 29 | if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `m.entry(k)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `m.entry(k)` error: usage of `contains_key` followed by `insert` on a `HashMap` --> entry.rs:33:5 | 33 | if m.contains_key(&k) { None } else { foo(); m.insert(k, v) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `m.entry(k)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `m.entry(k)` error: usage of `contains_key` followed by `insert` on a `BTreeMap` --> entry.rs:37:5 | 37 | if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `m.entry(k)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `m.entry(k)` error: aborting due to 7 previous errors diff --git a/clippy_tests/examples/eq_op.stderr b/clippy_tests/examples/eq_op.stderr index 530dfac79ed..87e0e88584a 100644 --- a/clippy_tests/examples/eq_op.stderr +++ b/clippy_tests/examples/eq_op.stderr @@ -2,7 +2,7 @@ error: this boolean expression can be simplified --> eq_op.rs:37:5 | 37 | true && true; - | ^^^^^^^^^^^^ help: try `true` + | ^^^^^^^^^^^^ help: try: `true` | = note: `-D nonminimal-bool` implied by `-D warnings` @@ -10,31 +10,31 @@ error: this boolean expression can be simplified --> eq_op.rs:39:5 | 39 | true || true; - | ^^^^^^^^^^^^ help: try `true` + | ^^^^^^^^^^^^ help: try: `true` error: this boolean expression can be simplified --> eq_op.rs:45:5 | 45 | a == b && b == a; - | ^^^^^^^^^^^^^^^^ help: try `a == b` + | ^^^^^^^^^^^^^^^^ help: try: `a == b` error: this boolean expression can be simplified --> eq_op.rs:46:5 | 46 | a != b && b != a; - | ^^^^^^^^^^^^^^^^ help: try `a != b` + | ^^^^^^^^^^^^^^^^ help: try: `a != b` error: this boolean expression can be simplified --> eq_op.rs:47:5 | 47 | a < b && b > a; - | ^^^^^^^^^^^^^^ help: try `a < b` + | ^^^^^^^^^^^^^^ help: try: `a < b` error: this boolean expression can be simplified --> eq_op.rs:48:5 | 48 | a <= b && b >= a; - | ^^^^^^^^^^^^^^^^ help: try `a <= b` + | ^^^^^^^^^^^^^^^^ help: try: `a <= b` error: equal expressions as operands to `==` --> eq_op.rs:10:5 @@ -200,7 +200,7 @@ error: taken reference of right operand 89 | let z = x & &y; | ^^^^-- | | - | help: use the right value directly `y` + | help: use the right value directly: `y` | = note: `-D op-ref` implied by `-D warnings` diff --git a/clippy_tests/examples/eta.stderr b/clippy_tests/examples/eta.stderr index e6600be3358..f23f98f2bb7 100644 --- a/clippy_tests/examples/eta.stderr +++ b/clippy_tests/examples/eta.stderr @@ -2,7 +2,7 @@ error: redundant closure found --> eta.rs:7:27 | 7 | let a = Some(1u8).map(|a| foo(a)); - | ^^^^^^^^^^ help: remove closure as shown: `foo` + | ^^^^^^^^^^ help: remove closure as shown:: `foo` | = note: `-D redundant-closure` implied by `-D warnings` @@ -10,13 +10,13 @@ error: redundant closure found --> eta.rs:8:10 | 8 | meta(|a| foo(a)); - | ^^^^^^^^^^ help: remove closure as shown: `foo` + | ^^^^^^^^^^ help: remove closure as shown:: `foo` error: redundant closure found --> eta.rs:9:27 | 9 | let c = Some(1u8).map(|a| {1+2; foo}(a)); - | ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `{1+2; foo}` + | ^^^^^^^^^^^^^^^^^ help: remove closure as shown:: `{1+2; foo}` error: this expression borrows a reference that is immediately dereferenced by the compiler --> eta.rs:11:21 @@ -30,7 +30,7 @@ error: redundant closure found --> eta.rs:18:27 | 18 | let e = Some(1u8).map(|a| generic(a)); - | ^^^^^^^^^^^^^^ help: remove closure as shown: `generic` + | ^^^^^^^^^^^^^^ help: remove closure as shown:: `generic` error: aborting due to 5 previous errors diff --git a/clippy_tests/examples/float_cmp.stderr b/clippy_tests/examples/float_cmp.stderr index d0de1486eb7..476c94c8a5e 100644 --- a/clippy_tests/examples/float_cmp.stderr +++ b/clippy_tests/examples/float_cmp.stderr @@ -2,7 +2,7 @@ error: strict comparison of f32 or f64 --> float_cmp.rs:43:5 | 43 | ONE == 1f32; - | ^^^^^^^^^^^ help: consider comparing them within some error `(ONE - 1f32).abs() < error` + | ^^^^^^^^^^^ help: consider comparing them within some error: `(ONE - 1f32).abs() < error` | = note: `-D float-cmp` implied by `-D warnings` note: std::f32::EPSILON and std::f64::EPSILON are available. @@ -15,7 +15,7 @@ error: strict comparison of f32 or f64 --> float_cmp.rs:44:5 | 44 | ONE == 1.0 + 0.0; - | ^^^^^^^^^^^^^^^^ help: consider comparing them within some error `(ONE - (1.0 + 0.0)).abs() < error` + | ^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE - (1.0 + 0.0)).abs() < error` | note: std::f32::EPSILON and std::f64::EPSILON are available. --> float_cmp.rs:44:5 @@ -27,7 +27,7 @@ error: strict comparison of f32 or f64 --> float_cmp.rs:45:5 | 45 | ONE + ONE == ZERO + ONE + ONE; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error `(ONE + ONE - (ZERO + ONE + ONE)).abs() < error` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE + ONE - (ZERO + ONE + ONE)).abs() < error` | note: std::f32::EPSILON and std::f64::EPSILON are available. --> float_cmp.rs:45:5 @@ -39,7 +39,7 @@ error: strict comparison of f32 or f64 --> float_cmp.rs:46:5 | 46 | ONE != 2.0; - | ^^^^^^^^^^ help: consider comparing them within some error `(ONE - 2.0).abs() < error` + | ^^^^^^^^^^ help: consider comparing them within some error: `(ONE - 2.0).abs() < error` | note: std::f32::EPSILON and std::f64::EPSILON are available. --> float_cmp.rs:46:5 @@ -51,7 +51,7 @@ error: strict comparison of f32 or f64 --> float_cmp.rs:48:5 | 48 | twice(ONE) != ONE; - | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some error `(twice(ONE) - ONE).abs() < error` + | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(twice(ONE) - ONE).abs() < error` | note: std::f32::EPSILON and std::f64::EPSILON are available. --> float_cmp.rs:48:5 @@ -63,7 +63,7 @@ error: strict comparison of f32 or f64 --> float_cmp.rs:49:5 | 49 | ONE as f64 != 2.0; - | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some error `(ONE as f64 - 2.0).abs() < error` + | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE as f64 - 2.0).abs() < error` | note: std::f32::EPSILON and std::f64::EPSILON are available. --> float_cmp.rs:49:5 @@ -75,7 +75,7 @@ error: strict comparison of f32 or f64 --> float_cmp.rs:54:5 | 54 | x == 1.0; - | ^^^^^^^^ help: consider comparing them within some error `(x - 1.0).abs() < error` + | ^^^^^^^^ help: consider comparing them within some error: `(x - 1.0).abs() < error` | note: std::f32::EPSILON and std::f64::EPSILON are available. --> float_cmp.rs:54:5 @@ -87,7 +87,7 @@ error: strict comparison of f32 or f64 --> float_cmp.rs:57:5 | 57 | twice(x) != twice(ONE as f64); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error `(twice(x) - twice(ONE as f64)).abs() < error` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(twice(x) - twice(ONE as f64)).abs() < error` | note: std::f32::EPSILON and std::f64::EPSILON are available. --> float_cmp.rs:57:5 diff --git a/clippy_tests/examples/for_loop.stderr b/clippy_tests/examples/for_loop.stderr index 06765f35779..5cf8e611f4d 100644 --- a/clippy_tests/examples/for_loop.stderr +++ b/clippy_tests/examples/for_loop.stderr @@ -332,7 +332,7 @@ error: it is more idiomatic to loop over references to containers instead of usi --> for_loop.rs:203:15 | 203 | for _v in vec.iter() { } - | ^^^^^^^^^^ help: to write this more concisely, try `&vec` + | ^^^^^^^^^^ help: to write this more concisely, try: `&vec` | = note: `-D explicit-iter-loop` implied by `-D warnings` @@ -340,13 +340,13 @@ error: it is more idiomatic to loop over references to containers instead of usi --> for_loop.rs:205:15 | 205 | for _v in vec.iter_mut() { } - | ^^^^^^^^^^^^^^ help: to write this more concisely, try `&mut vec` + | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec` error: it is more idiomatic to loop over containers instead of using explicit iteration methods` --> for_loop.rs:208:15 | 208 | for _v in out_vec.into_iter() { } - | ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try `out_vec` + | ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec` | = note: `-D explicit-into-iter-loop` implied by `-D warnings` @@ -354,61 +354,61 @@ error: it is more idiomatic to loop over references to containers instead of usi --> for_loop.rs:211:15 | 211 | for _v in array.into_iter() {} - | ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try `&array` + | ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&array` error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods --> for_loop.rs:216:15 | 216 | for _v in [1, 2, 3].iter() { } - | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try `&[1, 2, 3]` + | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]` error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods --> for_loop.rs:220:15 | 220 | for _v in [0; 32].iter() {} - | ^^^^^^^^^^^^^^ help: to write this more concisely, try `&[0; 32]` + | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]` error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods --> for_loop.rs:225:15 | 225 | for _v in ll.iter() { } - | ^^^^^^^^^ help: to write this more concisely, try `&ll` + | ^^^^^^^^^ help: to write this more concisely, try: `&ll` error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods --> for_loop.rs:228:15 | 228 | for _v in vd.iter() { } - | ^^^^^^^^^ help: to write this more concisely, try `&vd` + | ^^^^^^^^^ help: to write this more concisely, try: `&vd` error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods --> for_loop.rs:231:15 | 231 | for _v in bh.iter() { } - | ^^^^^^^^^ help: to write this more concisely, try `&bh` + | ^^^^^^^^^ help: to write this more concisely, try: `&bh` error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods --> for_loop.rs:234:15 | 234 | for _v in hm.iter() { } - | ^^^^^^^^^ help: to write this more concisely, try `&hm` + | ^^^^^^^^^ help: to write this more concisely, try: `&hm` error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods --> for_loop.rs:237:15 | 237 | for _v in bt.iter() { } - | ^^^^^^^^^ help: to write this more concisely, try `&bt` + | ^^^^^^^^^ help: to write this more concisely, try: `&bt` error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods --> for_loop.rs:240:15 | 240 | for _v in hs.iter() { } - | ^^^^^^^^^ help: to write this more concisely, try `&hs` + | ^^^^^^^^^ help: to write this more concisely, try: `&hs` error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods --> for_loop.rs:243:15 | 243 | for _v in bs.iter() { } - | ^^^^^^^^^ help: to write this more concisely, try `&bs` + | ^^^^^^^^^ help: to write this more concisely, try: `&bs` error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want --> for_loop.rs:245:5 diff --git a/clippy_tests/examples/if_let_redundant_pattern_matching.stderr b/clippy_tests/examples/if_let_redundant_pattern_matching.stderr index afa7b20c8d6..aefe624a8d4 100644 --- a/clippy_tests/examples/if_let_redundant_pattern_matching.stderr +++ b/clippy_tests/examples/if_let_redundant_pattern_matching.stderr @@ -2,7 +2,7 @@ error: redundant pattern matching, consider using `is_ok()` --> if_let_redundant_pattern_matching.rs:9:12 | 9 | if let Ok(_) = Ok::(42) {} - | -------^^^^^--------------------- help: try this `if Ok::(42).is_ok()` + | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` | = note: `-D if-let-redundant-pattern-matching` implied by `-D warnings` @@ -10,19 +10,19 @@ error: redundant pattern matching, consider using `is_err()` --> if_let_redundant_pattern_matching.rs:11:12 | 11 | if let Err(_) = Err::(42) { - | -------^^^^^^---------------------- help: try this `if Err::(42).is_err()` + | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_none()` --> if_let_redundant_pattern_matching.rs:14:12 | 14 | if let None = None::<()> { - | -------^^^^------------- help: try this `if None::<()>.is_none()` + | -------^^^^------------- help: try this: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` --> if_let_redundant_pattern_matching.rs:17:12 | 17 | if let Some(_) = Some(42) { - | -------^^^^^^^----------- help: try this `if Some(42).is_some()` + | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` error: aborting due to 4 previous errors diff --git a/clippy_tests/examples/inconsistent_digit_grouping.rs b/clippy_tests/examples/inconsistent_digit_grouping.rs new file mode 100644 index 00000000000..06e8996deb7 --- /dev/null +++ b/clippy_tests/examples/inconsistent_digit_grouping.rs @@ -0,0 +1,8 @@ +#![feature(plugin)] +#![plugin(clippy)] +#[warn(inconsistent_digit_grouping)] +#[allow(unused_variables)] +fn main() { + let good = (123, 1_234, 1_2345_6789, 123_f32, 1_234.12_f32, 1_234.123_4_f32, 1.123_456_7_f32); + let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); +} diff --git a/clippy_tests/examples/inconsistent_digit_grouping.stderr b/clippy_tests/examples/inconsistent_digit_grouping.stderr new file mode 100644 index 00000000000..f86353eb266 --- /dev/null +++ b/clippy_tests/examples/inconsistent_digit_grouping.stderr @@ -0,0 +1,45 @@ +error: digits grouped inconsistently by underscores + --> inconsistent_digit_grouping.rs:7:16 + | +7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); + | ^^^^^^^^ + | + = note: `-D inconsistent-digit-grouping` implied by `-D warnings` + = help: consider making each group three or four digits + +error: digits grouped inconsistently by underscores + --> inconsistent_digit_grouping.rs:7:26 + | +7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); + | ^^^^^^^^^^ + | + = help: consider making each group three or four digits + +error: digits grouped inconsistently by underscores + --> inconsistent_digit_grouping.rs:7:38 + | +7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); + | ^^^^^^^^ + | + = help: consider making each group three or four digits + +error: digits grouped inconsistently by underscores + --> inconsistent_digit_grouping.rs:7:48 + | +7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); + | ^^^^^^^^^^^^^^ + | + = help: consider making each group three or four digits + +error: digits grouped inconsistently by underscores + --> inconsistent_digit_grouping.rs:7:64 + | +7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); + | ^^^^^^^^^^^^^^ + | + = help: consider making each group three or four digits + +error: aborting due to 5 previous errors + + +To learn more, run the command again with --verbose. diff --git a/clippy_tests/examples/large_digit_groups.rs b/clippy_tests/examples/large_digit_groups.rs new file mode 100644 index 00000000000..65bcdc7435e --- /dev/null +++ b/clippy_tests/examples/large_digit_groups.rs @@ -0,0 +1,8 @@ +#![feature(plugin)] +#![plugin(clippy)] +#[warn(large_digit_groups)] +#[allow(unused_variables)] +fn main() { + let good = (0b1011_i64, 0o1_234_u32, 0x1_234_567, 1_2345_6789, 1234_f32, 1_234.12_f32, 1_234.123_f32, 1.123_4_f32); + let bad = (0b1_10110_i64, 0x1_23456_78901_usize, 1_23456_f32, 1_23456.12_f32, 1_23456.12345_f32, 1_23456.12345_6_f32); +} diff --git a/clippy_tests/examples/large_digit_groups.stderr b/clippy_tests/examples/large_digit_groups.stderr new file mode 100644 index 00000000000..75d6461a547 --- /dev/null +++ b/clippy_tests/examples/large_digit_groups.stderr @@ -0,0 +1,53 @@ +error: digit groups should be smaller + --> large_digit_groups.rs:7:16 + | +7 | let bad = (0b1_10110_i64, 0x1_23456_78901_usize, 1_23456_f32, 1_23456.12_f32, 1_23456.12345_f32, 1_23456.12345_6_f32); + | ^^^^^^^^^^^^^ + | + = note: `-D large-digit-groups` implied by `-D warnings` + = help: consider using groups of three or four digits + +error: digit groups should be smaller + --> large_digit_groups.rs:7:31 + | +7 | let bad = (0b1_10110_i64, 0x1_23456_78901_usize, 1_23456_f32, 1_23456.12_f32, 1_23456.12345_f32, 1_23456.12345_6_f32); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using groups of three or four digits + +error: digit groups should be smaller + --> large_digit_groups.rs:7:54 + | +7 | let bad = (0b1_10110_i64, 0x1_23456_78901_usize, 1_23456_f32, 1_23456.12_f32, 1_23456.12345_f32, 1_23456.12345_6_f32); + | ^^^^^^^^^^^ + | + = help: consider using groups of three or four digits + +error: digit groups should be smaller + --> large_digit_groups.rs:7:67 + | +7 | let bad = (0b1_10110_i64, 0x1_23456_78901_usize, 1_23456_f32, 1_23456.12_f32, 1_23456.12345_f32, 1_23456.12345_6_f32); + | ^^^^^^^^^^^^^^ + | + = help: consider using groups of three or four digits + +error: digit groups should be smaller + --> large_digit_groups.rs:7:83 + | +7 | let bad = (0b1_10110_i64, 0x1_23456_78901_usize, 1_23456_f32, 1_23456.12_f32, 1_23456.12345_f32, 1_23456.12345_6_f32); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using groups of three or four digits + +error: digit groups should be smaller + --> large_digit_groups.rs:7:102 + | +7 | let bad = (0b1_10110_i64, 0x1_23456_78901_usize, 1_23456_f32, 1_23456.12_f32, 1_23456.12345_f32, 1_23456.12345_6_f32); + | ^^^^^^^^^^^^^^^^^^^ + | + = help: consider using groups of three or four digits + +error: aborting due to 6 previous errors + + +To learn more, run the command again with --verbose. diff --git a/clippy_tests/examples/len_zero.stderr b/clippy_tests/examples/len_zero.stderr index 0ab65d468f8..a1113047106 100644 --- a/clippy_tests/examples/len_zero.stderr +++ b/clippy_tests/examples/len_zero.stderr @@ -46,7 +46,7 @@ error: length comparison to zero --> len_zero.rs:130:8 | 130 | if x.len() == 0 { - | ^^^^^^^^^^^^ help: using `is_empty` is more concise: `x.is_empty()` + | ^^^^^^^^^^^^ help: using `is_empty` is more concise:: `x.is_empty()` | = note: `-D len-zero` implied by `-D warnings` @@ -54,37 +54,37 @@ error: length comparison to zero --> len_zero.rs:134:8 | 134 | if "".len() == 0 { - | ^^^^^^^^^^^^^ help: using `is_empty` is more concise: `"".is_empty()` + | ^^^^^^^^^^^^^ help: using `is_empty` is more concise:: `"".is_empty()` error: length comparison to zero --> len_zero.rs:148:8 | 148 | if has_is_empty.len() == 0 { - | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise: `has_is_empty.is_empty()` + | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise:: `has_is_empty.is_empty()` error: length comparison to zero --> len_zero.rs:151:8 | 151 | if has_is_empty.len() != 0 { - | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise: `!has_is_empty.is_empty()` + | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise:: `!has_is_empty.is_empty()` error: length comparison to zero --> len_zero.rs:154:8 | 154 | if has_is_empty.len() > 0 { - | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise: `!has_is_empty.is_empty()` + | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise:: `!has_is_empty.is_empty()` error: length comparison to zero --> len_zero.rs:160:8 | 160 | if with_is_empty.len() == 0 { - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise: `with_is_empty.is_empty()` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise:: `with_is_empty.is_empty()` error: length comparison to zero --> len_zero.rs:172:8 | 172 | if b.len() != 0 { - | ^^^^^^^^^^^^ help: using `is_empty` is more concise: `!b.is_empty()` + | ^^^^^^^^^^^^ help: using `is_empty` is more concise:: `!b.is_empty()` error: aborting due to 11 previous errors diff --git a/clippy_tests/examples/let_if_seq.stderr b/clippy_tests/examples/let_if_seq.stderr index e33adf4fd7c..eda6229427a 100644 --- a/clippy_tests/examples/let_if_seq.stderr +++ b/clippy_tests/examples/let_if_seq.stderr @@ -5,7 +5,7 @@ error: `if _ { .. } else { .. }` is an expression 58 | | if f() { 59 | | foo = 42; 60 | | } - | |_____^ help: it is more idiomatic to write `let foo = if f() { 42 } else { 0 };` + | |_____^ help: it is more idiomatic to write: `let foo = if f() { 42 } else { 0 };` | = note: `-D useless-let-if-seq` implied by `-D warnings` = note: you might not need `mut` at all @@ -20,7 +20,7 @@ error: `if _ { .. } else { .. }` is an expression ... | 68 | | f(); 69 | | } - | |_____^ help: it is more idiomatic to write `let bar = if f() { ..; 42 } else { ..; 0 };` + | |_____^ help: it is more idiomatic to write: `let bar = if f() { ..; 42 } else { ..; 0 };` | = note: you might not need `mut` at all @@ -33,7 +33,7 @@ error: `if _ { .. } else { .. }` is an expression 74 | | } else { 75 | | quz = 0; 76 | | } - | |_____^ help: it is more idiomatic to write `let quz = if f() { 42 } else { 0 };` + | |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };` error: `if _ { .. } else { .. }` is an expression --> let_if_seq.rs:100:5 @@ -42,7 +42,7 @@ error: `if _ { .. } else { .. }` is an expression 101 | | if f() { 102 | | baz = 42; 103 | | } - | |_____^ help: it is more idiomatic to write `let baz = if f() { 42 } else { 0 };` + | |_____^ help: it is more idiomatic to write: `let baz = if f() { 42 } else { 0 };` | = note: you might not need `mut` at all diff --git a/clippy_tests/examples/literals.rs b/clippy_tests/examples/literals.rs index fa76d330878..e8105a74b5c 100644 --- a/clippy_tests/examples/literals.rs +++ b/clippy_tests/examples/literals.rs @@ -14,7 +14,7 @@ fn main() { let fail1 = 0xabCD; let fail2 = 0xabCD_u32; let fail2 = 0xabCD_isize; - let fail_multi_zero = 000123usize; + let fail_multi_zero = 000_123usize; let ok6 = 1234_i32; let ok7 = 1234_f32; @@ -30,5 +30,5 @@ fn main() { let fail8 = 0123; let ok11 = 0o123; - let ok12 = 0b101010; + let ok12 = 0b10_1010; } diff --git a/clippy_tests/examples/literals.stderr b/clippy_tests/examples/literals.stderr index 5decf43be7e..6f6535b8d97 100644 --- a/clippy_tests/examples/literals.stderr +++ b/clippy_tests/examples/literals.stderr @@ -21,26 +21,26 @@ error: inconsistent casing in hexadecimal literal error: integer type suffix should be separated by an underscore --> literals.rs:17:27 | -17 | let fail_multi_zero = 000123usize; - | ^^^^^^^^^^^ +17 | let fail_multi_zero = 000_123usize; + | ^^^^^^^^^^^^ | = note: `-D unseparated-literal-suffix` implied by `-D warnings` error: this is a decimal constant --> literals.rs:17:27 | -17 | let fail_multi_zero = 000123usize; - | ^^^^^^^^^^^ +17 | let fail_multi_zero = 000_123usize; + | ^^^^^^^^^^^^ | = note: `-D zero-prefixed-literal` implied by `-D warnings` help: if you mean to use a decimal constant, remove the `0` to remove confusion: | -17 | let fail_multi_zero = 123usize; - | ^^^^^^^^ +17 | let fail_multi_zero = _123usize; + | ^^^^^^^^^ help: if you mean to use an octal constant, use `0o`: | -17 | let fail_multi_zero = 0o123usize; - | ^^^^^^^^^^ +17 | let fail_multi_zero = 0o_123usize; + | ^^^^^^^^^^^ error: integer type suffix should be separated by an underscore --> literals.rs:22:17 diff --git a/clippy_tests/examples/matches.stderr b/clippy_tests/examples/matches.stderr index 59e63ff2434..4a7491b8de6 100644 --- a/clippy_tests/examples/matches.stderr +++ b/clippy_tests/examples/matches.stderr @@ -5,7 +5,7 @@ error: you seem to be trying to use match for destructuring a single pattern. Co 27 | | ExprNode::ExprAddrOf => Some(&NODE), 28 | | _ => { let x = 5; None }, 29 | | } - | |_____^ help: try this `if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None }` + | |_____^ help: try this: `if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None }` | = note: `-D single-match-else` implied by `-D warnings` @@ -16,7 +16,7 @@ error: you seem to be trying to use match for destructuring a single pattern. Co 36 | | Some(y) => { println!("{:?}", y); } 37 | | _ => () 38 | | }; - | |_____^ help: try this `if let Some(y) = x { println!("{:?}", y); }` + | |_____^ help: try this: `if let Some(y) = x { println!("{:?}", y); }` | = note: `-D single-match` implied by `-D warnings` @@ -27,7 +27,7 @@ error: you seem to be trying to use match for destructuring a single pattern. Co 42 | | (2...3, 7...9) => dummy(), 43 | | _ => {} 44 | | }; - | |_____^ help: try this `if let (2...3, 7...9) = z { dummy() }` + | |_____^ help: try this: `if let (2...3, 7...9) = z { dummy() }` error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` --> matches.rs:63:5 @@ -36,7 +36,7 @@ error: you seem to be trying to use match for destructuring a single pattern. Co 64 | | Some(y) => dummy(), 65 | | None => () 66 | | }; - | |_____^ help: try this `if let Some(y) = x { dummy() }` + | |_____^ help: try this: `if let Some(y) = x { dummy() }` error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` --> matches.rs:68:5 @@ -45,7 +45,7 @@ error: you seem to be trying to use match for destructuring a single pattern. Co 69 | | Ok(y) => dummy(), 70 | | Err(..) => () 71 | | }; - | |_____^ help: try this `if let Ok(y) = y { dummy() }` + | |_____^ help: try this: `if let Ok(y) = y { dummy() }` error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` --> matches.rs:75:5 @@ -54,7 +54,7 @@ error: you seem to be trying to use match for destructuring a single pattern. Co 76 | | Cow::Borrowed(..) => dummy(), 77 | | Cow::Owned(..) => (), 78 | | }; - | |_____^ help: try this `if let Cow::Borrowed(..) = c { dummy() }` + | |_____^ help: try this: `if let Cow::Borrowed(..) = c { dummy() }` error: you seem to be trying to match on a boolean expression --> matches.rs:96:5 @@ -63,7 +63,7 @@ error: you seem to be trying to match on a boolean expression 97 | | true => 0, 98 | | false => 42, 99 | | }; - | |_____^ help: consider using an if/else expression `if test { 0 } else { 42 }` + | |_____^ help: consider using an if/else expression: `if test { 0 } else { 42 }` | = note: `-D match-bool` implied by `-D warnings` @@ -74,7 +74,7 @@ error: you seem to be trying to match on a boolean expression 103 | | true => 1, 104 | | false => 0, 105 | | }; - | |_____^ help: consider using an if/else expression `if option == 1 { 1 } else { 0 }` + | |_____^ help: consider using an if/else expression: `if option == 1 { 1 } else { 0 }` error: you seem to be trying to match on a boolean expression --> matches.rs:107:5 @@ -83,7 +83,7 @@ error: you seem to be trying to match on a boolean expression 108 | | true => (), 109 | | false => { println!("Noooo!"); } 110 | | }; - | |_____^ help: consider using an if/else expression `if !test { println!("Noooo!"); }` + | |_____^ help: consider using an if/else expression: `if !test { println!("Noooo!"); }` error: you seem to be trying to match on a boolean expression --> matches.rs:112:5 @@ -92,7 +92,7 @@ error: you seem to be trying to match on a boolean expression 113 | | false => { println!("Noooo!"); } 114 | | _ => (), 115 | | }; - | |_____^ help: consider using an if/else expression `if !test { println!("Noooo!"); }` + | |_____^ help: consider using an if/else expression: `if !test { println!("Noooo!"); }` error: you seem to be trying to match on a boolean expression --> matches.rs:117:5 @@ -101,7 +101,7 @@ error: you seem to be trying to match on a boolean expression 118 | | false => { println!("Noooo!"); } 119 | | _ => (), 120 | | }; - | |_____^ help: consider using an if/else expression `if !(test && test) { println!("Noooo!"); }` + | |_____^ help: consider using an if/else expression: `if !(test && test) { println!("Noooo!"); }` error: equal expressions as operands to `&&` --> matches.rs:117:11 @@ -118,7 +118,7 @@ error: you seem to be trying to match on a boolean expression 123 | | false => { println!("Noooo!"); } 124 | | true => { println!("Yes!"); } 125 | | }; - | |_____^ help: consider using an if/else expression `if test { println!("Yes!"); } else { println!("Noooo!"); }` + | |_____^ help: consider using an if/else expression: `if test { println!("Yes!"); } else { println!("Noooo!"); }` error: you don't need to add `&` to all patterns --> matches.rs:138:9 @@ -156,7 +156,7 @@ error: you don't need to add `&` to both the expression and the patterns 155 | | &Some(v) => println!("{:?}", v), 156 | | &None => println!("none"), 157 | | } - | |_____^ help: try `match w { .. }` + | |_____^ help: try: `match w { .. }` error: you don't need to add `&` to all patterns --> matches.rs:165:5 @@ -177,7 +177,7 @@ error: you don't need to add `&` to both the expression and the patterns 170 | / if let &None = &b { 171 | | println!("none"); 172 | | } - | |_____^ help: try `if let .. = b { .. }` + | |_____^ help: try: `if let .. = b { .. }` error: some ranges overlap --> matches.rs:179:9 diff --git a/clippy_tests/examples/methods.stderr b/clippy_tests/examples/methods.stderr index 51cbf35a471..c45eab9f499 100644 --- a/clippy_tests/examples/methods.stderr +++ b/clippy_tests/examples/methods.stderr @@ -182,7 +182,7 @@ error: use of `unwrap_or` followed by a function call --> methods.rs:268:5 | 268 | with_constructor.unwrap_or(make()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `with_constructor.unwrap_or_else(make)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_constructor.unwrap_or_else(make)` | = note: `-D or-fun-call` implied by `-D warnings` @@ -190,67 +190,67 @@ error: use of `unwrap_or` followed by a call to `new` --> methods.rs:271:5 | 271 | with_new.unwrap_or(Vec::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `with_new.unwrap_or_default()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_new.unwrap_or_default()` error: use of `unwrap_or` followed by a function call --> methods.rs:274:5 | 274 | with_const_args.unwrap_or(Vec::with_capacity(12)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `with_const_args.unwrap_or_else(|| Vec::with_capacity(12))` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_const_args.unwrap_or_else(|| Vec::with_capacity(12))` error: use of `unwrap_or` followed by a function call --> methods.rs:277:5 | 277 | with_err.unwrap_or(make()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `with_err.unwrap_or_else(|_| make())` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_err.unwrap_or_else(|_| make())` error: use of `unwrap_or` followed by a function call --> methods.rs:280:5 | 280 | with_err_args.unwrap_or(Vec::with_capacity(12)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `with_err_args.unwrap_or_else(|_| Vec::with_capacity(12))` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_err_args.unwrap_or_else(|_| Vec::with_capacity(12))` error: use of `unwrap_or` followed by a call to `default` --> methods.rs:283:5 | 283 | with_default_trait.unwrap_or(Default::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `with_default_trait.unwrap_or_default()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_trait.unwrap_or_default()` error: use of `unwrap_or` followed by a call to `default` --> methods.rs:286:5 | 286 | with_default_type.unwrap_or(u64::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `with_default_type.unwrap_or_default()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_type.unwrap_or_default()` error: use of `unwrap_or` followed by a function call --> methods.rs:289:5 | 289 | with_vec.unwrap_or(vec![]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `with_vec.unwrap_or_else(|| < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] ))` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_vec.unwrap_or_else(|| < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] ))` error: use of `unwrap_or` followed by a function call --> methods.rs:294:5 | 294 | without_default.unwrap_or(Foo::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `without_default.unwrap_or_else(Foo::new)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `without_default.unwrap_or_else(Foo::new)` error: use of `or_insert` followed by a function call --> methods.rs:297:5 | 297 | map.entry(42).or_insert(String::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `map.entry(42).or_insert_with(String::new)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `map.entry(42).or_insert_with(String::new)` error: use of `or_insert` followed by a function call --> methods.rs:300:5 | 300 | btree.entry(42).or_insert(String::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `btree.entry(42).or_insert_with(String::new)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `btree.entry(42).or_insert_with(String::new)` error: use of `unwrap_or` followed by a function call --> methods.rs:303:13 | 303 | let _ = stringy.unwrap_or("".to_owned()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `stringy.unwrap_or_else(|| "".to_owned())` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `stringy.unwrap_or_else(|| "".to_owned())` error: called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable --> methods.rs:314:23 @@ -326,7 +326,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co --> methods.rs:369:17 | 369 | let _ = boxed_slice.get(1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&boxed_slice[1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&boxed_slice[1]` | = note: `-D get-unwrap` implied by `-D warnings` @@ -334,55 +334,55 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co --> methods.rs:370:17 | 370 | let _ = some_slice.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&some_slice[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]` error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise --> methods.rs:371:17 | 371 | let _ = some_vec.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&some_vec[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]` error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise --> methods.rs:372:17 | 372 | let _ = some_vecdeque.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&some_vecdeque[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]` error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise --> methods.rs:373:17 | 373 | let _ = some_hashmap.get(&1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&some_hashmap[&1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]` error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise --> methods.rs:374:17 | 374 | let _ = some_btreemap.get(&1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&some_btreemap[&1]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]` error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise --> methods.rs:379:10 | 379 | *boxed_slice.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&mut boxed_slice[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&mut boxed_slice[0]` error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise --> methods.rs:380:10 | 380 | *some_slice.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&mut some_slice[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&mut some_slice[0]` error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise --> methods.rs:381:10 | 381 | *some_vec.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&mut some_vec[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&mut some_vec[0]` error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise --> methods.rs:382:10 | 382 | *some_vecdeque.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&mut some_vecdeque[0]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&mut some_vecdeque[0]` error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message --> methods.rs:396:13 @@ -436,7 +436,7 @@ error: you should use the `starts_with` method --> methods.rs:425:5 | 425 | "".chars().next() == Some(' '); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this `"".starts_with(' ')` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with(' ')` | = note: `-D chars-next-cmp` implied by `-D warnings` @@ -444,13 +444,13 @@ error: you should use the `starts_with` method --> methods.rs:426:5 | 426 | Some(' ') != "".chars().next(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this `!"".starts_with(' ')` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with(' ')` error: calling `.extend(_.chars())` --> methods.rs:435:5 | 435 | s.extend(abc.chars()); - | ^^^^^^^^^^^^^^^^^^^^^ help: try this `s.push_str(abc)` + | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(abc)` | = note: `-D string-extend-chars` implied by `-D warnings` @@ -458,19 +458,19 @@ error: calling `.extend(_.chars())` --> methods.rs:438:5 | 438 | s.extend("abc".chars()); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try this `s.push_str("abc")` + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str("abc")` error: calling `.extend(_.chars())` --> methods.rs:441:5 | 441 | s.extend(def.chars()); - | ^^^^^^^^^^^^^^^^^^^^^ help: try this `s.push_str(&def)` + | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&def)` error: using `clone` on a `Copy` type --> methods.rs:452:5 | 452 | 42.clone(); - | ^^^^^^^^^^ help: try removing the `clone` call `42` + | ^^^^^^^^^^ help: try removing the `clone` call: `42` | = note: `-D clone-on-copy` implied by `-D warnings` @@ -478,25 +478,25 @@ error: using `clone` on a `Copy` type --> methods.rs:456:5 | 456 | (&42).clone(); - | ^^^^^^^^^^^^^ help: try dereferencing it `*(&42)` + | ^^^^^^^^^^^^^ help: try dereferencing it: `*(&42)` error: using `clone` on a `Copy` type --> methods.rs:460:5 | 460 | t.clone(); - | ^^^^^^^^^ help: try removing the `clone` call `t` + | ^^^^^^^^^ help: try removing the `clone` call: `t` error: using `clone` on a `Copy` type --> methods.rs:462:5 | 462 | Some(t).clone(); - | ^^^^^^^^^^^^^^^ help: try removing the `clone` call `Some(t)` + | ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)` error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type --> methods.rs:468:22 | 468 | let z: &Vec<_> = y.clone(); - | ^^^^^^^^^ help: try dereferencing it `(*y).clone()` + | ^^^^^^^^^ help: try dereferencing it: `(*y).clone()` | = note: `-D clone-double-ref` implied by `-D warnings` @@ -504,7 +504,7 @@ error: single-character string constant used as pattern --> methods.rs:475:13 | 475 | x.split("x"); - | --------^^^- help: try using a char instead: `x.split('x')` + | --------^^^- help: try using a char instead:: `x.split('x')` | = note: `-D single-char-pattern` implied by `-D warnings` @@ -512,97 +512,97 @@ error: single-character string constant used as pattern --> methods.rs:492:16 | 492 | x.contains("x"); - | -----------^^^- help: try using a char instead: `x.contains('x')` + | -----------^^^- help: try using a char instead:: `x.contains('x')` error: single-character string constant used as pattern --> methods.rs:493:19 | 493 | x.starts_with("x"); - | --------------^^^- help: try using a char instead: `x.starts_with('x')` + | --------------^^^- help: try using a char instead:: `x.starts_with('x')` error: single-character string constant used as pattern --> methods.rs:494:17 | 494 | x.ends_with("x"); - | ------------^^^- help: try using a char instead: `x.ends_with('x')` + | ------------^^^- help: try using a char instead:: `x.ends_with('x')` error: single-character string constant used as pattern --> methods.rs:495:12 | 495 | x.find("x"); - | -------^^^- help: try using a char instead: `x.find('x')` + | -------^^^- help: try using a char instead:: `x.find('x')` error: single-character string constant used as pattern --> methods.rs:496:13 | 496 | x.rfind("x"); - | --------^^^- help: try using a char instead: `x.rfind('x')` + | --------^^^- help: try using a char instead:: `x.rfind('x')` error: single-character string constant used as pattern --> methods.rs:497:14 | 497 | x.rsplit("x"); - | ---------^^^- help: try using a char instead: `x.rsplit('x')` + | ---------^^^- help: try using a char instead:: `x.rsplit('x')` error: single-character string constant used as pattern --> methods.rs:498:24 | 498 | x.split_terminator("x"); - | -------------------^^^- help: try using a char instead: `x.split_terminator('x')` + | -------------------^^^- help: try using a char instead:: `x.split_terminator('x')` error: single-character string constant used as pattern --> methods.rs:499:25 | 499 | x.rsplit_terminator("x"); - | --------------------^^^- help: try using a char instead: `x.rsplit_terminator('x')` + | --------------------^^^- help: try using a char instead:: `x.rsplit_terminator('x')` error: single-character string constant used as pattern --> methods.rs:500:17 | 500 | x.splitn(0, "x"); - | ------------^^^- help: try using a char instead: `x.splitn(0, 'x')` + | ------------^^^- help: try using a char instead:: `x.splitn(0, 'x')` error: single-character string constant used as pattern --> methods.rs:501:18 | 501 | x.rsplitn(0, "x"); - | -------------^^^- help: try using a char instead: `x.rsplitn(0, 'x')` + | -------------^^^- help: try using a char instead:: `x.rsplitn(0, 'x')` error: single-character string constant used as pattern --> methods.rs:502:15 | 502 | x.matches("x"); - | ----------^^^- help: try using a char instead: `x.matches('x')` + | ----------^^^- help: try using a char instead:: `x.matches('x')` error: single-character string constant used as pattern --> methods.rs:503:16 | 503 | x.rmatches("x"); - | -----------^^^- help: try using a char instead: `x.rmatches('x')` + | -----------^^^- help: try using a char instead:: `x.rmatches('x')` error: single-character string constant used as pattern --> methods.rs:504:21 | 504 | x.match_indices("x"); - | ----------------^^^- help: try using a char instead: `x.match_indices('x')` + | ----------------^^^- help: try using a char instead:: `x.match_indices('x')` error: single-character string constant used as pattern --> methods.rs:505:22 | 505 | x.rmatch_indices("x"); - | -----------------^^^- help: try using a char instead: `x.rmatch_indices('x')` + | -----------------^^^- help: try using a char instead:: `x.rmatch_indices('x')` error: single-character string constant used as pattern --> methods.rs:506:25 | 506 | x.trim_left_matches("x"); - | --------------------^^^- help: try using a char instead: `x.trim_left_matches('x')` + | --------------------^^^- help: try using a char instead:: `x.trim_left_matches('x')` error: single-character string constant used as pattern --> methods.rs:507:26 | 507 | x.trim_right_matches("x"); - | ---------------------^^^- help: try using a char instead: `x.trim_right_matches('x')` + | ---------------------^^^- help: try using a char instead:: `x.trim_right_matches('x')` error: you are getting the inner pointer of a temporary `CString` --> methods.rs:517:5 diff --git a/clippy_tests/examples/needless_bool.stderr b/clippy_tests/examples/needless_bool.stderr index c521e1228c7..6d129777fa9 100644 --- a/clippy_tests/examples/needless_bool.stderr +++ b/clippy_tests/examples/needless_bool.stderr @@ -16,19 +16,19 @@ error: this if-then-else expression returns a bool literal --> needless_bool.rs:11:5 | 11 | if x { true } else { false }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to `x` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `x` error: this if-then-else expression returns a bool literal --> needless_bool.rs:12:5 | 12 | if x { false } else { true }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to `!x` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `!x` error: this if-then-else expression returns a bool literal --> needless_bool.rs:13:5 | 13 | if x && y { false } else { true }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to `!(x && y)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `!(x && y)` error: this if-then-else expression will always return true --> needless_bool.rs:25:5 @@ -46,25 +46,25 @@ error: this if-then-else expression returns a bool literal --> needless_bool.rs:35:5 | 35 | if x { return true } else { return false }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to `return x` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `return x` error: this if-then-else expression returns a bool literal --> needless_bool.rs:40:5 | 40 | if x && y { return true } else { return false }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to `return x && y` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `return x && y` error: this if-then-else expression returns a bool literal --> needless_bool.rs:45:5 | 45 | if x { return false } else { return true }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to `return !x` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `return !x` error: this if-then-else expression returns a bool literal --> needless_bool.rs:50:5 | 50 | if x && y { return false } else { return true }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to `return !(x && y)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `return !(x && y)` error: aborting due to 11 previous errors diff --git a/clippy_tests/examples/needless_pass_by_value.stderr b/clippy_tests/examples/needless_pass_by_value.stderr index 12a9640e767..15701d65124 100644 --- a/clippy_tests/examples/needless_pass_by_value.stderr +++ b/clippy_tests/examples/needless_pass_by_value.stderr @@ -2,7 +2,7 @@ error: this argument is passed by value, but not consumed in the function body --> needless_pass_by_value.rs:9:23 | 9 | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec { - | ^^^^^^ help: consider changing the type to `&[T]` + | ^^^^^^ help: consider changing the type to: `&[T]` | = note: `-D needless-pass-by-value` implied by `-D warnings` @@ -10,19 +10,19 @@ error: this argument is passed by value, but not consumed in the function body --> needless_pass_by_value.rs:23:11 | 23 | fn bar(x: String, y: Wrapper) { - | ^^^^^^ help: consider changing the type to `&str` + | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body --> needless_pass_by_value.rs:23:22 | 23 | fn bar(x: String, y: Wrapper) { - | ^^^^^^^ help: consider taking a reference instead `&Wrapper` + | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body --> needless_pass_by_value.rs:29:63 | 29 | fn test_borrow_trait, U>(t: T, u: U) { - | ^ help: consider taking a reference instead `&U` + | ^ help: consider taking a reference instead: `&U` error: this argument is passed by value, but not consumed in the function body --> needless_pass_by_value.rs:40:18 @@ -40,7 +40,7 @@ error: this argument is passed by value, but not consumed in the function body --> needless_pass_by_value.rs:53:24 | 53 | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { - | ^^^^^^^ help: consider taking a reference instead `&Wrapper` + | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body --> needless_pass_by_value.rs:53:36 diff --git a/clippy_tests/examples/needless_return.stderr b/clippy_tests/examples/needless_return.stderr index 8cd549c96da..158f9c432df 100644 --- a/clippy_tests/examples/needless_return.stderr +++ b/clippy_tests/examples/needless_return.stderr @@ -2,7 +2,7 @@ error: unneeded return statement --> needless_return.rs:11:5 | 11 | return true; - | ^^^^^^^^^^^^ help: remove `return` as shown: `true` + | ^^^^^^^^^^^^ help: remove `return` as shown:: `true` | = note: `-D needless-return` implied by `-D warnings` @@ -10,43 +10,43 @@ error: unneeded return statement --> needless_return.rs:15:5 | 15 | return true - | ^^^^^^^^^^^ help: remove `return` as shown: `true` + | ^^^^^^^^^^^ help: remove `return` as shown:: `true` error: unneeded return statement --> needless_return.rs:20:9 | 20 | return true; - | ^^^^^^^^^^^^ help: remove `return` as shown: `true` + | ^^^^^^^^^^^^ help: remove `return` as shown:: `true` error: unneeded return statement --> needless_return.rs:22:9 | 22 | return false; - | ^^^^^^^^^^^^^ help: remove `return` as shown: `false` + | ^^^^^^^^^^^^^ help: remove `return` as shown:: `false` error: unneeded return statement --> needless_return.rs:28:17 | 28 | true => return false, - | ^^^^^^^^^^^^ help: remove `return` as shown: `false` + | ^^^^^^^^^^^^ help: remove `return` as shown:: `false` error: unneeded return statement --> needless_return.rs:30:13 | 30 | return true; - | ^^^^^^^^^^^^ help: remove `return` as shown: `true` + | ^^^^^^^^^^^^ help: remove `return` as shown:: `true` error: unneeded return statement --> needless_return.rs:37:9 | 37 | return true; - | ^^^^^^^^^^^^ help: remove `return` as shown: `true` + | ^^^^^^^^^^^^ help: remove `return` as shown:: `true` error: unneeded return statement --> needless_return.rs:39:16 | 39 | let _ = || return true; - | ^^^^^^^^^^^ help: remove `return` as shown: `true` + | ^^^^^^^^^^^ help: remove `return` as shown:: `true` error: aborting due to 8 previous errors diff --git a/clippy_tests/examples/no_effect.stderr b/clippy_tests/examples/no_effect.stderr index 48ed821635f..4d1c29ed079 100644 --- a/clippy_tests/examples/no_effect.stderr +++ b/clippy_tests/examples/no_effect.stderr @@ -154,7 +154,7 @@ error: statement can be reduced --> no_effect.rs:65:5 | 65 | Tuple(get_number()); - | ^^^^^^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` | = note: `-D unnecessary-operation` implied by `-D warnings` @@ -162,109 +162,109 @@ error: statement can be reduced --> no_effect.rs:66:5 | 66 | Struct { field: get_number() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: statement can be reduced --> no_effect.rs:67:5 | 67 | Struct { ..get_struct() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with `get_struct();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_struct();` error: statement can be reduced --> no_effect.rs:68:5 | 68 | Enum::Tuple(get_number()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: statement can be reduced --> no_effect.rs:69:5 | 69 | Enum::Struct { field: get_number() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: statement can be reduced --> no_effect.rs:70:5 | 70 | 5 + get_number(); - | ^^^^^^^^^^^^^^^^^ help: replace it with `5;get_number();` + | ^^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();` error: statement can be reduced --> no_effect.rs:71:5 | 71 | *&get_number(); - | ^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: statement can be reduced --> no_effect.rs:72:5 | 72 | &get_number(); - | ^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: statement can be reduced --> no_effect.rs:73:5 | 73 | (5, 6, get_number()); - | ^^^^^^^^^^^^^^^^^^^^^ help: replace it with `5;6;get_number();` + | ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `5;6;get_number();` error: statement can be reduced --> no_effect.rs:74:5 | 74 | box get_number(); - | ^^^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: statement can be reduced --> no_effect.rs:75:5 | 75 | get_number()..; - | ^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: statement can be reduced --> no_effect.rs:76:5 | 76 | ..get_number(); - | ^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: statement can be reduced --> no_effect.rs:77:5 | 77 | 5..get_number(); - | ^^^^^^^^^^^^^^^^ help: replace it with `5;get_number();` + | ^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();` error: statement can be reduced --> no_effect.rs:78:5 | 78 | [42, get_number()]; - | ^^^^^^^^^^^^^^^^^^^ help: replace it with `42;get_number();` + | ^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();` error: statement can be reduced --> no_effect.rs:79:5 | 79 | [42, 55][get_number() as usize]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with `[42, 55];get_number() as usize;` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42, 55];get_number() as usize;` error: statement can be reduced --> no_effect.rs:80:5 | 80 | (42, get_number()).1; - | ^^^^^^^^^^^^^^^^^^^^^ help: replace it with `42;get_number();` + | ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();` error: statement can be reduced --> no_effect.rs:81:5 | 81 | [get_number(); 55]; - | ^^^^^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: statement can be reduced --> no_effect.rs:82:5 | 82 | [42; 55][get_number() as usize]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with `[42; 55];get_number() as usize;` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42; 55];get_number() as usize;` error: statement can be reduced --> no_effect.rs:83:5 | 83 | {get_number()}; - | ^^^^^^^^^^^^^^^ help: replace it with `get_number();` + | ^^^^^^^^^^^^^^^ help: replace it with: `get_number();` error: aborting due to 44 previous errors diff --git a/clippy_tests/examples/precedence.stderr b/clippy_tests/examples/precedence.stderr index 516ddf5622b..945279092bc 100644 --- a/clippy_tests/examples/precedence.stderr +++ b/clippy_tests/examples/precedence.stderr @@ -2,7 +2,7 @@ error: operator precedence can trip the unwary --> precedence.rs:8:5 | 8 | 1 << 2 + 3; - | ^^^^^^^^^^ help: consider parenthesizing your expression `1 << (2 + 3)` + | ^^^^^^^^^^ help: consider parenthesizing your expression: `1 << (2 + 3)` | = note: `-D precedence` implied by `-D warnings` @@ -10,49 +10,49 @@ error: operator precedence can trip the unwary --> precedence.rs:9:5 | 9 | 1 + 2 << 3; - | ^^^^^^^^^^ help: consider parenthesizing your expression `(1 + 2) << 3` + | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3` error: operator precedence can trip the unwary --> precedence.rs:10:5 | 10 | 4 >> 1 + 1; - | ^^^^^^^^^^ help: consider parenthesizing your expression `4 >> (1 + 1)` + | ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)` error: operator precedence can trip the unwary --> precedence.rs:11:5 | 11 | 1 + 3 >> 2; - | ^^^^^^^^^^ help: consider parenthesizing your expression `(1 + 3) >> 2` + | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2` error: operator precedence can trip the unwary --> precedence.rs:12:5 | 12 | 1 ^ 1 - 1; - | ^^^^^^^^^ help: consider parenthesizing your expression `1 ^ (1 - 1)` + | ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)` error: operator precedence can trip the unwary --> precedence.rs:13:5 | 13 | 3 | 2 - 1; - | ^^^^^^^^^ help: consider parenthesizing your expression `3 | (2 - 1)` + | ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)` error: operator precedence can trip the unwary --> precedence.rs:14:5 | 14 | 3 & 5 - 2; - | ^^^^^^^^^ help: consider parenthesizing your expression `3 & (5 - 2)` + | ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)` error: unary minus has lower precedence than method call --> precedence.rs:15:5 | 15 | -1i32.abs(); - | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent `-(1i32.abs())` + | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1i32.abs())` error: unary minus has lower precedence than method call --> precedence.rs:16:5 | 16 | -1f32.abs(); - | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent `-(1f32.abs())` + | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1f32.abs())` error: aborting due to 9 previous errors diff --git a/clippy_tests/examples/redundant_closure_call.stderr b/clippy_tests/examples/redundant_closure_call.stderr index 4b346d01ed7..0dc9672b15c 100644 --- a/clippy_tests/examples/redundant_closure_call.stderr +++ b/clippy_tests/examples/redundant_closure_call.stderr @@ -16,7 +16,7 @@ error: Try not to call a closure in the expression where it is declared. --> redundant_closure_call.rs:7:10 | 7 | let a = (|| 42)(); - | ^^^^^^^^^ help: Try doing something like: `42` + | ^^^^^^^^^ help: Try doing something like: : `42` error: Try not to call a closure in the expression where it is declared. --> redundant_closure_call.rs:10:14 diff --git a/clippy_tests/examples/reference.stderr b/clippy_tests/examples/reference.stderr index acc6b033a13..6e8bfedf433 100644 --- a/clippy_tests/examples/reference.stderr +++ b/clippy_tests/examples/reference.stderr @@ -2,7 +2,7 @@ error: immediately dereferencing a reference --> reference.rs:19:13 | 19 | let b = *&a; - | ^^^ help: try this `a` + | ^^^ help: try this: `a` | = note: `-D deref-addrof` implied by `-D warnings` @@ -10,61 +10,61 @@ error: immediately dereferencing a reference --> reference.rs:21:13 | 21 | let b = *&get_number(); - | ^^^^^^^^^^^^^^ help: try this `get_number()` + | ^^^^^^^^^^^^^^ help: try this: `get_number()` error: immediately dereferencing a reference --> reference.rs:26:13 | 26 | let b = *&bytes[1..2][0]; - | ^^^^^^^^^^^^^^^^ help: try this `bytes[1..2][0]` + | ^^^^^^^^^^^^^^^^ help: try this: `bytes[1..2][0]` error: immediately dereferencing a reference --> reference.rs:30:13 | 30 | let b = *&(a); - | ^^^^^ help: try this `(a)` + | ^^^^^ help: try this: `(a)` error: immediately dereferencing a reference --> reference.rs:32:13 | 32 | let b = *(&a); - | ^^^^^ help: try this `a` + | ^^^^^ help: try this: `a` error: immediately dereferencing a reference --> reference.rs:34:13 | 34 | let b = *((&a)); - | ^^^^^^^ help: try this `a` + | ^^^^^^^ help: try this: `a` error: immediately dereferencing a reference --> reference.rs:36:13 | 36 | let b = *&&a; - | ^^^^ help: try this `&a` + | ^^^^ help: try this: `&a` error: immediately dereferencing a reference --> reference.rs:38:14 | 38 | let b = **&aref; - | ^^^^^^ help: try this `aref` + | ^^^^^^ help: try this: `aref` error: immediately dereferencing a reference --> reference.rs:42:14 | 42 | let b = **&&a; - | ^^^^ help: try this `&a` + | ^^^^ help: try this: `&a` error: immediately dereferencing a reference --> reference.rs:46:17 | 46 | let y = *&mut x; - | ^^^^^^^ help: try this `x` + | ^^^^^^^ help: try this: `x` error: immediately dereferencing a reference --> reference.rs:53:18 | 53 | let y = **&mut &mut x; - | ^^^^^^^^^^^^ help: try this `&mut x` + | ^^^^^^^^^^^^ help: try this: `&mut x` error: aborting due to 11 previous errors diff --git a/clippy_tests/examples/short_circuit_statement.stderr b/clippy_tests/examples/short_circuit_statement.stderr index 8dcc43711cc..74976bfdc27 100644 --- a/clippy_tests/examples/short_circuit_statement.stderr +++ b/clippy_tests/examples/short_circuit_statement.stderr @@ -2,7 +2,7 @@ error: boolean short circuit operator in statement may be clearer using an expli --> short_circuit_statement.rs:7:5 | 7 | f() && g(); - | ^^^^^^^^^^^ help: replace it with `if f() { g(); }` + | ^^^^^^^^^^^ help: replace it with: `if f() { g(); }` | = note: `-D short-circuit-statement` implied by `-D warnings` @@ -10,13 +10,13 @@ error: boolean short circuit operator in statement may be clearer using an expli --> short_circuit_statement.rs:8:5 | 8 | f() || g(); - | ^^^^^^^^^^^ help: replace it with `if !f() { g(); }` + | ^^^^^^^^^^^ help: replace it with: `if !f() { g(); }` error: boolean short circuit operator in statement may be clearer using an explicit test --> short_circuit_statement.rs:9:5 | 9 | 1 == 2 || g(); - | ^^^^^^^^^^^^^^ help: replace it with `if !(1 == 2) { g(); }` + | ^^^^^^^^^^^^^^ help: replace it with: `if !(1 == 2) { g(); }` error: aborting due to 3 previous errors diff --git a/clippy_tests/examples/strings.stderr b/clippy_tests/examples/strings.stderr index 6f2ed0353bb..fd2d749f4ec 100644 --- a/clippy_tests/examples/strings.stderr +++ b/clippy_tests/examples/strings.stderr @@ -2,7 +2,7 @@ error: manual implementation of an assign operation --> strings.rs:10:9 | 10 | x = x + "."; - | ^^^^^^^^^^^ help: replace it with `x += "."` + | ^^^^^^^^^^^ help: replace it with: `x += "."` | = note: `-D assign-op-pattern` implied by `-D warnings` @@ -32,7 +32,7 @@ error: manual implementation of an assign operation --> strings.rs:24:9 | 24 | x = x + "."; - | ^^^^^^^^^^^ help: replace it with `x += "."` + | ^^^^^^^^^^^ help: replace it with: `x += "."` error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead --> strings.rs:38:9 @@ -44,7 +44,7 @@ error: manual implementation of an assign operation --> strings.rs:38:9 | 38 | x = x + "."; - | ^^^^^^^^^^^ help: replace it with `x += "."` + | ^^^^^^^^^^^ help: replace it with: `x += "."` error: you added something to a string. Consider using `String::push_str()` instead --> strings.rs:42:13 @@ -56,17 +56,23 @@ error: calling `as_bytes()` on a string literal --> strings.rs:50:14 | 50 | let bs = "hello there".as_bytes(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead `b"hello there"` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"` | = note: `-D string-lit-as-bytes` implied by `-D warnings` +error: calling `as_bytes()` on a string literal + --> strings.rs:55:18 + | +55 | let strify = stringify!(foobar).as_bytes(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `bstringify!(foobar)` + error: manual implementation of an assign operation --> strings.rs:65:7 | 65 | ; x = x + 1; - | ^^^^^^^^^ help: replace it with `x += 1` + | ^^^^^^^^^ help: replace it with: `x += 1` -error: aborting due to 10 previous errors +error: aborting due to 11 previous errors To learn more, run the command again with --verbose. diff --git a/clippy_tests/examples/swap.stderr b/clippy_tests/examples/swap.stderr index 99cf0aee310..c2e05ddc8df 100644 --- a/clippy_tests/examples/swap.stderr +++ b/clippy_tests/examples/swap.stderr @@ -4,7 +4,7 @@ error: this looks like you are swapping elements of `foo` manually 11 | / let temp = foo[0]; 12 | | foo[0] = foo[1]; 13 | | foo[1] = temp; - | |_________________^ help: try `foo.swap(0, 1)` + | |_________________^ help: try: `foo.swap(0, 1)` | = note: `-D manual-swap` implied by `-D warnings` @@ -14,7 +14,7 @@ error: this looks like you are swapping elements of `foo` manually 20 | / let temp = foo[0]; 21 | | foo[0] = foo[1]; 22 | | foo[1] = temp; - | |_________________^ help: try `foo.swap(0, 1)` + | |_________________^ help: try: `foo.swap(0, 1)` error: this looks like you are swapping elements of `foo` manually --> swap.rs:29:5 @@ -22,7 +22,7 @@ error: this looks like you are swapping elements of `foo` manually 29 | / let temp = foo[0]; 30 | | foo[0] = foo[1]; 31 | | foo[1] = temp; - | |_________________^ help: try `foo.swap(0, 1)` + | |_________________^ help: try: `foo.swap(0, 1)` error: this looks like you are swapping `a` and `b` manually --> swap.rs:47:7 @@ -31,7 +31,7 @@ error: this looks like you are swapping `a` and `b` manually | _______^ 48 | | a = b; 49 | | b = t; - | |_________^ help: try `std::mem::swap(&mut a, &mut b)` + | |_________^ help: try: `std::mem::swap(&mut a, &mut b)` | = note: or maybe you should use `std::mem::replace`? @@ -42,7 +42,7 @@ error: this looks like you are swapping `c.0` and `a` manually | _______^ 57 | | c.0 = a; 58 | | a = t; - | |_________^ help: try `std::mem::swap(&mut c.0, &mut a)` + | |_________^ help: try: `std::mem::swap(&mut c.0, &mut a)` | = note: or maybe you should use `std::mem::replace`? @@ -51,7 +51,7 @@ error: this looks like you are trying to swap `a` and `b` | 44 | / a = b; 45 | | b = a; - | |_________^ help: try `std::mem::swap(&mut a, &mut b)` + | |_________^ help: try: `std::mem::swap(&mut a, &mut b)` | = note: `-D almost-swapped` implied by `-D warnings` = note: or maybe you should use `std::mem::replace`? @@ -61,7 +61,7 @@ error: this looks like you are trying to swap `c.0` and `a` | 53 | / c.0 = a; 54 | | a = c.0; - | |___________^ help: try `std::mem::swap(&mut c.0, &mut a)` + | |___________^ help: try: `std::mem::swap(&mut c.0, &mut a)` | = note: or maybe you should use `std::mem::replace`? diff --git a/clippy_tests/examples/toplevel_ref_arg.stderr b/clippy_tests/examples/toplevel_ref_arg.stderr index fd55e390189..59cb6448b4e 100644 --- a/clippy_tests/examples/toplevel_ref_arg.stderr +++ b/clippy_tests/examples/toplevel_ref_arg.stderr @@ -10,25 +10,25 @@ error: `ref` on an entire `let` pattern is discouraged, take a reference with `& --> toplevel_ref_arg.rs:18:7 | 18 | let ref x = 1; - | ----^^^^^----- help: try `let x = &1;` + | ----^^^^^----- help: try: `let x = &1;` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead --> toplevel_ref_arg.rs:20:7 | 20 | let ref y: (&_, u8) = (&1, 2); - | ----^^^^^--------------------- help: try `let y: &(&_, u8) = &(&1, 2);` + | ----^^^^^--------------------- help: try: `let y: &(&_, u8) = &(&1, 2);` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead --> toplevel_ref_arg.rs:22:7 | 22 | let ref z = 1 + 2; - | ----^^^^^--------- help: try `let z = &(1 + 2);` + | ----^^^^^--------- help: try: `let z = &(1 + 2);` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead --> toplevel_ref_arg.rs:24:7 | 24 | let ref mut z = 1 + 2; - | ----^^^^^^^^^--------- help: try `let z = &mut (1 + 2);` + | ----^^^^^^^^^--------- help: try: `let z = &mut (1 + 2);` error: aborting due to 5 previous errors diff --git a/clippy_tests/examples/unreadable_literal.rs b/clippy_tests/examples/unreadable_literal.rs new file mode 100644 index 00000000000..45daf70b171 --- /dev/null +++ b/clippy_tests/examples/unreadable_literal.rs @@ -0,0 +1,8 @@ +#![feature(plugin)] +#![plugin(clippy)] +#[warn(unreadable_literal)] +#[allow(unused_variables)] +fn main() { + let good = (0b1011_i64, 0o1_234_u32, 0x1_234_567, 1_2345_6789, 1234_f32, 1_234.12_f32, 1_234.123_f32, 1.123_4_f32); + let bad = (0b10110_i64, 0x12345678901_usize, 12345_f32, 1.23456_f32); +} diff --git a/clippy_tests/examples/unreadable_literal.stderr b/clippy_tests/examples/unreadable_literal.stderr new file mode 100644 index 00000000000..a7d97ec4b0f --- /dev/null +++ b/clippy_tests/examples/unreadable_literal.stderr @@ -0,0 +1,37 @@ +error: long literal lacking separators + --> unreadable_literal.rs:7:16 + | +7 | let bad = (0b10110_i64, 0x12345678901_usize, 12345_f32, 1.23456_f32); + | ^^^^^^^^^^^ + | + = note: `-D unreadable-literal` implied by `-D warnings` + = help: consider using underscores to make literal more readable + +error: long literal lacking separators + --> unreadable_literal.rs:7:29 + | +7 | let bad = (0b10110_i64, 0x12345678901_usize, 12345_f32, 1.23456_f32); + | ^^^^^^^^^^^^^^^^^^^ + | + = help: consider using underscores to make literal more readable + +error: long literal lacking separators + --> unreadable_literal.rs:7:50 + | +7 | let bad = (0b10110_i64, 0x12345678901_usize, 12345_f32, 1.23456_f32); + | ^^^^^^^^^ + | + = help: consider using underscores to make literal more readable + +error: long literal lacking separators + --> unreadable_literal.rs:7:61 + | +7 | let bad = (0b10110_i64, 0x12345678901_usize, 12345_f32, 1.23456_f32); + | ^^^^^^^^^^^ + | + = help: consider using underscores to make literal more readable + +error: aborting due to 4 previous errors + + +To learn more, run the command again with --verbose. diff --git a/clippy_tests/examples/vec.stderr b/clippy_tests/examples/vec.stderr index d4ad4b560d9..968e2ad8d44 100644 --- a/clippy_tests/examples/vec.stderr +++ b/clippy_tests/examples/vec.stderr @@ -2,7 +2,7 @@ error: useless use of `vec!` --> vec.rs:24:14 | 24 | on_slice(&vec![]); - | ^^^^^^^ help: you can use a slice directly `&[]` + | ^^^^^^^ help: you can use a slice directly: `&[]` | = note: `-D useless-vec` implied by `-D warnings` @@ -10,31 +10,31 @@ error: useless use of `vec!` --> vec.rs:27:14 | 27 | on_slice(&vec![1, 2]); - | ^^^^^^^^^^^ help: you can use a slice directly `&[1, 2]` + | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` --> vec.rs:30:14 | 30 | on_slice(&vec ![1, 2]); - | ^^^^^^^^^^^^ help: you can use a slice directly `&[1, 2]` + | ^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` --> vec.rs:33:14 | 33 | on_slice(&vec!(1, 2)); - | ^^^^^^^^^^^ help: you can use a slice directly `&[1, 2]` + | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` --> vec.rs:36:14 | 36 | on_slice(&vec![1; 2]); - | ^^^^^^^^^^^ help: you can use a slice directly `&[1; 2]` + | ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]` error: useless use of `vec!` --> vec.rs:49:14 | 49 | for a in vec![1, 2, 3] { - | ^^^^^^^^^^^^^ help: you can use a slice directly `&[1, 2, 3]` + | ^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]` error: aborting due to 6 previous errors diff --git a/clippy_tests/examples/while_loop.stderr b/clippy_tests/examples/while_loop.stderr index c41e42d9e64..f84b5526729 100644 --- a/clippy_tests/examples/while_loop.stderr +++ b/clippy_tests/examples/while_loop.stderr @@ -8,7 +8,7 @@ error: this loop could be written as a `while let` loop 13 | | break 14 | | } 15 | | } - | |_____^ help: try `while let Some(_x) = y { .. }` + | |_____^ help: try: `while let Some(_x) = y { .. }` | = note: `-D while-let-loop` implied by `-D warnings` @@ -21,7 +21,7 @@ error: this loop could be written as a `while let` loop 25 | | None => break 26 | | }; 27 | | } - | |_____^ help: try `while let Some(_x) = y { .. }` + | |_____^ help: try: `while let Some(_x) = y { .. }` error: this loop could be written as a `while let` loop --> while_loop.rs:28:5 @@ -33,7 +33,7 @@ error: this loop could be written as a `while let` loop ... | 34 | | let _str = "foo"; 35 | | } - | |_____^ help: try `while let Some(x) = y { .. }` + | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop --> while_loop.rs:36:5 @@ -45,7 +45,7 @@ error: this loop could be written as a `while let` loop ... | 42 | | { let _b = "foobar"; } 43 | | } - | |_____^ help: try `while let Some(x) = y { .. }` + | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop --> while_loop.rs:58:5 @@ -57,7 +57,7 @@ error: this loop could be written as a `while let` loop ... | 64 | | let _ = (e, l); 65 | | } - | |_____^ help: try `while let Some(word) = "".split_whitespace().next() { .. }` + | |_____^ help: try: `while let Some(word) = "".split_whitespace().next() { .. }` error: this loop could be written as a `for` loop --> while_loop.rs:68:5 @@ -65,7 +65,7 @@ error: this loop could be written as a `for` loop 68 | / while let Option::Some(x) = iter.next() { 69 | | println!("{}", x); 70 | | } - | |_____^ help: try `for x in iter { .. }` + | |_____^ help: try: `for x in iter { .. }` | = note: `-D while-let-on-iterator` implied by `-D warnings` @@ -75,13 +75,13 @@ error: this loop could be written as a `for` loop 73 | / while let Some(x) = iter.next() { 74 | | println!("{}", x); 75 | | } - | |_____^ help: try `for x in iter { .. }` + | |_____^ help: try: `for x in iter { .. }` error: this loop could be written as a `for` loop --> while_loop.rs:78:5 | 78 | while let Some(_) = iter.next() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `for _ in iter { .. }` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in iter { .. }` error: this loop could be written as a `while let` loop --> while_loop.rs:118:5 @@ -93,7 +93,7 @@ error: this loop could be written as a `while let` loop 122 | | }; 123 | | loop {} 124 | | } - | |_____^ help: try `while let Some(ele) = iter.next() { .. }` + | |_____^ help: try: `while let Some(ele) = iter.next() { .. }` error: empty `loop {}` detected. You may want to either use `panic!()` or add `std::thread::sleep(..);` to the loop body. --> while_loop.rs:123:9