From 2abd1f73d93e3e57515121cc98cc14fe6ccb17dd Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Wed, 19 Jul 2017 19:56:32 -0400 Subject: [PATCH 01/14] 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 d7b915fd16de..425fb4670b27 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 000000000000..1b38c5265a90 --- /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 a34590518e91..1c61011755e5 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 dd36c5cad29d..fd88ca612d2b 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 049e2ab7bf36..2f7642100b27 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 77f36ce228cf..c7f403ac59e0 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 02b80cb965cc..b62f2e0c4473 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 03fa72646a85..85cc80052058 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 90ab28afcd95..e494bdd214ee 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 bf7e642914f8..067f1e68c6eb 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 de5c22e41a7d..dd29d5e14f25 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 530dfac79ed4..87e0e88584ac 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 e6600be3358d..f23f98f2bb7c 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 d0de1486eb73..476c94c8a5ef 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 06765f35779a..5cf8e611f4da 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 afa7b20c8d62..aefe624a8d40 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 000000000000..06e8996deb7b --- /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 000000000000..f86353eb266f --- /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 000000000000..65bcdc7435e8 --- /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 000000000000..75d6461a5473 --- /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 0ab65d468f86..a11130471069 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 e33adf4fd7ce..eda6229427ac 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 fa76d3308786..e8105a74b5cf 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 5decf43be7ec..6f6535b8d970 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 59e63ff2434b..4a7491b8de62 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 51cbf35a471e..c45eab9f4997 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 c521e1228c77..6d129777fa95 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 12a9640e767e..15701d651243 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 8cd549c96da4..158f9c432df7 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 48ed821635f1..4d1c29ed079e 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 516ddf5622bb..945279092bcc 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 4b346d01ed70..0dc9672b15cc 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 acc6b033a134..6e8bfedf4335 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 8dcc43711cc2..74976bfdc27f 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 6f2ed0353bb1..fd2d749f4ecb 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 99cf0aee310a..c2e05ddc8df1 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 fd55e3901898..59cb6448b4eb 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 000000000000..45daf70b171a --- /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 000000000000..a7d97ec4b0f7 --- /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 d4ad4b560d92..968e2ad8d447 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 c41e42d9e64c..f84b55267290 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 From 83a6dbc82887bf0b8674e56729ba816cb7da62aa Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Sat, 22 Jul 2017 19:49:47 -0400 Subject: [PATCH 02/14] Fix lint descriptions. --- clippy_lints/src/literal_digit_grouping.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index 1b38c5265a90..d6d93383d3bc 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -6,7 +6,7 @@ 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. +/// **What it does:** Warns if a long integral or floating-point constant does not contain underscores. /// /// **Why is this bad?** Reading long numbers is difficult without separators. /// @@ -23,7 +23,7 @@ declare_lint! { "long integer literal without underscores" } -/// **What it does:** Warns if an integral constant is grouped inconsistently with underscores. +/// **What it does:** Warns if an integral or floating-point constant is grouped inconsistently with underscores. /// /// **Why is this bad?** Readers may incorrectly interpret inconsistently grouped digits. /// @@ -40,7 +40,7 @@ declare_lint! { "integer literals with digits grouped inconsistently" } -/// **What it does:** Warns if the digits of an integral constant are grouped into groups that +/// **What it does:** Warns if the digits of an integral or floating-point constant are grouped into groups that /// are too large. /// /// **Why is this bad?** Negatively impacts readability. From f17def58010f207328ddb00437cf7e3f49d2681b Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Sat, 22 Jul 2017 19:54:44 -0400 Subject: [PATCH 03/14] Use if let over match. --- clippy_lints/src/literal_digit_grouping.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index d6d93383d3bc..67a5b7f37004 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -73,9 +73,8 @@ impl EarlyLintPass for LiteralDigitGrouping { return; } - match expr.node { - ExprKind::Lit(ref lit) => self.check_lit(cx, lit), - _ => (), + if let ExprKind::Lit(ref lit) = expr.node { + self.check_lit(cx, lit) } } } From 937a0aa20a18a749ac3c277536d5c41b0ba433f5 Mon Sep 17 00:00:00 2001 From: Matt Kraai Date: Mon, 24 Jul 2017 06:37:12 -0700 Subject: [PATCH 04/14] Update from upstream. --- CHANGELOG.md | 3 ++ Cargo.toml | 4 +-- clippy_lints/Cargo.toml | 2 +- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/methods.rs | 2 +- clippy_lints/src/misc_early.rs | 4 +-- clippy_lints/src/needless_bool.rs | 8 ++--- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/utils/mod.rs | 1 + clippy_tests/examples/bool_comparison.stderr | 8 ++--- clippy_tests/examples/eta.stderr | 8 ++--- clippy_tests/examples/len_zero.stderr | 14 ++++---- clippy_tests/examples/literals.stderr | 12 +++---- clippy_tests/examples/methods.stderr | 34 ++++++++++---------- clippy_tests/examples/needless_return.stderr | 16 ++++----- tests/ui/transmute.stderr | 30 ++++++++--------- 17 files changed, 78 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 485b9d87f5e0..d31e46e34738 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.145 +* Update to *rustc 1.20.0-nightly (afe145d22 2017-07-23)* + ## 0.0.144 * Update to *rustc 1.20.0-nightly (086eaa78e 2017-07-15)* diff --git a/Cargo.toml b/Cargo.toml index 13dc87d6d856..a2aa6464566f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.144" +version = "0.0.145" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -32,7 +32,7 @@ path = "src/main.rs" [dependencies] # begin automatic update -clippy_lints = { version = "0.0.144", path = "clippy_lints" } +clippy_lints = { version = "0.0.145", path = "clippy_lints" } # end automatic update cargo_metadata = "0.2" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 2180cc714277..da3187be4aa4 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin automatic update -version = "0.0.144" +version = "0.0.145" # end automatic update authors = [ "Manish Goregaokar ", diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index f7199f073e4f..7ec528b90f44 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -96,7 +96,7 @@ fn check_closure(cx: &LateContext, expr: &Expr) { expr.span, "redundant closure found", |db| if let Some(snippet) = snippet_opt(cx, caller.span) { - db.span_suggestion(expr.span, "remove closure as shown:", snippet); + db.span_suggestion(expr.span, "remove closure as shown", snippet); }); } } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 4f97f939964b..3a88c53d61d8 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -173,7 +173,7 @@ fn check_len_zero(cx: &LateContext, span: Span, name: Name, args: &[Expr], lit: LEN_ZERO, span, "length comparison to zero", - "using `is_empty` is more concise:", + "using `is_empty` is more concise", format!("{}{}.is_empty()", op, snippet(cx, args[0].span, "_"))); } } diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 835b836f7ec2..788e6cda01ae 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -1233,7 +1233,7 @@ fn lint_single_char_pattern(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr) SINGLE_CHAR_PATTERN, arg.span, "single-character string constant used as pattern", - |db| { db.span_suggestion(expr.span, "try using a char instead:", hint); }); + |db| { db.span_suggestion(expr.span, "try using a char instead", hint); }); } } } diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 1c61011755e5..c7d459acab01 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -366,12 +366,12 @@ impl MiscEarly { |db| { db.span_suggestion( lit.span, - "if you mean to use a decimal constant, remove the `0` to remove confusion:", + "if you mean to use a decimal constant, remove the `0` to remove confusion", src.trim_left_matches('0').to_string(), ); db.span_suggestion( lit.span, - "if you mean to use an octal constant, use `0o`:", + "if you mean to use an octal constant, use `0o`", format!("0o{}", src.trim_left_matches('0')), ); }); diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index db6c38b0ff68..4456547c7770 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { BOOL_COMPARISON, e.span, "equality checks against true are unnecessary", - "try simplifying it as shown:", + "try simplifying it as shown", hint); }, (Other, Bool(true)) => { @@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { BOOL_COMPARISON, e.span, "equality checks against true are unnecessary", - "try simplifying it as shown:", + "try simplifying it as shown", hint); }, (Bool(false), Other) => { @@ -144,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { BOOL_COMPARISON, e.span, "equality checks against false can be replaced by a negation", - "try simplifying it as shown:", + "try simplifying it as shown", (!hint).to_string()); }, (Other, Bool(false)) => { @@ -153,7 +153,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { BOOL_COMPARISON, e.span, "equality checks against false can be replaced by a negation", - "try simplifying it as shown:", + "try simplifying it as shown", (!hint).to_string()); }, _ => (), diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index d1d804ca39f8..acd60ba2f46d 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -97,7 +97,7 @@ impl ReturnPass { ret_span, "unneeded return statement", |db| if let Some(snippet) = snippet_opt(cx, inner_span) { - db.span_suggestion(ret_span, "remove `return` as shown:", snippet); + db.span_suggestion(ret_span, "remove `return` as shown", snippet); }); } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 5b53d6dbea7f..e8e11e37a5cd 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -584,6 +584,7 @@ pub fn multispan_sugg(db: &mut DiagnosticBuilder, help_msg: String, sugg: Vec<(S }) .collect(), msg: help_msg, + show_code_when_inline: true, }; db.suggestions.push(sugg); } diff --git a/clippy_tests/examples/bool_comparison.stderr b/clippy_tests/examples/bool_comparison.stderr index b62f2e0c4473..02b80cb965cc 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/eta.stderr b/clippy_tests/examples/eta.stderr index f23f98f2bb7c..e6600be3358d 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/len_zero.stderr b/clippy_tests/examples/len_zero.stderr index a11130471069..0ab65d468f86 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/literals.stderr b/clippy_tests/examples/literals.stderr index 6f6535b8d970..4eabb03fe5ad 100644 --- a/clippy_tests/examples/literals.stderr +++ b/clippy_tests/examples/literals.stderr @@ -33,11 +33,11 @@ error: this is a decimal constant | ^^^^^^^^^^^^ | = note: `-D zero-prefixed-literal` implied by `-D warnings` -help: if you mean to use a decimal constant, remove the `0` to remove confusion: +help: if you mean to use a decimal constant, remove the `0` to remove confusion | -17 | let fail_multi_zero = _123usize; - | ^^^^^^^^^ -help: if you mean to use an octal constant, use `0o`: +17 | let fail_multi_zero = 123usize; + | ^^^^^^^^ +help: if you mean to use an octal constant, use `0o` | 17 | let fail_multi_zero = 0o_123usize; | ^^^^^^^^^^^ @@ -78,11 +78,11 @@ error: this is a decimal constant 30 | let fail8 = 0123; | ^^^^ | -help: if you mean to use a decimal constant, remove the `0` to remove confusion: +help: if you mean to use a decimal constant, remove the `0` to remove confusion | 30 | let fail8 = 123; | ^^^ -help: if you mean to use an octal constant, use `0o`: +help: if you mean to use an octal constant, use `0o` | 30 | let fail8 = 0o123; | ^^^^^ diff --git a/clippy_tests/examples/methods.stderr b/clippy_tests/examples/methods.stderr index c45eab9f4997..dc0a2f3554ec 100644 --- a/clippy_tests/examples/methods.stderr +++ b/clippy_tests/examples/methods.stderr @@ -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_return.stderr b/clippy_tests/examples/needless_return.stderr index 158f9c432df7..8cd549c96da4 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/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index f878b6ad1730..7a1e4e867202 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -10,25 +10,25 @@ warning: transmute from a reference to a pointer --> $DIR/transmute.rs:26:23 | 26 | let _: *const T = core::intrinsics::transmute(t); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `t as *const T` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T` warning: transmute from a reference to a pointer --> $DIR/transmute.rs:28:21 | 28 | let _: *mut T = core::intrinsics::transmute(t); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `t as *const T as *mut T` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` warning: transmute from a reference to a pointer --> $DIR/transmute.rs:30:23 | 30 | let _: *const U = core::intrinsics::transmute(t); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `t as *const T as *const U` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` warning: transmute from a pointer type (`*const T`) to a reference type (`&T`) --> $DIR/transmute.rs:35:17 | 35 | let _: &T = std::mem::transmute(p); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try `&*p` + | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*p` | = note: #[warn(transmute_ptr_to_ref)] on by default @@ -36,55 +36,55 @@ warning: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) --> $DIR/transmute.rs:38:21 | 38 | let _: &mut T = std::mem::transmute(m); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try `&mut *m` + | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *m` warning: transmute from a pointer type (`*mut T`) to a reference type (`&T`) --> $DIR/transmute.rs:41:17 | 41 | let _: &T = std::mem::transmute(m); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try `&*m` + | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*m` warning: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) --> $DIR/transmute.rs:44:21 | 44 | let _: &mut T = std::mem::transmute(p as *mut T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `&mut *(p as *mut T)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(p as *mut T)` warning: transmute from a pointer type (`*const U`) to a reference type (`&T`) --> $DIR/transmute.rs:47:17 | 47 | let _: &T = std::mem::transmute(o); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try `&*(o as *const T)` + | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(o as *const T)` warning: transmute from a pointer type (`*mut U`) to a reference type (`&mut T`) --> $DIR/transmute.rs:50:21 | 50 | let _: &mut T = std::mem::transmute(om); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try `&mut *(om as *mut T)` + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(om as *mut T)` warning: transmute from a pointer type (`*mut U`) to a reference type (`&T`) --> $DIR/transmute.rs:53:17 | 53 | let _: &T = std::mem::transmute(om); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try `&*(om as *const T)` + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)` warning: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<'_, u8>`) --> $DIR/transmute.rs:64:32 | 64 | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `&*(raw as *const Foo<_>)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const Foo<_>)` warning: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<'_, &u8>`) --> $DIR/transmute.rs:66:33 | 66 | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `&*(raw as *const Foo<&_>)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const Foo<&_>)` warning: transmute from a pointer type (`*const i32`) to a reference type (`&u8`) --> $DIR/transmute.rs:70:14 | 70 | unsafe { std::mem::transmute::<_, Bar>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `&*(raw as *const u8)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const u8)` warning: transmute from a type (`std::vec::Vec`) to itself --> $DIR/transmute.rs:76:27 @@ -120,13 +120,13 @@ warning: transmute from an integer to a pointer --> $DIR/transmute.rs:92:31 | 92 | let _: *const usize = std::mem::transmute(5_isize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `5_isize as *const usize` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `5_isize as *const usize` warning: transmute from an integer to a pointer --> $DIR/transmute.rs:96:31 | 96 | let _: *const usize = std::mem::transmute(1+1usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `(1+1usize) as *const usize` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(1+1usize) as *const usize` warning: transmute from a type (`*const Usize`) to the type that it points to (`Usize`) --> $DIR/transmute.rs:111:24 From 017b77ae0577c4a446b8a43443023f5e67edbdab Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Sun, 30 Jul 2017 18:21:38 -0400 Subject: [PATCH 05/14] rustfmt --- clippy_lints/src/literal_digit_grouping.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index 67a5b7f37004..06eef93d138e 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -6,7 +6,8 @@ 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 or floating-point constant does not contain underscores. +/// **What it does:** Warns if a long integral or floating-point constant does +/// not contain underscores. /// /// **Why is this bad?** Reading long numbers is difficult without separators. /// @@ -23,9 +24,11 @@ declare_lint! { "long integer literal without underscores" } -/// **What it does:** Warns if an integral or floating-point constant is grouped inconsistently with underscores. +/// **What it does:** Warns if an integral or floating-point constant is +/// grouped inconsistently with underscores. /// -/// **Why is this bad?** Readers may incorrectly interpret inconsistently grouped digits. +/// **Why is this bad?** Readers may incorrectly interpret inconsistently +/// grouped digits. /// /// **Known problems:** None. /// @@ -40,7 +43,8 @@ declare_lint! { "integer literals with digits grouped inconsistently" } -/// **What it does:** Warns if the digits of an integral or floating-point constant are grouped into groups that +/// **What it does:** Warns if the digits of an integral or floating-point +/// constant are grouped into groups that /// are too large. /// /// **Why is this bad?** Negatively impacts readability. From fbbd788799405efcd89fe12adf85f0a41c952a3a Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Sun, 30 Jul 2017 18:33:15 -0400 Subject: [PATCH 06/14] Add some structs for cleaning up lint logic later. DigitInfo for storing radix, type, digits of a literal. WarningType for making warning messages consistent. --- clippy_lints/src/literal_digit_grouping.rs | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index 06eef93d138e..9b26cc53d471 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -62,6 +62,127 @@ declare_lint! { "grouping digits into groups that are too large" } +#[derive(Debug)] +enum Radix { + Binary, + Octal, + Decimal, + Hexadecimal, +} + +impl Radix { + /// Return a reasonable digit group size for this radix. + pub fn suggest_grouping(&self) -> usize { + match *self { + Radix::Binary | Radix::Hexadecimal => 4, + Radix::Octal | Radix::Decimal => 3, + } + } +} + +#[derive(Debug)] +struct DigitInfo<'a> { + /// Characters of a literal between the radix prefix and type suffix. + pub digits: &'a str, + /// Which radix the literal was represented in. + pub radix: Radix, + /// The radix prefix, if present. + pub prefix: Option<&'a str>, + /// The type suffix, including preceding underscore if present. + pub suffix: Option<&'a str>, + /// True for floating-point literals. + pub float: bool, +} + +impl<'a> DigitInfo<'a> { + pub fn new(lit: &str, float: bool) -> DigitInfo { + // Determine delimiter for radix prefix, if present, and radix. + let radix = if lit.starts_with("0x") { + Radix::Hexadecimal + } else if lit.starts_with("0b") { + Radix::Binary + } else if lit.starts_with("0o") { + Radix::Octal + } else { + Radix::Decimal + }; + + // Grab part of the literal after prefix, if present. + let (prefix, sans_prefix) = if let Radix::Decimal = radix { + (None, lit) + } else { + let (p, s) = lit.split_at(2); + (Some(p), s) + }; + + let mut last_d = '\0'; + for (d_idx, d) in sans_prefix.char_indices() { + if !float && (d == 'i' || d == 'u') || float && d == 'f' { + let suffix_start = if last_d == '_' { d_idx - 1 } else { d_idx }; + let (digits, suffix) = sans_prefix.split_at(suffix_start); + return DigitInfo { + digits: digits, + radix: radix, + prefix: prefix, + suffix: Some(suffix), + float: float, + }; + } + last_d = d + } + + // No suffix found + DigitInfo { + digits: sans_prefix, + radix: radix, + prefix: prefix, + suffix: None, + float: float, + } + } +} + +enum WarningType { + UnreadableLiteral, + InconsistentDigitGrouping, + LargeDigitGroups, +} + + +impl WarningType { + pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: &syntax_pos::Span) { + match *self { + WarningType::UnreadableLiteral => { + span_help_and_lint( + cx, + UNREADABLE_LITERAL, + *span, + "long literal lacking separators", + &format!("consider: {}", grouping_hint), + ) + }, + WarningType::LargeDigitGroups => { + span_help_and_lint( + cx, + LARGE_DIGIT_GROUPS, + *span, + "digit groups should be smaller", + &format!("consider: {}", grouping_hint), + ) + }, + WarningType::InconsistentDigitGrouping => { + span_help_and_lint( + cx, + INCONSISTENT_DIGIT_GROUPING, + *span, + "digits grouped inconsistently by underscores", + &format!("consider: {}", grouping_hint), + ) + }, + }; + } +} + #[derive(Copy, Clone)] pub struct LiteralDigitGrouping; From 471b6811d8ab95815331aff8470076fbc45dae8e Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Sun, 30 Jul 2017 18:37:11 -0400 Subject: [PATCH 07/14] Implement method for digit grouping suggestions --- clippy_lints/src/literal_digit_grouping.rs | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index 9b26cc53d471..5bc9190b1f56 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -140,6 +140,49 @@ impl<'a> DigitInfo<'a> { float: float, } } + + /// Returns digits grouped in a sensible way. + fn grouping_hint(&self) -> String { + let group_size = self.radix.suggest_grouping(); + if self.digits.contains('.') { + let mut parts = self.digits.split("."); + let int_part_hint = parts + .next() + .unwrap() + .chars() + .rev() + .filter(|&c| c != '_') + .collect::>() + .chunks(group_size) + .map(|chunk| chunk.into_iter().rev().collect()) + .rev() + .collect::>() + .join("_"); + let frac_part_hint = parts + .next() + .unwrap() + .chars() + .filter(|&c| c != '_') + .collect::>() + .chunks(group_size) + .map(|chunk| chunk.into_iter().collect()) + .collect::>() + .join("_"); + format!("{}.{}{}", int_part_hint, frac_part_hint, self.suffix.unwrap_or("")) + } else { + let hint = self.digits + .chars() + .rev() + .filter(|&c| c != '_') + .collect::>() + .chunks(group_size) + .map(|chunk| chunk.into_iter().rev().collect()) + .rev() + .collect::>() + .join("_"); + format!("{}{}{}", self.prefix.unwrap_or(""), hint, self.suffix.unwrap_or("")) + } + } } enum WarningType { From a6cb1189ddcb2973ba816634e909ed7ddc131058 Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Sun, 30 Jul 2017 18:46:41 -0400 Subject: [PATCH 08/14] do_lint() shouldn't format warnings. --- clippy_lints/src/literal_digit_grouping.rs | 37 ++++++++-------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index 5bc9190b1f56..ac59f4cb3f16 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -331,28 +331,23 @@ impl LiteralDigitGrouping { 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 { + /// Performs lint on `digits` (no decimal point) and returns the group + /// size on success or `WarningType` when emitting a warning. + fn do_lint(digits: &str) -> Result { // 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 - }) + 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; + return Err(WarningType::UnreadableLiteral); } else { - return Some(0); + return Ok(0); } } else { // Check consistency and the sizes of the groups. @@ -364,17 +359,11 @@ impl LiteralDigitGrouping { && (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; + return Err(WarningType::InconsistentDigitGrouping); } 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 Err(WarningType::LargeDigitGroups); } - return Some(group_size); + return Ok(group_size); } } } From 3b5696524210060b75998fea33b83d7e02d84258 Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Sun, 30 Jul 2017 18:51:01 -0400 Subject: [PATCH 09/14] Use DigitInfo instead of get_digits(). --- clippy_lints/src/literal_digit_grouping.rs | 39 +++++----------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index ac59f4cb3f16..e9661762996a 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -256,9 +256,10 @@ impl LiteralDigitGrouping { 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); + let digit_info = DigitInfo::new(&src, false); + let _ = LiteralDigitGrouping::do_lint(digit_info.digits).map_err(|warning_type| { + warning_type.display(&digit_info.grouping_hint(), cx, &lit.span) + }); }} // Lint floating-point literals. @@ -268,7 +269,10 @@ impl LiteralDigitGrouping { let Some(firstch) = src.chars().next(), char::to_digit(firstch, 10).is_some() ], { - let digits: Vec<&str> = LiteralDigitGrouping::get_digits(&src, true) + let digit_info = DigitInfo::new(&src, true); + // Separate digits into integral and fractional parts. + let parts: Vec<&str> = digit_info + .digits .split_terminator('.') .collect(); @@ -301,34 +305,7 @@ impl LiteralDigitGrouping { }} } - /// 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 From 06fd8784d7c9c74a9be210c900492430cbe9eb40 Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Sun, 30 Jul 2017 18:54:56 -0400 Subject: [PATCH 10/14] Loose ends and factor out consistency logic. --- clippy_lints/src/literal_digit_grouping.rs | 51 ++++++++++++---------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index e9661762996a..266fd5031b57 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -278,33 +278,38 @@ impl LiteralDigitGrouping { // 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"); - } + let _ = LiteralDigitGrouping::do_lint(parts[0]) + .map(|integral_group_size| { + if parts.len() > 1 { + // Lint the fractional part of literal just like integral part, but reversed. + let fractional_part = &parts[1].chars().rev().collect::(); + let _ = LiteralDigitGrouping::do_lint(fractional_part) + .map(|fractional_group_size| { + let consistent = LiteralDigitGrouping::parts_consistent(integral_group_size, fractional_group_size, parts[0].len(), parts[1].len()); + if !consistent { + WarningType::InconsistentDigitGrouping.display(&digit_info.grouping_hint(), cx, &lit.span); + } + }) + .map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, &lit.span)); } - } - } + }) + .map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, &lit.span)); }} } + /// Given the sizes of the digit groups of both integral and fractional + /// parts, and the length + /// of both parts, determine if the digits have been grouped consistently. + fn parts_consistent(int_group_size: usize, frac_group_size: usize, int_size: usize, frac_size: usize) -> bool { + match (int_group_size, frac_group_size) { + // No groups on either side of decimal point - trivially consistent. + (0, 0) => true, + // Integral part has grouped digits, fractional part does not. + (_, 0) => frac_size <= int_group_size, + // Fractional part has grouped digits, integral part does not. + (0, _) => int_size <= frac_group_size, + // Both parts have grouped digits. Groups should be the same size. + (_, _) => int_group_size == frac_group_size, } } From 5dbdfc1836aef07473cc01310dd239d97d0e50fc Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Mon, 31 Jul 2017 20:02:53 -0400 Subject: [PATCH 11/14] Update stderr files. --- .../examples/inconsistent_digit_grouping.stderr | 10 +++++----- clippy_tests/examples/large_digit_groups.stderr | 12 ++++++------ clippy_tests/examples/literals.stderr | 4 ++-- clippy_tests/examples/unreadable_literal.stderr | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/clippy_tests/examples/inconsistent_digit_grouping.stderr b/clippy_tests/examples/inconsistent_digit_grouping.stderr index f86353eb266f..ba2bc305d8d3 100644 --- a/clippy_tests/examples/inconsistent_digit_grouping.stderr +++ b/clippy_tests/examples/inconsistent_digit_grouping.stderr @@ -5,7 +5,7 @@ error: digits grouped inconsistently by underscores | ^^^^^^^^ | = note: `-D inconsistent-digit-grouping` implied by `-D warnings` - = help: consider making each group three or four digits + = help: consider: 123_456 error: digits grouped inconsistently by underscores --> inconsistent_digit_grouping.rs:7:26 @@ -13,7 +13,7 @@ error: digits grouped inconsistently by underscores 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 + = help: consider: 12_345_678 error: digits grouped inconsistently by underscores --> inconsistent_digit_grouping.rs:7:38 @@ -21,7 +21,7 @@ error: digits grouped inconsistently by underscores 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 + = help: consider: 1_234_567 error: digits grouped inconsistently by underscores --> inconsistent_digit_grouping.rs:7:48 @@ -29,7 +29,7 @@ error: digits grouped inconsistently by underscores 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 + = help: consider: 1_234.567_8_f32 error: digits grouped inconsistently by underscores --> inconsistent_digit_grouping.rs:7:64 @@ -37,7 +37,7 @@ error: digits grouped inconsistently by underscores 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 + = help: consider: 1.234_567_8_f32 error: aborting due to 5 previous errors diff --git a/clippy_tests/examples/large_digit_groups.stderr b/clippy_tests/examples/large_digit_groups.stderr index 75d6461a5473..408bff8b3cd6 100644 --- a/clippy_tests/examples/large_digit_groups.stderr +++ b/clippy_tests/examples/large_digit_groups.stderr @@ -5,7 +5,7 @@ error: digit groups should be smaller | ^^^^^^^^^^^^^ | = note: `-D large-digit-groups` implied by `-D warnings` - = help: consider using groups of three or four digits + = help: consider: 0b11_0110_i64 error: digit groups should be smaller --> large_digit_groups.rs:7:31 @@ -13,7 +13,7 @@ error: digit groups should be smaller 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 + = help: consider: 0x123_4567_8901_usize error: digit groups should be smaller --> large_digit_groups.rs:7:54 @@ -21,7 +21,7 @@ error: digit groups should be smaller 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 + = help: consider: 123_456_f32 error: digit groups should be smaller --> large_digit_groups.rs:7:67 @@ -29,7 +29,7 @@ error: digit groups should be smaller 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 + = help: consider: 123_456.12_f32 error: digit groups should be smaller --> large_digit_groups.rs:7:83 @@ -37,7 +37,7 @@ error: digit groups should be smaller 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 + = help: consider: 123_456.123_45_f32 error: digit groups should be smaller --> large_digit_groups.rs:7:102 @@ -45,7 +45,7 @@ error: digit groups should be smaller 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 + = help: consider: 123_456.123_456_f32 error: aborting due to 6 previous errors diff --git a/clippy_tests/examples/literals.stderr b/clippy_tests/examples/literals.stderr index 4eabb03fe5ad..db67e3f190c3 100644 --- a/clippy_tests/examples/literals.stderr +++ b/clippy_tests/examples/literals.stderr @@ -35,8 +35,8 @@ error: this is a decimal constant = 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 = 0o_123usize; diff --git a/clippy_tests/examples/unreadable_literal.stderr b/clippy_tests/examples/unreadable_literal.stderr index a7d97ec4b0f7..e4c110915d0a 100644 --- a/clippy_tests/examples/unreadable_literal.stderr +++ b/clippy_tests/examples/unreadable_literal.stderr @@ -5,7 +5,7 @@ error: long literal lacking separators | ^^^^^^^^^^^ | = note: `-D unreadable-literal` implied by `-D warnings` - = help: consider using underscores to make literal more readable + = help: consider: 0b1_0110_i64 error: long literal lacking separators --> unreadable_literal.rs:7:29 @@ -13,7 +13,7 @@ error: long literal lacking separators 7 | let bad = (0b10110_i64, 0x12345678901_usize, 12345_f32, 1.23456_f32); | ^^^^^^^^^^^^^^^^^^^ | - = help: consider using underscores to make literal more readable + = help: consider: 0x123_4567_8901_usize error: long literal lacking separators --> unreadable_literal.rs:7:50 @@ -21,7 +21,7 @@ error: long literal lacking separators 7 | let bad = (0b10110_i64, 0x12345678901_usize, 12345_f32, 1.23456_f32); | ^^^^^^^^^ | - = help: consider using underscores to make literal more readable + = help: consider: 12_345_f32 error: long literal lacking separators --> unreadable_literal.rs:7:61 @@ -29,7 +29,7 @@ error: long literal lacking separators 7 | let bad = (0b10110_i64, 0x12345678901_usize, 12345_f32, 1.23456_f32); | ^^^^^^^^^^^ | - = help: consider using underscores to make literal more readable + = help: consider: 1.234_56_f32 error: aborting due to 4 previous errors From 9b78086ab350ba4b177e64df1eec0ff079fe56f2 Mon Sep 17 00:00:00 2001 From: Jay Hardee Date: Mon, 31 Jul 2017 20:20:27 -0400 Subject: [PATCH 12/14] Fix hints from misc_early --- clippy_lints/src/misc_early.rs | 4 ++-- clippy_tests/examples/literals.stderr | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index c7d459acab01..c63dff52ae92 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -367,12 +367,12 @@ impl MiscEarly { db.span_suggestion( lit.span, "if you mean to use a decimal constant, remove the `0` to remove confusion", - src.trim_left_matches('0').to_string(), + src.trim_left_matches(|c| c == '_' || c == '0').to_string(), ); db.span_suggestion( lit.span, "if you mean to use an octal constant, use `0o`", - format!("0o{}", src.trim_left_matches('0')), + format!("0o{}", src.trim_left_matches(|c| c == '_' || c == '0')), ); }); } diff --git a/clippy_tests/examples/literals.stderr b/clippy_tests/examples/literals.stderr index db67e3f190c3..05f623cae951 100644 --- a/clippy_tests/examples/literals.stderr +++ b/clippy_tests/examples/literals.stderr @@ -35,12 +35,12 @@ error: this is a decimal constant = 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 = 0o_123usize; - | ^^^^^^^^^^^ +17 | let fail_multi_zero = 0o123usize; + | ^^^^^^^^^^ error: integer type suffix should be separated by an underscore --> literals.rs:22:17 From 4fa6f83708662b16d6afd7a6376ac0c9966c9e98 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 1 Aug 2017 09:45:36 +0200 Subject: [PATCH 13/14] Clippy fixes itself --- clippy_lints/src/literal_digit_grouping.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index 266fd5031b57..a07c40ed2419 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -327,9 +327,9 @@ impl LiteralDigitGrouping { if underscore_positions.is_empty() { // Check if literal needs underscores. if digits.len() > 4 { - return Err(WarningType::UnreadableLiteral); + Err(WarningType::UnreadableLiteral) } else { - return Ok(0); + Ok(0) } } else { // Check consistency and the sizes of the groups. @@ -345,7 +345,7 @@ impl LiteralDigitGrouping { } else if group_size > 4 { return Err(WarningType::LargeDigitGroups); } - return Ok(group_size); + Ok(group_size) } } } From 9d8d2d87c33c4528a781c0c36597cb80d2b00be2 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 1 Aug 2017 09:55:17 +0200 Subject: [PATCH 14/14] More autoclippyification --- clippy_lints/src/literal_digit_grouping.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index a07c40ed2419..ec80e6968f85 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -145,7 +145,7 @@ impl<'a> DigitInfo<'a> { fn grouping_hint(&self) -> String { let group_size = self.radix.suggest_grouping(); if self.digits.contains('.') { - let mut parts = self.digits.split("."); + let mut parts = self.digits.split('.'); let int_part_hint = parts .next() .unwrap()