Auto merge of #4567 - phansch:toplevel_ref_arg, r=flip1995
Add run-rustfix for toplevel_ref_arg lint changelog: none cc #3630
This commit is contained in:
commit
d5ec41c442
25
tests/ui/toplevel_ref_arg.fixed
Normal file
25
tests/ui/toplevel_ref_arg.fixed
Normal file
@ -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;
|
||||
}
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
11
tests/ui/toplevel_ref_arg_non_rustfix.rs
Normal file
11
tests/ui/toplevel_ref_arg_non_rustfix.rs
Normal file
@ -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);
|
||||
}
|
10
tests/ui/toplevel_ref_arg_non_rustfix.stderr
Normal file
10
tests/ui/toplevel_ref_arg_non_rustfix.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user