add test for rejecting EIIs in statement position

This commit is contained in:
Jana Dönszelmann 2026-01-11 16:25:10 +01:00
parent df55233c6d
commit 8dd701cec7
No known key found for this signature in database
2 changed files with 19 additions and 9 deletions

View file

@ -1,11 +1,6 @@
#![feature(extern_item_impls)]
// EIIs can, despite not being super useful, be declared in statement position
// nested inside items. Items in statement position, when expanded as part of a macro,
// need to be wrapped slightly differently (in an `ast::Statement`).
// We did this on the happy path (no errors), but when there was an error, we'd
// replace it with *just* an `ast::Item` not wrapped in an `ast::Statement`.
// This caused an ICE (https://github.com/rust-lang/rust/issues/149980).
// this test fails to build, but demonstrates that no ICE is produced.
// EIIs cannot be used in statement position.
// This is also a regression test for an ICE (https://github.com/rust-lang/rust/issues/149980).
fn main() {
struct Bar;
@ -13,4 +8,10 @@ fn main() {
#[eii]
//~^ ERROR `#[eii]` is only valid on functions
impl Bar {}
// Even on functions, eiis in statement position are rejected
#[eii]
//~^ ERROR `#[eii]` can only be used on functions inside a module
fn foo() {}
}

View file

@ -1,8 +1,17 @@
error: `#[eii]` is only valid on functions
--> $DIR/error_statement_position.rs:13:5
--> $DIR/error_statement_position.rs:8:5
|
LL | #[eii]
| ^^^^^^
error: aborting due to 1 previous error
error: `#[eii]` can only be used on functions inside a module
--> $DIR/error_statement_position.rs:14:5
|
LL | #[eii]
| ^^^^^^
LL |
LL | fn foo() {}
| --- `#[eii]` is used on this item, which is part of another item's local scope
error: aborting due to 2 previous errors