diff --git a/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs b/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs index c2511ac75d5d2..c2bf70534ad3e 100644 --- a/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs +++ b/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs @@ -91,14 +91,29 @@ fn parse_unstable( for param in list.mixed() { let param_span = param.span(); - if let Some(ident) = param.meta_item().and_then(|i| i.path().word()) { - res.push(ident.name); - } else { + let fail = || { cx.emit_err(session_diagnostics::ExpectsFeatures { span: param_span, name: symbol.to_ident_string(), - }); - } + }) + }; + + let Some(meta_item) = param.meta_item() else { + fail(); + continue; + }; + + let Ok(()) = meta_item.args().no_args() else { + fail(); + continue; + }; + + let Some(ident) = meta_item.path().word() else { + fail(); + continue; + }; + + res.push(ident.name); } res diff --git a/tests/ui/attributes/allow-internal-unstable-name-value.rs b/tests/ui/attributes/allow-internal-unstable-name-value.rs new file mode 100644 index 0000000000000..a05a53d352b6e --- /dev/null +++ b/tests/ui/attributes/allow-internal-unstable-name-value.rs @@ -0,0 +1,9 @@ +#![feature(allow_internal_unstable)] +#![allow(internal_features)] + +#[allow_internal_unstable(cat = "meow")] //~ ERROR `allow_internal_unstable` expects feature names +macro_rules! foo { + () => {} +} + +fn main() {} diff --git a/tests/ui/attributes/allow-internal-unstable-name-value.stderr b/tests/ui/attributes/allow-internal-unstable-name-value.stderr new file mode 100644 index 0000000000000..f0adc556993b8 --- /dev/null +++ b/tests/ui/attributes/allow-internal-unstable-name-value.stderr @@ -0,0 +1,8 @@ +error: `allow_internal_unstable` expects feature names + --> $DIR/allow-internal-unstable-name-value.rs:4:27 + | +LL | #[allow_internal_unstable(cat = "meow")] + | ^^^^^^^^^^^^ + +error: aborting due to 1 previous error +