From 189f264926ff70b58c8907473de60766477e7dd6 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Mon, 11 Aug 2025 01:46:34 +0000 Subject: Allow attr entries to declare list of alternatives for `List` and `NamedValueStr` Modify `AttributeTemplate` to support list of alternatives for list and name value attribute styles. Suggestions now provide more correct suggested code: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler)] | LL - #[used(compiler, linker)] LL + #[used(linker)] | LL - #[used(compiler, linker)] LL + #[used] | ``` instead of the prior "masking" of the lack of this feature by suggesting pipe-separated lists: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler|linker)] | LL - #[used(compiler, linker)] LL + #[used] | ``` --- compiler/rustc_parse/src/validate_attr.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_parse/src') diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index a7f8d3b9139..3df9f426ed0 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -298,11 +298,15 @@ fn emit_malformed_attribute( suggestions.push(format!("#{inner}[{name}]")); } if let Some(descr) = template.list { - suggestions.push(format!("#{inner}[{name}({descr})]")); + for descr in descr { + suggestions.push(format!("#{inner}[{name}({descr})]")); + } } suggestions.extend(template.one_of.iter().map(|&word| format!("#{inner}[{name}({word})]"))); if let Some(descr) = template.name_value_str { - suggestions.push(format!("#{inner}[{name} = \"{descr}\"]")); + for descr in descr { + suggestions.push(format!("#{inner}[{name} = \"{descr}\"]")); + } } if should_warn(name) { psess.buffer_lint( -- cgit 1.4.1-3-g733a5