Skip to content

Commit 6312207

Browse files
committed
Added tests
1 parent f214189 commit 6312207

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ run-rustfix
2+
#![allow(
3+
dead_code,
4+
unused_must_use
5+
)]
6+
7+
struct Named {
8+
foo: usize,
9+
}
10+
11+
struct Unnamed(usize);
12+
13+
fn named_struct_field_access(named: *mut Named) {
14+
named->foo += 1; //~ ERROR `->` used for field access or method call
15+
}
16+
17+
fn unnamed_struct_field_access(unnamed: *mut Unnamed) {
18+
unnamed->0 += 1; //~ ERROR `->` used for field access or method call
19+
}
20+
21+
fn main() {}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
error: `->` used for field access or method call
2+
--> $DIR/expr-rarrow-call-on-a-raw-pointer.rs:14:10
3+
|
4+
LL | named->foo += 1;
5+
| ^^
6+
|
7+
= help: the `.` operator will automatically dereference the value, except if the value is a raw pointer
8+
help: try using `.` instead
9+
|
10+
LL - named->foo += 1;
11+
LL + named.foo += 1;
12+
|
13+
14+
error: `->` used for field access or method call
15+
--> $DIR/expr-rarrow-call-on-a-raw-pointer.rs:18:12
16+
|
17+
LL | unnamed->0 += 1;
18+
| ^^
19+
|
20+
= help: the `.` operator will automatically dereference the value, except if the value is a raw pointer
21+
help: try using `.` instead
22+
|
23+
LL - unnamed->0 += 1;
24+
LL + unnamed.0 += 1;
25+
|
26+
27+
error[E0609]: no field `foo` on type `*mut Named`
28+
--> $DIR/expr-rarrow-call-on-a-raw-pointer.rs:14:12
29+
|
30+
LL | named->foo += 1;
31+
| ^^^ unknown field
32+
|
33+
help: `named` is a raw pointer; try dereferencing it
34+
|
35+
LL - named->foo += 1;
36+
LL + (*named).foo += 1;
37+
|
38+
39+
error[E0609]: no field `0` on type `*mut Unnamed`
40+
--> $DIR/expr-rarrow-call-on-a-raw-pointer.rs:18:14
41+
|
42+
LL | unnamed->0 += 1;
43+
| ^ unknown field
44+
|
45+
help: `unnamed` is a raw pointer; try dereferencing it
46+
|
47+
LL - unnamed->0 += 1;
48+
LL + (*unnamed).0 += 1;
49+
|
50+
51+
error: aborting due to 4 previous errors
52+
53+
For more information about this error, try `rustc --explain E0609`.

0 commit comments

Comments
 (0)