Skip to content

More rustfix tests #4408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
},
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/int_plus_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
});
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/assign_ops.fixed
Original file line number Diff line number Diff line change
@@ -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";
}
2 changes: 2 additions & 0 deletions tests/ui/assign_ops.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// run-rustfix

#[allow(dead_code, unused_assignments)]
#[warn(clippy::assign_op_pattern)]
fn main() {
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/assign_ops.stderr
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
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`
|
= 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"`
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/int_plus_one.fixed
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 8 additions & 6 deletions tests/ui/int_plus_one.rs
Original file line number Diff line number Diff line change
@@ -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
}
40 changes: 12 additions & 28 deletions tests/ui/int_plus_one.stderr
Original file line number Diff line number Diff line change
@@ -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
|
LL | y + 1 <= x;
| ^^^^^^^^^^
help: change `>= y + 1` to `> y` as shown
--> $DIR/int_plus_one.rs:10:13
|
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
|
LL | y <= x - 1;
| ^^^^^^^^^^
help: change `>= y + 1` to `> y` as shown
--> $DIR/int_plus_one.rs:13:13
|
LL | y < x;
| ^^^^^
LL | let _ = y <= x - 1;
| ^^^^^^^^^^ help: change it to: `y < x`

error: aborting due to 4 previous errors

25 changes: 25 additions & 0 deletions tests/ui/outer_expn_data.fixed
Original file line number Diff line number Diff line change
@@ -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() {}
2 changes: 2 additions & 0 deletions tests/ui/outer_expn_data.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// run-rustfix

#![deny(clippy::internal)]
#![feature(rustc_private)]

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/outer_expn_data.stderr
Original file line number Diff line number Diff line change
@@ -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)]
| ^^^^^^^^^^^^^^^^
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/rename.fixed
Original file line number Diff line number Diff line change
@@ -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() {}
10 changes: 3 additions & 7 deletions tests/ui/rename.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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() {}
10 changes: 5 additions & 5 deletions tests/ui/rename.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
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`
|
= 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`
Expand Down