From 8dd701cec77fec63902e78c575dd34e2f715dfa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= Date: Sun, 11 Jan 2026 16:25:10 +0100 Subject: [PATCH] add test for rejecting EIIs in statement position --- tests/ui/eii/error_statement_position.rs | 15 ++++++++------- tests/ui/eii/error_statement_position.stderr | 13 +++++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/ui/eii/error_statement_position.rs b/tests/ui/eii/error_statement_position.rs index cf81e7e6a8b2..75d87595b9e3 100644 --- a/tests/ui/eii/error_statement_position.rs +++ b/tests/ui/eii/error_statement_position.rs @@ -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() {} } diff --git a/tests/ui/eii/error_statement_position.stderr b/tests/ui/eii/error_statement_position.stderr index 01b7394ef00f..f14e6c33e64f 100644 --- a/tests/ui/eii/error_statement_position.stderr +++ b/tests/ui/eii/error_statement_position.stderr @@ -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