Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1e686f1

Browse files
committed
Add test for unnecessary_refs lint
1 parent d297ee4 commit 1e686f1

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

‎tests/ui/consts/offset_from.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//@ run-pass
22

3+
#![allow(unnecessary_refs)]
4+
35
struct Struct {
46
field: (),
57
}

‎tests/ui/lint/lint-unnecessary-refs.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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() {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /