Skip to content

Commit 8d04038

Browse files
Make deref_addrof suggestions stricter
SUGGESTION matches a substring so 'aref' in the testcases can match 'let b = *aref', 'let b = **aref', 'let b = *&aref' etc, which are all wrong.
1 parent a9f5b90 commit 8d04038

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

tests/compile-fail/reference.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,56 +19,58 @@ fn main() {
1919
let b = *&a;
2020
//~^ERROR immediately dereferencing a reference
2121
//~|HELP try this
22-
//~|SUGGESTION a
22+
//~|SUGGESTION let b = a;
2323

2424
let b = *&get_number();
2525
//~^ERROR immediately dereferencing a reference
2626
//~|HELP try this
27-
//~|SUGGESTION get_number()
27+
//~|SUGGESTION let b = get_number();
2828

2929
let b = *get_reference(&a);
3030

3131
let bytes : Vec<usize> = vec![1, 2, 3, 4];
3232
let b = *&bytes[1..2][0];
3333
//~^ERROR immediately dereferencing a reference
3434
//~|HELP try this
35-
//~|SUGGESTION bytes[1..2][0]
35+
//~|SUGGESTION let b = bytes[1..2][0];
3636

3737
let b = *(&a);
3838
//~^ERROR immediately dereferencing a reference
3939
//~|HELP try this
40-
//~|SUGGESTION a
40+
//~|SUGGESTION let b = a;
4141

4242
let b = *&&a;
4343
//~^ERROR immediately dereferencing a reference
4444
//~|HELP try this
45-
//~|SUGGESTION &a
45+
//~|SUGGESTION let b = &a;
4646

4747
let b = **&aref;
4848
//~^ERROR immediately dereferencing a reference
4949
//~|HELP try this
50-
//~|SUGGESTION aref
50+
//~|SUGGESTION let b = *aref;
5151

52-
//This produces a suggestion of 'let b = *&a;' which is still incorrect
52+
//This produces a suggestion of 'let b = *&a;' which
53+
//will trigger the 'deref_addrof' lint again
5354
let b = **&&a;
5455
//~^ERROR immediately dereferencing a reference
5556
//~|HELP try this
56-
//~|SUGGESTION a
57+
//~|SUGGESTION let b = *&a;
5758

5859
{
5960
let mut x = 10;
6061
let y = *&mut x;
6162
//~^ERROR immediately dereferencing a reference
6263
//~|HELP try this
63-
//~|SUGGESTION x
64+
//~|SUGGESTION let y = x;
6465
}
6566

6667
{
67-
//This produces a suggestion of 'let y = *&mut x' which is still incorrect
68+
//This produces a suggestion of 'let y = *&mut x' which
69+
//will trigger the 'deref_addrof' lint again
6870
let mut x = 10;
6971
let y = **&mut &mut x;
7072
//~^ERROR immediately dereferencing a reference
7173
//~|HELP try this
72-
//~|SUGGESTION x
74+
//~|SUGGESTION let y = *&mut x;
7375
}
7476
}

0 commit comments

Comments
 (0)