Skip to content

Commit 888b736

Browse files
committed
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
2 parents 83f2eb7 + eeeadf3 commit 888b736

15 files changed

+129
-60
lines changed

clippy_lints/src/attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
277277
line_span,
278278
"if you just forgot a `!`, use",
279279
sugg,
280-
Applicability::MachineApplicable,
280+
Applicability::MaybeIncorrect,
281281
);
282282
},
283283
);

clippy_lints/src/int_plus_one.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl IntPlusOne {
158158
|db| {
159159
db.span_suggestion(
160160
block.span,
161-
"change `>= y + 1` to `> y` as shown",
161+
"change it to",
162162
recommendation,
163163
Applicability::MachineApplicable, // snippet
164164
);

clippy_lints/src/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
407407
lhs - rhs,
408408
if op == BinOpKind::Eq { '<' } else { '>' }
409409
),
410-
Applicability::MachineApplicable, // snippet
410+
Applicability::HasPlaceholders, // snippet
411411
);
412412
db.span_note(expr.span, "std::f32::EPSILON and std::f64::EPSILON are available.");
413413
});

tests/ui/assign_ops.fixed

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-rustfix
2+
3+
#[allow(dead_code, unused_assignments)]
4+
#[warn(clippy::assign_op_pattern)]
5+
fn main() {
6+
let mut a = 5;
7+
a += 1;
8+
a += 1;
9+
a -= 1;
10+
a *= 99;
11+
a *= 42;
12+
a /= 2;
13+
a %= 5;
14+
a &= 1;
15+
a = 1 - a;
16+
a = 5 / a;
17+
a = 42 % a;
18+
a = 6 << a;
19+
let mut s = String::new();
20+
s += "bla";
21+
}

