File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 11//@ run-pass
22
3+ #![ allow( unnecessary_refs) ]
4+
35struct Struct {
46 field : ( ) ,
57}
Original file line number Diff line number Diff line change 1+ #![ deny( unnecessary_refs) ]
2+
3+ struct A {
4+ a : i32 ,
5+ b : u8 ,
6+ }
7+
8+ fn via_ref ( x : * const ( i32 , i32 ) ) -> * const i32 {
9+ unsafe { & ( * x) . 0 as * const i32 }
10+ //~^ ERROR creating unecessary reference is discouraged [unnecessary_refs]
11+ }
12+
13+ fn via_ref_struct ( x : * const A ) -> * const u8 {
14+ unsafe { & ( * x) . b as * const u8 }
15+ //~^ ERROR creating unecessary reference is discouraged [unnecessary_refs]
16+ }
17+
18+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: creating unecessary reference is discouraged
2+ --> $DIR/lint-unnecessary-refs.rs:9:14
3+ |
4+ LL | unsafe { &(*x).0 as *const i32 }
5+ | ^^^^^^^^^^^^^^^^^^^^^
6+ |
7+ note: the lint level is defined here
8+ --> $DIR/lint-unnecessary-refs.rs:1:9
9+ |
10+ LL | #![deny(unnecessary_refs)]
11+ | ^^^^^^^^^^^^^^^^
12+ help: consider using `&raw const` for a safer and more explicit raw pointer
13+ |
14+ LL - unsafe { &(*x).0 as *const i32 }
15+ LL + unsafe { &raw const (*x).0 }
16+ |
17+
18+ error: creating unecessary reference is discouraged
19+ --> $DIR/lint-unnecessary-refs.rs:14:14
20+ |
21+ LL | unsafe { &(*x).b as *const u8 }
22+ | ^^^^^^^^^^^^^^^^^^^^
23+ |
24+ help: consider using `&raw const` for a safer and more explicit raw pointer
25+ |
26+ LL - unsafe { &(*x).b as *const u8 }
27+ LL + unsafe { &raw const (*x).b }
28+ |
29+
30+ error: aborting due to 2 previous errors
31+
You can’t perform that action at this time.
0 commit comments