Auto merge of #4408 - phansch:more_rustfix_tests, r=flip1995
More rustfix tests <!-- Thank you for making Clippy better! We're collecting our changelog from pull request descriptions. If your PR only updates to the latest nightly, you can leave the `changelog` entry as `none`. Otherwise, please write a short comment explaining your change. If your PR fixes an issue, you can add "fixes #issue_number" into this PR description. This way the issue will be automatically closed when your PR is merged. If you added a new lint, here's a checklist for things that will be checked during review or continuous integration. - [ ] Followed [lint naming conventions][lint_naming] - [ ] Added passing UI tests (including committed `.stderr` file) - [ ] `cargo test` passes locally - [ ] Executed `./util/dev update_lints` - [ ] Added lint documentation - [ ] Run `./util/dev fmt` [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints Note that you can skip the above if you are just opening a WIP PR in order to get feedback. Delete this line and everything above before opening your PR --> cc #3630 This is probably easier reviewed per-commit. changelog: none
This commit is contained in:
commit
888b736560
@ -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,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -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.");
|
||||
});
|
||||
|
21
tests/ui/assign_ops.fixed
Normal file
21
tests/ui/assign_ops.fixed
Normal file
@ -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";
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
#[allow(dead_code, unused_assignments)]
|
||||
#[warn(clippy::assign_op_pattern)]
|
||||
fn main() {
|
||||
|
@ -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"`
|
||||
|
17
tests/ui/int_plus_one.fixed
Normal file
17
tests/ui/int_plus_one.fixed
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
25
tests/ui/outer_expn_data.fixed
Normal file
25
tests/ui/outer_expn_data.fixed
Normal file
@ -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() {}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
#![deny(clippy::internal)]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
|
@ -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)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
20
tests/ui/rename.fixed
Normal file
20
tests/ui/rename.fixed
Normal file
@ -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() {}
|
@ -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() {}
|
||||
|
@ -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`
|
||||
|
Loading…
x
Reference in New Issue
Block a user