Skip to content

Commit d03b5b4

Browse files
tests: overly-terse inline-const-as-item error
1 parent 506f22b commit d03b5b4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// reported in https://github.com/rust-lang/rust/issues/128338
2+
3+
// This had an overly-terse diagnostic, because we recognized this is where an item should be, but
4+
// but didn't recognize an inline const in this place is probably trying to be an "anon const item".
5+
// Those are written like this:
6+
const _: () = {};
7+
// const _ are often used as compile-time assertions that don't conflict with other const items
8+
9+
const { assert!(size_of::<u32>() <= size_of::<usize>()) };
10+
//~^ error: expected item
11+
//~| for a full list of items
12+
13+
fn main() {
14+
const { assert!(size_of::<u32>() <= size_of::<usize>()) };
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected item, found keyword `const`
2+
--> $DIR/expr-in-item-context.rs:9:1
3+
|
4+
LL | const { assert!(size_of::<u32>() <= size_of::<usize>()) };
5+
| ^^^^^ expected item
6+
|
7+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)