tests/ui/assign_ops.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-rustfix
2+
13
#[allow(dead_code, unused_assignments)]
24
#[warn(clippy::assign_op_pattern)]
35
fn main() {

tests/ui/assign_ops.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
error: manual implementation of an assign operation
2-
--> $DIR/assign_ops.rs:5:5
2+
--> $DIR/assign_ops.rs:7:5
33
|
44
LL | a = a + 1;
55
| ^^^^^^^^^ help: replace it with: `a += 1`
66
|
77
= note: `-D clippy::assign-op-pattern` implied by `-D warnings`
88

99
error: manual implementation of an assign operation
10-
--> $DIR/assign_ops.rs:6:5
10+
--> $DIR/assign_ops.rs:8:5
1111
|
1212
LL | a = 1 + a;
1313
| ^^^^^^^^^ help: replace it with: `a += 1`
1414

1515
error: manual implementation of an assign operation
16-
--> $DIR/assign_ops.rs:7:5
16+
--> $DIR/assign_ops.rs:9:5
1717
|
1818
LL | a = a - 1;
1919
| ^^^^^^^^^ help: replace it with: `a -= 1`
2020

2121
error: manual implementation of an assign operation
22-
--> $DIR/assign_ops.rs:8:5
22+
--> $DIR/assign_ops.rs:10:5
2323
|
2424
LL | a = a * 99;
2525
| ^^^^^^^^^^ help: replace it with: `a *= 99`
2626

2727
error: manual implementation of an assign operation
28-
--> $DIR/assign_ops.rs:9:5
28+
--> $DIR/assign_ops.rs:11:5
2929
|
3030
LL | a = 42 * a;
3131
| ^^^^^^^^^^ help: replace it with: `a *= 42`
3232

3333
error: manual implementation of an assign operation
34-
--> $DIR/assign_ops.rs:10:5
34+
--> $DIR/assign_ops.rs:12:5
3535
|
3636
LL | a = a / 2;
3737
| ^^^^^^^^^ help: replace it with: `a /= 2`
3838

3939
error: manual implementation of an assign operation
40-
--> $DIR/assign_ops.rs:11:5
40+
--> $DIR/assign_ops.rs:13:5
4141
|
4242
LL | a = a % 5;
4343
| ^^^^^^^^^ help: replace it with: `a %= 5`
4444

4545
error: manual implementation of an assign operation
46-
--> $DIR/assign_ops.rs:12:5
46+
--> $DIR/assign_ops.rs:14:5
4747
|
4848
LL | a = a & 1;
4949
| ^^^^^^^^^ help: replace it with: `a &= 1`
5050

5151
error: manual implementation of an assign operation
52-
--> $DIR/assign_ops.rs:18:5
52+
--> $DIR/assign_ops.rs:20:5
5353
|
5454
LL | s = s + "bla";
5555
| ^^^^^^^^^^^^^ help: replace it with: `s += "bla"`

tests/ui/int_plus_one.fixed

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-rustfix
2+
3+
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
4+
#[warn(clippy::int_plus_one)]
5+
fn main() {
6+
let x = 1i32;
7+
let y = 0i32;
8+
9+
let _ = x > y;
10+
let _ = y < x;
11+
12+
let _ = x > y;
13+
let _ = y < x;
14+
15+
let _ = x > y; // should be ok
16+
let _ = y < x; // should be ok
17+
}

tests/ui/int_plus_one.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
// run-rustfix
2+
13
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
24
#[warn(clippy::int_plus_one)]
35
fn main() {
46
let x = 1i32;
57
let y = 0i32;
68

7-
x >= y + 1;
8-
y + 1 <= x;
9+
let _ = x >= y + 1;
10+
let _ = y + 1 <= x;
911

10-
x - 1 >= y;
11-
y <= x - 1;
12+
let _ = x - 1 >= y;
13+
let _ = y <= x - 1;
1214

13-
x > y; // should be ok
14-
y < x; // should be ok
15+
let _ = x > y; // should be ok
16+
let _ = y < x; // should be ok
1517
}

tests/ui/int_plus_one.stderr

+12-28
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,28 @@
11
error: Unnecessary `>= y + 1` or `x - 1 >=`
2-
--> $DIR/int_plus_one.rs:7:5
2+
--> $DIR/int_plus_one.rs:9:13
33
|
4-
LL | x >= y + 1;
5-
| ^^^^^^^^^^
4+
LL | let _ = x >= y + 1;
5+
| ^^^^^^^^^^ help: change it to: `x > y`
66
|
77
= note: `-D clippy::int-plus-one` implied by `-D warnings`
8-
help: change `>= y + 1` to `> y` as shown
9-
|
10-
LL | x > y;
11-
| ^^^^^
128

139
error: Unnecessary `>= y + 1` or `x - 1 >=`
14-
--> $DIR/int_plus_one.rs:8:5
15-
|
16-
LL | y + 1 <= x;
17-
| ^^^^^^^^^^
18-
help: change `>= y + 1` to `> y` as shown
10+
--> $DIR/int_plus_one.rs:10:13
1911
|
20-
LL | y < x;
21-
| ^^^^^
12+
LL | let _ = y + 1 <= x;
13+
| ^^^^^^^^^^ help: change it to: `y < x`
2214

2315
error: Unnecessary `>= y + 1` or `x - 1 >=`
24-
--> $DIR/int_plus_one.rs:10:5
16+
--> $DIR/int_plus_one.rs:12:13
2517
|
26-
LL | x - 1 >= y;
27-
| ^^^^^^^^^^
28-
help: change `>= y + 1` to `> y` as shown
29-
|
30-
LL | x > y;
31-
| ^^^^^
18+
LL | let _ = x - 1 >= y;
19+
| ^^^^^^^^^^ help: change it to: `x > y`
3220

3321
error: Unnecessary `>= y + 1` or `x - 1 >=`
34-
--> $DIR/int_plus_one.rs:11:5
35-
|
36-
LL | y <= x - 1;
37-
| ^^^^^^^^^^
38-
help: change `>= y + 1` to `> y` as shown
22+
--> $DIR/int_plus_one.rs:13:13
3923
|
40-
LL | y < x;
41-
| ^^^^^
24+
LL | let _ = y <= x - 1;
25+
| ^^^^^^^^^^ help: change it to: `y < x`
4226

4327
error: aborting due to 4 previous errors
4428

tests/ui/outer_expn_data.fixed

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// run-rustfix
2+
3+
#![deny(clippy::internal)]
4+
#![feature(rustc_private)]
5+
6+
#[macro_use]
7+
extern crate rustc;
8+
use rustc::hir::Expr;
9+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
10+
11+
declare_lint! {
12+
pub TEST_LINT,
13+
Warn,
14+
""
15+
}
16+
17+
declare_lint_pass!(Pass => [TEST_LINT]);
18+
19+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
20+
fn check_expr(&mut self, _cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
21+
let _ = expr.span.ctxt().outer_expn_data();
22+
}
23+
}
24+
25+
fn main() {}

