diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 1159df5475a..558298c2e0e 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -277,7 +277,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes { line_span, "if you just forgot a `!`, use", sugg, - Applicability::MachineApplicable, + Applicability::MaybeIncorrect, ); }, ); diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 22ebf562d3b..c886743533f 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -158,7 +158,7 @@ impl IntPlusOne { |db| { db.span_suggestion( block.span, - "change `>= y + 1` to `> y` as shown", + "change it to", recommendation, Applicability::MachineApplicable, // snippet ); diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index b9c05bb2bd3..c6bcb845c7a 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -407,7 +407,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { lhs - rhs, if op == BinOpKind::Eq { '<' } else { '>' } ), - Applicability::MachineApplicable, // snippet + Applicability::HasPlaceholders, // snippet ); db.span_note(expr.span, "std::f32::EPSILON and std::f64::EPSILON are available."); }); diff --git a/tests/ui/assign_ops.fixed b/tests/ui/assign_ops.fixed new file mode 100644 index 00000000000..52b1b3afe16 --- /dev/null +++ b/tests/ui/assign_ops.fixed @@ -0,0 +1,21 @@ +// run-rustfix + +#[allow(dead_code, unused_assignments)] +#[warn(clippy::assign_op_pattern)] +fn main() { + let mut a = 5; + a += 1; + a += 1; + a -= 1; + a *= 99; + a *= 42; + a /= 2; + a %= 5; + a &= 1; + a = 1 - a; + a = 5 / a; + a = 42 % a; + a = 6 << a; + let mut s = String::new(); + s += "bla"; +} diff --git a/tests/ui/assign_ops.rs b/tests/ui/assign_ops.rs index c7b4865f5c2..527a46b2c2b 100644 --- a/tests/ui/assign_ops.rs +++ b/tests/ui/assign_ops.rs @@ -1,3 +1,5 @@ +// run-rustfix + #[allow(dead_code, unused_assignments)] #[warn(clippy::assign_op_pattern)] fn main() { diff --git a/tests/ui/assign_ops.stderr b/tests/ui/assign_ops.stderr index 646f9970122..3486bd8da4d 100644 --- a/tests/ui/assign_ops.stderr +++ b/tests/ui/assign_ops.stderr @@ -1,5 +1,5 @@ error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:5:5 + --> $DIR/assign_ops.rs:7:5 | LL | a = a + 1; | ^^^^^^^^^ help: replace it with: `a += 1` @@ -7,49 +7,49 @@ LL | a = a + 1; = note: `-D clippy::assign-op-pattern` implied by `-D warnings` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:6:5 + --> $DIR/assign_ops.rs:8:5 | LL | a = 1 + a; | ^^^^^^^^^ help: replace it with: `a += 1` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:7:5 + --> $DIR/assign_ops.rs:9:5 | LL | a = a - 1; | ^^^^^^^^^ help: replace it with: `a -= 1` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:8:5 + --> $DIR/assign_ops.rs:10:5 | LL | a = a * 99; | ^^^^^^^^^^ help: replace it with: `a *= 99` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:9:5 + --> $DIR/assign_ops.rs:11:5 | LL | a = 42 * a; | ^^^^^^^^^^ help: replace it with: `a *= 42` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:10:5 + --> $DIR/assign_ops.rs:12:5 | LL | a = a / 2; | ^^^^^^^^^ help: replace it with: `a /= 2` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:11:5 + --> $DIR/assign_ops.rs:13:5 | LL | a = a % 5; | ^^^^^^^^^ help: replace it with: `a %= 5` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:12:5 + --> $DIR/assign_ops.rs:14:5 | LL | a = a & 1; | ^^^^^^^^^ help: replace it with: `a &= 1` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:18:5 + --> $DIR/assign_ops.rs:20:5 | LL | s = s + "bla"; | ^^^^^^^^^^^^^ help: replace it with: `s += "bla"` diff --git a/tests/ui/int_plus_one.fixed b/tests/ui/int_plus_one.fixed new file mode 100644 index 00000000000..642830f24f5 --- /dev/null +++ b/tests/ui/int_plus_one.fixed @@ -0,0 +1,17 @@ +// run-rustfix + +#[allow(clippy::no_effect, clippy::unnecessary_operation)] +#[warn(clippy::int_plus_one)] +fn main() { + let x = 1i32; + let y = 0i32; + + let _ = x > y; + let _ = y < x; + + let _ = x > y; + let _ = y < x; + + let _ = x > y; // should be ok + let _ = y < x; // should be ok +} diff --git a/tests/ui/int_plus_one.rs b/tests/ui/int_plus_one.rs index 42d8045244f..0755a0c79d2 100644 --- a/tests/ui/int_plus_one.rs +++ b/tests/ui/int_plus_one.rs @@ -1,15 +1,17 @@ +// run-rustfix + #[allow(clippy::no_effect, clippy::unnecessary_operation)] #[warn(clippy::int_plus_one)] fn main() { let x = 1i32; let y = 0i32; - x >= y + 1; - y + 1 <= x; + let _ = x >= y + 1; + let _ = y + 1 <= x; - x - 1 >= y; - y <= x - 1; + let _ = x - 1 >= y; + let _ = y <= x - 1; - x > y; // should be ok - y < x; // should be ok + let _ = x > y; // should be ok + let _ = y < x; // should be ok } diff --git a/tests/ui/int_plus_one.stderr b/tests/ui/int_plus_one.stderr index 4a783e50c67..29a6914761c 100644 --- a/tests/ui/int_plus_one.stderr +++ b/tests/ui/int_plus_one.stderr @@ -1,44 +1,28 @@ error: Unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:7:5 + --> $DIR/int_plus_one.rs:9:13 | -LL | x >= y + 1; - | ^^^^^^^^^^ +LL | let _ = x >= y + 1; + | ^^^^^^^^^^ help: change it to: `x > y` | = note: `-D clippy::int-plus-one` implied by `-D warnings` -help: change `>= y + 1` to `> y` as shown - | -LL | x > y; - | ^^^^^ error: Unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:8:5 + --> $DIR/int_plus_one.rs:10:13 | -LL | y + 1 <= x; - | ^^^^^^^^^^ -help: change `>= y + 1` to `> y` as shown - | -LL | y < x; - | ^^^^^ +LL | let _ = y + 1 <= x; + | ^^^^^^^^^^ help: change it to: `y < x` error: Unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:10:5 + --> $DIR/int_plus_one.rs:12:13 | -LL | x - 1 >= y; - | ^^^^^^^^^^ -help: change `>= y + 1` to `> y` as shown - | -LL | x > y; - | ^^^^^ +LL | let _ = x - 1 >= y; + | ^^^^^^^^^^ help: change it to: `x > y` error: Unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:11:5 + --> $DIR/int_plus_one.rs:13:13 | -LL | y <= x - 1; - | ^^^^^^^^^^ -help: change `>= y + 1` to `> y` as shown - | -LL | y < x; - | ^^^^^ +LL | let _ = y <= x - 1; + | ^^^^^^^^^^ help: change it to: `y < x` error: aborting due to 4 previous errors diff --git a/tests/ui/outer_expn_data.fixed b/tests/ui/outer_expn_data.fixed new file mode 100644 index 00000000000..4118214e6d9 --- /dev/null +++ b/tests/ui/outer_expn_data.fixed @@ -0,0 +1,25 @@ +// run-rustfix + +#![deny(clippy::internal)] +#![feature(rustc_private)] + +#[macro_use] +extern crate rustc; +use rustc::hir::Expr; +use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; + +declare_lint! { + pub TEST_LINT, + Warn, + "" +} + +declare_lint_pass!(Pass => [TEST_LINT]); + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { + fn check_expr(&mut self, _cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + let _ = expr.span.ctxt().outer_expn_data(); + } +} + +fn main() {} diff --git a/tests/ui/outer_expn_data.rs b/tests/ui/outer_expn_data.rs index 15ac315a586..a6726a9bf6a 100644 --- a/tests/ui/outer_expn_data.rs +++ b/tests/ui/outer_expn_data.rs @@ -1,3 +1,5 @@ +// run-rustfix + #![deny(clippy::internal)] #![feature(rustc_private)] diff --git a/tests/ui/outer_expn_data.stderr b/tests/ui/outer_expn_data.stderr index cd12ad79dd1..6803b3feb8e 100644 --- a/tests/ui/outer_expn_data.stderr +++ b/tests/ui/outer_expn_data.stderr @@ -1,11 +1,11 @@ error: usage of `outer_expn().expn_data()` - --> $DIR/outer_expn_data.rs:19:33 + --> $DIR/outer_expn_data.rs:21:33 | LL | let _ = expr.span.ctxt().outer_expn().expn_data(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.outer_expn_data()` | note: lint level defined here - --> $DIR/outer_expn_data.rs:1:9 + --> $DIR/outer_expn_data.rs:3:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed new file mode 100644 index 00000000000..947914aa123 --- /dev/null +++ b/tests/ui/rename.fixed @@ -0,0 +1,20 @@ +//! Test for Clippy lint renames. +// run-rustfix + +#![allow(dead_code)] +// allow the new lint name here, to test if the new name works +#![allow(clippy::module_name_repetitions)] +#![allow(clippy::new_without_default)] +#![allow(clippy::cognitive_complexity)] +#![allow(clippy::redundant_static_lifetimes)] +// warn for the old lint name here, to test if the renaming worked +#![warn(clippy::cognitive_complexity)] + +#[warn(clippy::module_name_repetitions)] +fn main() {} + +#[warn(clippy::new_without_default)] +struct Foo; + +#[warn(clippy::redundant_static_lifetimes)] +fn foo() {} diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index f3758174125..e2c8c223fc7 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -1,5 +1,7 @@ //! Test for Clippy lint renames. +// run-rustfix +#![allow(dead_code)] // allow the new lint name here, to test if the new name works #![allow(clippy::module_name_repetitions)] #![allow(clippy::new_without_default)] @@ -15,10 +17,4 @@ fn main() {} struct Foo; #[warn(clippy::const_static_lifetime)] -static Bar: &'static str = "baz"; - -impl Foo { - fn new() -> Self { - Foo - } -} +fn foo() {} diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 0765e6e954a..83c7f26ba5f 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:9:9 + --> $DIR/rename.rs:11:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` @@ -7,25 +7,25 @@ LL | #![warn(clippy::cyclomatic_complexity)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:11:8 + --> $DIR/rename.rs:13:8 | LL | #[warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:14:8 + --> $DIR/rename.rs:16:8 | LL | #[warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:17:8 + --> $DIR/rename.rs:19:8 | LL | #[warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:9:9 + --> $DIR/rename.rs:11:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`