From df83732f0971ec74f126009f40241b9730750300 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Mon, 23 Sep 2019 11:19:24 +0200 Subject: [PATCH] Add run-rustfix for toplevel_ref_arg lint --- tests/ui/toplevel_ref_arg.fixed | 25 ++++++++++++++++++++ tests/ui/toplevel_ref_arg.rs | 10 +++----- tests/ui/toplevel_ref_arg.stderr | 22 +++++++---------- tests/ui/toplevel_ref_arg_non_rustfix.rs | 11 +++++++++ tests/ui/toplevel_ref_arg_non_rustfix.stderr | 10 ++++++++ 5 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 tests/ui/toplevel_ref_arg.fixed create mode 100644 tests/ui/toplevel_ref_arg_non_rustfix.rs create mode 100644 tests/ui/toplevel_ref_arg_non_rustfix.stderr diff --git a/tests/ui/toplevel_ref_arg.fixed b/tests/ui/toplevel_ref_arg.fixed new file mode 100644 index 00000000000..8a4bf530173 --- /dev/null +++ b/tests/ui/toplevel_ref_arg.fixed @@ -0,0 +1,25 @@ +// run-rustfix + +#![warn(clippy::toplevel_ref_arg)] +#![allow(unused)] + +fn main() { + // Closures should not warn + let y = |ref x| println!("{:?}", x); + y(1u8); + + let x = &1; + + let y: &(&_, u8) = &(&1, 2); + + let z = &(1 + 2); + + let z = &mut (1 + 2); + + let (ref x, _) = (1, 2); // ok, not top level + println!("The answer is {}.", x); + + // Make sure that allowing the lint works + #[allow(clippy::toplevel_ref_arg)] + let ref mut x = 1_234_543; +} diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs index a412c387a0d..7d5eaa940e1 100644 --- a/tests/ui/toplevel_ref_arg.rs +++ b/tests/ui/toplevel_ref_arg.rs @@ -1,13 +1,9 @@ -#![warn(clippy::all)] +// run-rustfix + +#![warn(clippy::toplevel_ref_arg)] #![allow(unused)] -fn the_answer(ref mut x: u8) { - *x = 42; -} - fn main() { - let mut x = 0; - the_answer(x); // Closures should not warn let y = |ref x| println!("{:?}", x); y(1u8); diff --git a/tests/ui/toplevel_ref_arg.stderr b/tests/ui/toplevel_ref_arg.stderr index 00a753c6ac2..de80a9614de 100644 --- a/tests/ui/toplevel_ref_arg.stderr +++ b/tests/ui/toplevel_ref_arg.stderr @@ -1,34 +1,28 @@ -error: `ref` directly on a function argument is ignored. Consider using a reference type instead. - --> $DIR/toplevel_ref_arg.rs:4:15 +error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead + --> $DIR/toplevel_ref_arg.rs:11:9 | -LL | fn the_answer(ref mut x: u8) { - | ^^^^^^^^^ +LL | let ref x = 1; + | ----^^^^^----- help: try: `let x = &1;` | = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:15:9 - | -LL | let ref x = 1; - | ----^^^^^----- help: try: `let x = &1;` - -error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:17:9 + --> $DIR/toplevel_ref_arg.rs:13:9 | LL | let ref 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 - --> $DIR/toplevel_ref_arg.rs:19:9 + --> $DIR/toplevel_ref_arg.rs:15:9 | LL | let ref z = 1 + 2; | ----^^^^^--------- help: try: `let z = &(1 + 2);` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:21:9 + --> $DIR/toplevel_ref_arg.rs:17:9 | LL | let ref mut z = 1 + 2; | ----^^^^^^^^^--------- help: try: `let z = &mut (1 + 2);` -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.rs b/tests/ui/toplevel_ref_arg_non_rustfix.rs new file mode 100644 index 00000000000..42cac2ba4de --- /dev/null +++ b/tests/ui/toplevel_ref_arg_non_rustfix.rs @@ -0,0 +1,11 @@ +#![warn(clippy::toplevel_ref_arg)] +#![allow(unused)] + +fn the_answer(ref mut x: u8) { + *x = 42; +} + +fn main() { + let mut x = 0; + the_answer(x); +} diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/tests/ui/toplevel_ref_arg_non_rustfix.stderr new file mode 100644 index 00000000000..295e2f35608 --- /dev/null +++ b/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -0,0 +1,10 @@ +error: `ref` directly on a function argument is ignored. Consider using a reference type instead. + --> $DIR/toplevel_ref_arg_non_rustfix.rs:4:15 + | +LL | fn the_answer(ref mut x: u8) { + | ^^^^^^^^^ + | + = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` + +error: aborting due to previous error +