Skip to content

Commit adccb8d

Browse files
committed
Rework NameValueStr
1 parent 32ee26c commit adccb8d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

compiler/rustc_attr_parsing/src/attributes/transparency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<S: Stage> SingleAttributeParser<S> for TransparencyParser {
1919
cx.dcx().span_err(vec![used, unused], "multiple macro transparency attributes");
2020
});
2121
const TEMPLATE: AttributeTemplate =
22-
template!(NameValueStr: "transparent|semitransparent|opaque");
22+
template!(NameValueStr: ["transparent", "semitransparent", "opaque"]);
2323

2424
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
2525
let Some(nv) = args.name_value() else {

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ macro_rules! template {
216216
(List: $descr: expr) => { $crate::template!(@ false, Some($descr), &[], None, None) };
217217
(List: $descr: expr, $link: literal) => { $crate::template!(@ false, Some($descr), &[], None, Some($link)) };
218218
(OneOf: $one_of: expr) => { $crate::template!(@ false, None, $one_of, None, None) };
219-
(NameValueStr: $descr: expr) => { $crate::template!(@ false, None, &[], Some(&[$descr]), None) };
220-
(NameValueStr: $descr: expr, $link: literal) => { $crate::template!(@ false, None, &[], Some(&[$descr]), Some($link)) };
221-
(OneOfNameValueStr: $descr: expr) => { $crate::template!(@ false, None, &[], Some($descr), None) };
222-
(OneOfNameValueStr: $descr: expr, $link: literal) => { $crate::template!(@ false, None, &[], Some($descr), Some($link)) };
219+
(NameValueStr: [$($descr: literal),* $(,)?]) => { $crate::template!(@ false, None, &[], Some(&[$($descr,)*]), None) };
220+
(NameValueStr: [$($descr: literal),* $(,)?], $link: literal) => { $crate::template!(@ false, None, &[], Some(&[$($descr,)*]), Some($link)) };
221+
(NameValueStr: $descr: literal) => { $crate::template!(@ false, None, &[], Some(&[$descr]), None) };
222+
(NameValueStr: $descr: literal, $link: literal) => { $crate::template!(@ false, None, &[], Some(&[$descr]), Some($link)) };
223223
(Word, List: $descr: expr) => { $crate::template!(@ true, Some($descr), &[], None, None) };
224224
(Word, List: $descr: expr, $link: literal) => { $crate::template!(@ true, Some($descr), &[], None, Some($link)) };
225225
(Word, NameValueStr: $descr: expr) => { $crate::template!(@ true, None, &[], Some(&[$descr]), None) };
@@ -579,7 +579,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
579579
ungated!(
580580
crate_type, CrateLevel,
581581
template!(
582-
OneOfNameValueStr: &["bin", "lib", "dylib", "cdylib", "rlib", "staticlib", "sdylib", "proc-macro"],
582+
NameValueStr: ["bin", "lib", "dylib", "cdylib", "rlib", "staticlib", "sdylib", "proc-macro"],
583583
"https://doc.rust-lang.org/reference/linkage.html"
584584
),
585585
DuplicatesOk, EncodeCrossCrate::No,
@@ -696,7 +696,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
696696
// Runtime
697697
ungated!(
698698
windows_subsystem, CrateLevel,
699-
template!(OneOfNameValueStr: &["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute"),
699+
template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute"),
700700
FutureWarnFollowing, EncodeCrossCrate::No
701701
),
702702
ungated!( // RFC 2070
@@ -1027,7 +1027,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
10271027
// ==========================================================================
10281028

10291029
gated!(
1030-
linkage, Normal, template!(OneOfNameValueStr: &[
1030+
linkage, Normal, template!(NameValueStr: [
10311031
"available_externally",
10321032
"common",
10331033
"extern_weak",
@@ -1061,7 +1061,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
10611061
),
10621062
rustc_attr!(
10631063
rustc_macro_transparency, Normal,
1064-
template!(OneOfNameValueStr: &["transparent", "semiopaque", "opaque"]), ErrorFollowing,
1064+
template!(NameValueStr: ["transparent", "semiopaque", "opaque"]), ErrorFollowing,
10651065
EncodeCrossCrate::Yes, "used internally for testing macro hygiene",
10661066
),
10671067
rustc_attr!(

0 commit comments

Comments
 (0)