From d1e84c615c31be8fa6ca40fddaabc5ed30910efa Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Tue, 16 Apr 2019 20:26:55 +0200 Subject: [PATCH] Add run-rustfix for deref_addrof lint * renames `tests/ui/reference.{rs,stderr}` to `tests/ui/deref_addrof.{rs,stderr} * Moves small part of the testfile to a separate file as the lint triggered again on the fixed code (as intended) * Adds `// run-rustfix` to `tests/ui/deref_addrof.rs` --- tests/ui/deref_addrof.fixed | 39 +++++++++++++++++++ tests/ui/{reference.rs => deref_addrof.rs} | 20 ++-------- .../{reference.stderr => deref_addrof.stderr} | 36 +++++------------ tests/ui/deref_addrof_double_trigger.rs | 21 ++++++++++ tests/ui/deref_addrof_double_trigger.stderr | 22 +++++++++++ 5 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 tests/ui/deref_addrof.fixed rename tests/ui/{reference.rs => deref_addrof.rs} (59%) rename tests/ui/{reference.stderr => deref_addrof.stderr} (58%) create mode 100644 tests/ui/deref_addrof_double_trigger.rs create mode 100644 tests/ui/deref_addrof_double_trigger.stderr diff --git a/tests/ui/deref_addrof.fixed b/tests/ui/deref_addrof.fixed new file mode 100644 index 000000000000..9e5b51d6d5e6 --- /dev/null +++ b/tests/ui/deref_addrof.fixed @@ -0,0 +1,39 @@ +// run-rustfix + +fn get_number() -> usize { + 10 +} + +fn get_reference(n: &usize) -> &usize { + n +} + +#[allow(clippy::many_single_char_names, clippy::double_parens)] +#[allow(unused_variables, unused_parens)] +#[warn(clippy::deref_addrof)] +fn main() { + let a = 10; + let aref = &a; + + let b = a; + + let b = get_number(); + + let b = *get_reference(&a); + + let bytes: Vec = vec![1, 2, 3, 4]; + let b = bytes[1..2][0]; + + //This produces a suggestion of 'let b = (a);' which + //will trigger the 'unused_parens' lint + let b = (a); + + let b = a; + + #[rustfmt::skip] + let b = a; + + let b = &a; + + let b = *aref; +} diff --git a/tests/ui/reference.rs b/tests/ui/deref_addrof.rs similarity index 59% rename from tests/ui/reference.rs rename to tests/ui/deref_addrof.rs index c63997fa8583..5641a73cbc1c 100644 --- a/tests/ui/reference.rs +++ b/tests/ui/deref_addrof.rs @@ -1,3 +1,5 @@ +// run-rustfix + fn get_number() -> usize { 10 } @@ -7,7 +9,7 @@ fn get_reference(n: &usize) -> &usize { } #[allow(clippy::many_single_char_names, clippy::double_parens)] -#[allow(unused_variables)] +#[allow(unused_variables, unused_parens)] #[warn(clippy::deref_addrof)] fn main() { let a = 10; @@ -34,20 +36,4 @@ fn main() { let b = *&&a; let b = **&aref; - - //This produces a suggestion of 'let b = *&a;' which - //will trigger the 'clippy::deref_addrof' lint again - let b = **&&a; - - { - let mut x = 10; - let y = *&mut x; - } - - { - //This produces a suggestion of 'let y = *&mut x' which - //will trigger the 'clippy::deref_addrof' lint again - let mut x = 10; - let y = **&mut &mut x; - } } diff --git a/tests/ui/reference.stderr b/tests/ui/deref_addrof.stderr similarity index 58% rename from tests/ui/reference.stderr rename to tests/ui/deref_addrof.stderr index aea95a7fa9f3..bc51719e8a7a 100644 --- a/tests/ui/reference.stderr +++ b/tests/ui/deref_addrof.stderr @@ -1,5 +1,5 @@ error: immediately dereferencing a reference - --> $DIR/reference.rs:16:13 + --> $DIR/deref_addrof.rs:18:13 | LL | let b = *&a; | ^^^ help: try this: `a` @@ -7,64 +7,46 @@ LL | let b = *&a; = note: `-D clippy::deref-addrof` implied by `-D warnings` error: immediately dereferencing a reference - --> $DIR/reference.rs:18:13 + --> $DIR/deref_addrof.rs:20:13 | LL | let b = *&get_number(); | ^^^^^^^^^^^^^^ help: try this: `get_number()` error: immediately dereferencing a reference - --> $DIR/reference.rs:23:13 + --> $DIR/deref_addrof.rs:25:13 | LL | let b = *&bytes[1..2][0]; | ^^^^^^^^^^^^^^^^ help: try this: `bytes[1..2][0]` error: immediately dereferencing a reference - --> $DIR/reference.rs:27:13 + --> $DIR/deref_addrof.rs:29:13 | LL | let b = *&(a); | ^^^^^ help: try this: `(a)` error: immediately dereferencing a reference - --> $DIR/reference.rs:29:13 + --> $DIR/deref_addrof.rs:31:13 | LL | let b = *(&a); | ^^^^^ help: try this: `a` error: immediately dereferencing a reference - --> $DIR/reference.rs:32:13 + --> $DIR/deref_addrof.rs:34:13 | LL | let b = *((&a)); | ^^^^^^^ help: try this: `a` error: immediately dereferencing a reference - --> $DIR/reference.rs:34:13 + --> $DIR/deref_addrof.rs:36:13 | LL | let b = *&&a; | ^^^^ help: try this: `&a` error: immediately dereferencing a reference - --> $DIR/reference.rs:36:14 + --> $DIR/deref_addrof.rs:38:14 | LL | let b = **&aref; | ^^^^^^ help: try this: `aref` -error: immediately dereferencing a reference - --> $DIR/reference.rs:40:14 - | -LL | let b = **&&a; - | ^^^^ help: try this: `&a` - -error: immediately dereferencing a reference - --> $DIR/reference.rs:44:17 - | -LL | let y = *&mut x; - | ^^^^^^^ help: try this: `x` - -error: immediately dereferencing a reference - --> $DIR/reference.rs:51:18 - | -LL | let y = **&mut &mut x; - | ^^^^^^^^^^^^ help: try this: `&mut x` - -error: aborting due to 11 previous errors +error: aborting due to 8 previous errors diff --git a/tests/ui/deref_addrof_double_trigger.rs b/tests/ui/deref_addrof_double_trigger.rs new file mode 100644 index 000000000000..e19af5b9087f --- /dev/null +++ b/tests/ui/deref_addrof_double_trigger.rs @@ -0,0 +1,21 @@ +#[warn(clippy::deref_addrof)] +#[allow(unused_variables)] +fn main() { + let a = 10; + + //This produces a suggestion of 'let b = *&a;' which + //will trigger the 'clippy::deref_addrof' lint again + let b = **&&a; + + { + let mut x = 10; + let y = *&mut x; + } + + { + //This produces a suggestion of 'let y = *&mut x' which + //will trigger the 'clippy::deref_addrof' lint again + let mut x = 10; + let y = **&mut &mut x; + } +} diff --git a/tests/ui/deref_addrof_double_trigger.stderr b/tests/ui/deref_addrof_double_trigger.stderr new file mode 100644 index 000000000000..89284e1a8ed6 --- /dev/null +++ b/tests/ui/deref_addrof_double_trigger.stderr @@ -0,0 +1,22 @@ +error: immediately dereferencing a reference + --> $DIR/deref_addrof_double_trigger.rs:8:14 + | +LL | let b = **&&a; + | ^^^^ help: try this: `&a` + | + = note: `-D clippy::deref-addrof` implied by `-D warnings` + +error: immediately dereferencing a reference + --> $DIR/deref_addrof_double_trigger.rs:12:17 + | +LL | let y = *&mut x; + | ^^^^^^^ help: try this: `x` + +error: immediately dereferencing a reference + --> $DIR/deref_addrof_double_trigger.rs:19:18 + | +LL | let y = **&mut &mut x; + | ^^^^^^^^^^^^ help: try this: `&mut x` + +error: aborting due to 3 previous errors +