Skip to content

Commit 2006117

Browse files
committed
add ui tests for &raw not followed by const or mut
1 parent efc2576 commit 2006117

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Check that `&raw` that isn't followed by `const` or `mut` produces a
2+
//! helpful error message.
3+
//!
4+
//! Related issue: <https://github.com/rust-lang/rust/issues/133231>.
5+
6+
fn main() {
7+
let foo = 2;
8+
let _ = &raw foo;
9+
//~^ ERROR expected one of
10+
//~| HELP you might have meant to use a raw reference
11+
//~| HELP you might have meant to write a field access
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `foo`
2+
--> $DIR/let-stmt.rs:8:18
3+
|
4+
LL | let _ = &raw foo;
5+
| ^^^ expected one of 8 possible tokens
6+
|
7+
help: you might have meant to write a field access
8+
|
9+
LL | let _ = &raw.foo;
10+
| +
11+
12+
error: aborting due to 1 previous error
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Check that `&raw` that isn't followed by `const` or `mut` produces a
2+
//! helpful error message.
3+
//!
4+
//! Related issue: <https://github.com/rust-lang/rust/issues/133231>.
5+
6+
mod foo {
7+
pub static A: i32 = 0;
8+
}
9+
10+
fn main() {
11+
[&raw foo::A; 3];
12+
//~^ ERROR expected one of
13+
//~| HELP you might have meant to use a raw reference
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `!`, `,`, `.`, `::`, `;`, `?`, `]`, `{`, or an operator, found `foo`
2+
--> $DIR/nested-array-expr.rs:11:11
3+
|
4+
LL | [&raw foo::A; 3];
5+
| ^^^ expected one of 9 possible tokens
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Check that `&raw` that isn't followed by `const` or `mut` produces a
2+
//! helpful error message.
3+
//!
4+
//! Related issue: <https://github.com/rust-lang/rust/issues/133231>.
5+
6+
mod foo {
7+
pub static A: i32 = 0;
8+
}
9+
10+
fn get_ref() -> *const i32 {
11+
&raw foo::A
12+
//~^ ERROR expected one of
13+
//~| HELP you might have meant to use a raw reference
14+
}
15+
16+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `foo`
2+
--> $DIR/return-expr.rs:11:10
3+
|
4+
LL | &raw foo::A
5+
| ^^^ expected one of 8 possible tokens
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)