Skip to content

Commit 75c591d

Browse files
committed
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`
1 parent d516925 commit 75c591d

5 files changed

+99
-44
lines changed

tests/ui/deref_addrof.fixed

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// run-rustfix
2+
3+
fn get_number() -> usize {
4+
10
5+
}
6+
7+
fn get_reference(n: &usize) -> &usize {
8+
n
9+
}
10+
11+
#[allow(clippy::many_single_char_names, clippy::double_parens)]
12+
#[allow(unused_variables, unused_parens)]
13+
#[warn(clippy::deref_addrof)]
14+
fn main() {
15+
let a = 10;
16+
let aref = &a;
17+
18+
let b = a;
19+
20+
let b = get_number();
21+
22+
let b = *get_reference(&a);
23+
24+
let bytes: Vec<usize> = vec![1, 2, 3, 4];
25+
let b = bytes[1..2][0];
26+
27+
//This produces a suggestion of 'let b = (a);' which
28+
//will trigger the 'unused_parens' lint
29+
let b = (a);
30+
31+
let b = a;
32+
33+
#[rustfmt::skip]
34+
let b = a;
35+
36+
let b = &a;
37+
38+
let b = *aref;
39+
}

tests/ui/reference.rs renamed to tests/ui/deref_addrof.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-rustfix
2+
13
fn get_number() -> usize {
24
10
35
}
@@ -7,7 +9,7 @@ fn get_reference(n: &usize) -> &usize {
79
}
810

911
#[allow(clippy::many_single_char_names, clippy::double_parens)]
10-
#[allow(unused_variables)]
12+
#[allow(unused_variables, unused_parens)]
1113
#[warn(clippy::deref_addrof)]
1214
fn main() {
1315
let a = 10;
@@ -34,20 +36,4 @@ fn main() {
3436
let b = *&&a;
3537

3638
let b = **&aref;
37-
38-
//This produces a suggestion of 'let b = *&a;' which
39-
//will trigger the 'clippy::deref_addrof' lint again
40-
let b = **&&a;
41-
42-
{
43-
let mut x = 10;
44-
let y = *&mut x;
45-
}
46-
47-
{
48-
//This produces a suggestion of 'let y = *&mut x' which
49-
//will trigger the 'clippy::deref_addrof' lint again
50-
let mut x = 10;
51-
let y = **&mut &mut x;
52-
}
5339
}
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,52 @@
11
error: immediately dereferencing a reference
2-
--> $DIR/reference.rs:16:13
2+
--> $DIR/deref_addrof.rs:18:13
33
|
44
LL | let b = *&a;
55
| ^^^ help: try this: `a`
66
|
77
= note: `-D clippy::deref-addrof` implied by `-D warnings`
88

99
error: immediately dereferencing a reference
10-
--> $DIR/reference.rs:18:13
10+
--> $DIR/deref_addrof.rs:20:13
1111
|
1212
LL | let b = *&get_number();
1313
| ^^^^^^^^^^^^^^ help: try this: `get_number()`
1414

1515
error: immediately dereferencing a reference
16-
--> $DIR/reference.rs:23:13
16+
--> $DIR/deref_addrof.rs:25:13
1717
|
1818
LL | let b = *&bytes[1..2][0];
1919
| ^^^^^^^^^^^^^^^^ help: try this: `bytes[1..2][0]`
2020

2121
error: immediately dereferencing a reference
22-
--> $DIR/reference.rs:27:13
22+
--> $DIR/deref_addrof.rs:29:13
2323
|
2424
LL | let b = *&(a);
2525
| ^^^^^ help: try this: `(a)`
2626

2727
error: immediately dereferencing a reference
28-
--> $DIR/reference.rs:29:13
28+
--> $DIR/deref_addrof.rs:31:13
2929
|
3030
LL | let b = *(&a);
3131
| ^^^^^ help: try this: `a`
3232

3333
error: immediately dereferencing a reference
34-
--> $DIR/reference.rs:32:13
34+
--> $DIR/deref_addrof.rs:34:13
3535
|
3636
LL | let b = *((&a));
3737
| ^^^^^^^ help: try this: `a`
3838

3939
error: immediately dereferencing a reference
40-
--> $DIR/reference.rs:34:13
40+
--> $DIR/deref_addrof.rs:36:13
4141
|
4242
LL | let b = *&&a;
4343
| ^^^^ help: try this: `&a`
4444

4545
error: immediately dereferencing a reference
46-
--> $DIR/reference.rs:36:14
46+
--> $DIR/deref_addrof.rs:38:14
4747
|
4848
LL | let b = **&aref;
4949
| ^^^^^^ help: try this: `aref`
5050

51-
error: immediately dereferencing a reference
52-
--> $DIR/reference.rs:40:14
53-
|
54-
LL | let b = **&&a;
55-
| ^^^^ help: try this: `&a`
56-
57-
error: immediately dereferencing a reference
58-
--> $DIR/reference.rs:44:17
59-
|
60-
LL | let y = *&mut x;
61-
| ^^^^^^^ help: try this: `x`
62-
63-
error: immediately dereferencing a reference
64-
--> $DIR/reference.rs:51:18
65-
|
66-
LL | let y = **&mut &mut x;
67-
| ^^^^^^^^^^^^ help: try this: `&mut x`
68-
69-
error: aborting due to 11 previous errors
51+
error: aborting due to 8 previous errors
7052

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[warn(clippy::deref_addrof)]
2+
#[allow(unused_variables)]
3+
fn main() {
4+
//This produces a suggestion of 'let b = *&a;' which
5+
//will trigger the 'clippy::deref_addrof' lint again
6+
let b = **&&a;
7+
8+
{
9+
let mut x = 10;
10+
let y = *&mut x;
11+
}
12+
13+
{
14+
//This produces a suggestion of 'let y = *&mut x' which
15+
//will trigger the 'clippy::deref_addrof' lint again
16+
let mut x = 10;
17+
let y = **&mut &mut x;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0425]: cannot find value `a` in this scope
2+
--> $DIR/deref_addrof_double_trigger.rs:6:17
3+
|
4+
LL | let b = **&&a;
5+
| ^ not found in this scope
6+
7+
error: immediately dereferencing a reference
8+
--> $DIR/deref_addrof_double_trigger.rs:6:14
9+
|
10+
LL | let b = **&&a;
11+
| ^^^^ help: try this: `&a`
12+
|
13+
= note: `-D clippy::deref-addrof` implied by `-D warnings`
14+
15+
error: immediately dereferencing a reference
16+
--> $DIR/deref_addrof_double_trigger.rs:10:17
17+
|
18+
LL | let y = *&mut x;
19+
| ^^^^^^^ help: try this: `x`
20+
21+
error: immediately dereferencing a reference
22+
--> $DIR/deref_addrof_double_trigger.rs:17:18
23+
|
24+
LL | let y = **&mut &mut x;
25+
| ^^^^^^^^^^^^ help: try this: `&mut x`
26+
27+
error: aborting due to 4 previous errors
28+
29+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)