Skip to content

Commit 189f264

Browse files
committed
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] | ```
1 parent 5771665 commit 189f264

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+711
-272
lines changed

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser {
1515
type Item = (Symbol, Span);
1616
const CONVERT: ConvertFn<Self::Item> =
1717
|items, span| AttributeKind::AllowInternalUnstable(items, span);
18-
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
18+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["feat1, feat2, ..."]);
1919

2020
fn extend<'c>(
2121
cx: &'c mut AcceptContext<'_, '_, S>,
@@ -32,7 +32,7 @@ impl<S: Stage> CombineAttributeParser<S> for UnstableFeatureBoundParser {
3232
const PATH: &'static [rustc_span::Symbol] = &[sym::unstable_feature_bound];
3333
type Item = (Symbol, Span);
3434
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::UnstableFeatureBound(items);
35-
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
35+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["feat1, feat2, ..."]);
3636

3737
fn extend<'c>(
3838
cx: &'c mut AcceptContext<'_, '_, S>,
@@ -53,7 +53,7 @@ impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
5353
type Item = Symbol;
5454
const CONVERT: ConvertFn<Self::Item> =
5555
|items, first_span| AttributeKind::AllowConstFnUnstable(items, first_span);
56-
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
56+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["feat1, feat2, ..."]);
5757

5858
fn extend<'c>(
5959
cx: &'c mut AcceptContext<'_, '_, S>,

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
CfgMatchesLintEmitter, fluent_generated, parse_version, session_diagnostics, try_gate_cfg,
1717
};
1818

19-
pub const CFG_TEMPLATE: AttributeTemplate = template!(List: "predicate");
19+
pub const CFG_TEMPLATE: AttributeTemplate = template!(List: &["predicate"]);
2020

2121
pub fn parse_cfg_attr<'c, S: Stage>(
2222
cx: &'c mut AcceptContext<'_, '_, S>,

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
1717
const PATH: &[Symbol] = &[sym::optimize];
1818
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1919
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
20-
const TEMPLATE: AttributeTemplate = template!(List: "size|speed|none");
20+
const TEMPLATE: AttributeTemplate = template!(List: &["size", "speed", "none"]);
2121

2222
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
2323
let Some(list) = args.list() else {
@@ -253,7 +253,7 @@ pub(crate) struct UsedParser {
253253
impl<S: Stage> AttributeParser<S> for UsedParser {
254254
const ATTRIBUTES: AcceptMapping<Self, S> = &[(
255255
&[sym::used],
256-
template!(Word, List: "compiler|linker"),
256+
template!(Word, List: &["compiler", "linker"]),
257257
|group: &mut Self, cx, args| {
258258
let used_by = match args {
259259
ArgParser::NoArgs => UsedBy::Linker,
@@ -327,7 +327,7 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
327327
type Item = (Symbol, Span);
328328
const PATH: &[Symbol] = &[sym::target_feature];
329329
const CONVERT: ConvertFn<Self::Item> = |items, span| AttributeKind::TargetFeature(items, span);
330-
const TEMPLATE: AttributeTemplate = template!(List: "enable = \"feat1, feat2\"");
330+
const TEMPLATE: AttributeTemplate = template!(List: &["enable = \"feat1, feat2\""]);
331331

332332
fn extend<'c>(
333333
cx: &'c mut AcceptContext<'_, '_, S>,

compiler/rustc_attr_parsing/src/attributes/confusables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) struct ConfusablesParser {
1616
impl<S: Stage> AttributeParser<S> for ConfusablesParser {
1717
const ATTRIBUTES: AcceptMapping<Self, S> = &[(
1818
&[sym::rustc_confusables],
19-
template!(List: r#""name1", "name2", ..."#),
19+
template!(List: &[r#""name1", "name2", ..."#]),
2020
|this, cx, args| {
2121
let Some(list) = args.list() else {
2222
cx.expected_list(cx.attr_span);

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
4040
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
4141
const TEMPLATE: AttributeTemplate = template!(
4242
Word,
43-
List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
43+
List: &[r#"since = "version""#, r#"note = "reason""#, r#"since = "version", note = "reason""#],
4444
NameValueStr: "reason"
4545
);
4646

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
1818
const PATH: &'static [Symbol] = &[sym::inline];
1919
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
2020
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
21-
const TEMPLATE: AttributeTemplate = template!(Word, List: "always|never");
21+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["always", "never"]);
2222

2323
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
2424
match args {
@@ -59,7 +59,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser {
5959
const PATH: &'static [Symbol] = &[sym::rustc_force_inline];
6060
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
6161
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
62-
const TEMPLATE: AttributeTemplate = template!(Word, List: "reason", NameValueStr: "reason");
62+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["reason"], NameValueStr: "reason");
6363

6464
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
6565
let reason = match args {

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<S: Stage> SingleAttributeParser<S> for LinkOrdinalParser {
9494
const PATH: &[Symbol] = &[sym::link_ordinal];
9595
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
9696
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
97-
const TEMPLATE: AttributeTemplate = template!(List: "ordinal");
97+
const TEMPLATE: AttributeTemplate = template!(List: &["ordinal"]);
9898

9999
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
100100
let ordinal = parse_single_integer(cx, args)?;

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) struct MacroUseParser {
3131
first_span: Option<Span>,
3232
}
3333

34-
const MACRO_USE_TEMPLATE: AttributeTemplate = template!(Word, List: "name1, name2, ...");
34+
const MACRO_USE_TEMPLATE: AttributeTemplate = template!(Word, List: &["name1, name2, ..."]);
3535

3636
impl<S: Stage> AttributeParser<S> for MacroUseParser {
3737
const ATTRIBUTES: AcceptMapping<Self, S> = &[(

compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<S: Stage> SingleAttributeParser<S> for ProcMacroDeriveParser {
2929
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
3030
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
3131
const TEMPLATE: AttributeTemplate =
32-
template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)");
32+
template!(List: &["TraitName", "TraitName, attributes(name1, name2, ...)"]);
3333

3434
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
3535
let (trait_name, helper_attrs) = parse_derive_like(cx, args, true)?;
@@ -47,7 +47,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcBuiltinMacroParser {
4747
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
4848
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
4949
const TEMPLATE: AttributeTemplate =
50-
template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)");
50+
template!(List: &["TraitName", "TraitName, attributes(name1, name2, ...)"]);
5151

5252
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
5353
let (builtin_name, helper_attrs) = parse_derive_like(cx, args, false)?;

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ impl<S: Stage> CombineAttributeParser<S> for ReprParser {
2626
const CONVERT: ConvertFn<Self::Item> =
2727
|items, first_span| AttributeKind::Repr { reprs: items, first_span };
2828
// FIXME(jdonszelmann): never used
29-
const TEMPLATE: AttributeTemplate =
30-
template!(List: "C | Rust | align(...) | packed(...) | <integer type> | transparent");
29+
const TEMPLATE: AttributeTemplate = template!(List: &["C", "Rust", "transparent", "align(...)", "packed(...)", "<integer type>"]);
3130

3231
fn extend<'c>(
3332
cx: &'c mut AcceptContext<'_, '_, S>,
@@ -275,7 +274,7 @@ pub(crate) struct AlignParser(Option<(Align, Span)>);
275274

276275
impl AlignParser {
277276
const PATH: &'static [Symbol] = &[sym::rustc_align];
278-
const TEMPLATE: AttributeTemplate = template!(List: "<alignment in bytes>");
277+
const TEMPLATE: AttributeTemplate = template!(List: &["<alignment in bytes>"]);
279278

280279
fn parse<'c, S: Stage>(
281280
&mut self,

0 commit comments

Comments
 (0)