tests/ui/outer_expn_data.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-rustfix
2+
13
#![deny(clippy::internal)]
24
#![feature(rustc_private)]
35

tests/ui/outer_expn_data.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: usage of `outer_expn().expn_data()`
2-
--> $DIR/outer_expn_data.rs:19:33
2+
--> $DIR/outer_expn_data.rs:21:33
33
|
44
LL | let _ = expr.span.ctxt().outer_expn().expn_data();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.outer_expn_data()`
66
|
77
note: lint level defined here
8-
--> $DIR/outer_expn_data.rs:1:9
8+
--> $DIR/outer_expn_data.rs:3:9
99
|
1010
LL | #![deny(clippy::internal)]
1111
| ^^^^^^^^^^^^^^^^

tests/ui/rename.fixed

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Test for Clippy lint renames.
2+
// run-rustfix
3+
4+
#![allow(dead_code)]
5+
// allow the new lint name here, to test if the new name works
6+
#![allow(clippy::module_name_repetitions)]
7+
#![allow(clippy::new_without_default)]
8+
#![allow(clippy::cognitive_complexity)]
9+
#![allow(clippy::redundant_static_lifetimes)]
10+
// warn for the old lint name here, to test if the renaming worked
11+
#![warn(clippy::cognitive_complexity)]
12+
13+
#[warn(clippy::module_name_repetitions)]
14+
fn main() {}
15+
16+
#[warn(clippy::new_without_default)]
17+
struct Foo;
18+
19+
#[warn(clippy::redundant_static_lifetimes)]
20+
fn foo() {}

tests/ui/rename.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Test for Clippy lint renames.
2+
// run-rustfix
23

4+
#![allow(dead_code)]
35
// allow the new lint name here, to test if the new name works
46
#![allow(clippy::module_name_repetitions)]
57
#![allow(clippy::new_without_default)]
@@ -15,10 +17,4 @@ fn main() {}
1517
struct Foo;
1618

1719
#[warn(clippy::const_static_lifetime)]
18-
static Bar: &'static str = "baz";
19-
20-
impl Foo {
21-
fn new() -> Self {
22-
Foo
23-
}
24-
}
20+
fn foo() {}

tests/ui/rename.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
2-
--> $DIR/rename.rs:9:9
2+
--> $DIR/rename.rs:11:9
33
|
44
LL | #![warn(clippy::cyclomatic_complexity)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
66
|
77
= note: `-D renamed-and-removed-lints` implied by `-D warnings`
88

99
error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions`
10-
--> $DIR/rename.rs:11:8
10+
--> $DIR/rename.rs:13:8
1111
|
1212
LL | #[warn(clippy::stutter)]
1313
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions`
1414

1515
error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default`
16-
--> $DIR/rename.rs:14:8
16+
--> $DIR/rename.rs:16:8
1717
|
1818
LL | #[warn(clippy::new_without_default_derive)]
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default`
2020

2121
error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes`
22-
--> $DIR/rename.rs:17:8
22+
--> $DIR/rename.rs:19:8
2323
|
2424
LL | #[warn(clippy::const_static_lifetime)]
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes`
2626

2727
error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
28-
--> $DIR/rename.rs:9:9
28+
--> $DIR/rename.rs:11:9
2929
|
3030
LL | #![warn(clippy::cyclomatic_complexity)]
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`

0 commit comments

Comments
 (0)