Skip to content

Commit 92be9b0

Browse files
committed
Simplify Accepts, part 1.
Every slice of symbols has a single entry. Let's just use a symbol directly.
1 parent ce7cdf2 commit 92be9b0

File tree

8 files changed

+27
-25
lines changed

8 files changed

+27
-25
lines changed

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ use crate::session_diagnostics;
1010

1111
pub(crate) struct AllowInternalUnstableParser;
1212
impl CombineAttributeParser for AllowInternalUnstableParser {
13-
const PATH: &'static [rustc_span::Symbol] = &[sym::allow_internal_unstable];
13+
const PATH: Symbol = sym::allow_internal_unstable;
1414
type Item = (Symbol, Span);
1515
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowInternalUnstable;
1616

1717
fn extend<'a>(
1818
cx: &'a AcceptContext<'a>,
1919
args: &'a ArgParser<'a>,
2020
) -> impl IntoIterator<Item = Self::Item> + 'a {
21-
parse_unstable(cx, args, Self::PATH[0]).into_iter().zip(iter::repeat(cx.attr_span))
21+
parse_unstable(cx, args, Self::PATH).into_iter().zip(iter::repeat(cx.attr_span))
2222
}
2323
}
2424

2525
pub(crate) struct AllowConstFnUnstableParser;
2626
impl CombineAttributeParser for AllowConstFnUnstableParser {
27-
const PATH: &'static [rustc_span::Symbol] = &[sym::rustc_allow_const_fn_unstable];
27+
const PATH: Symbol = sym::rustc_allow_const_fn_unstable;
2828
type Item = Symbol;
2929
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowConstFnUnstable;
3030

3131
fn extend<'a>(
3232
cx: &'a AcceptContext<'a>,
3333
args: &'a ArgParser<'a>,
3434
) -> impl IntoIterator<Item = Self::Item> + 'a {
35-
parse_unstable(cx, args, Self::PATH[0])
35+
parse_unstable(cx, args, Self::PATH)
3636
}
3737
}
3838

compiler/rustc_attr_parsing/src/attributes/confusables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) struct ConfusablesParser {
1313
}
1414

1515
impl AttributeParser for ConfusablesParser {
16-
const ATTRIBUTES: AcceptMapping<Self> = &[(&[sym::rustc_confusables], |this, cx, args| {
16+
const ATTRIBUTES: AcceptMapping<Self> = &[(sym::rustc_confusables, |this, cx, args| {
1717
let Some(list) = args.list() else {
1818
// FIXME(jdonszelmann): error when not a list? Bring validation code here.
1919
// NOTE: currently subsequent attributes are silently ignored using

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ fn get(
4646
}
4747

4848
impl SingleAttributeParser for DeprecationParser {
49-
const PATH: &'static [rustc_span::Symbol] = &[sym::deprecated];
49+
const PATH: Symbol = sym::deprecated;
5050

51-
fn on_duplicate(cx: &AcceptContext<'_>, first_span: rustc_span::Span) {
51+
fn on_duplicate(cx: &AcceptContext<'_>, first_span: Span) {
5252
// FIXME(jdonszelmann): merge with errors from check_attrs.rs
5353
cx.emit_err(session_diagnostics::UnusedMultiple {
5454
this: cx.attr_span,

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use std::marker::PhantomData;
1818

1919
use rustc_attr_data_structures::AttributeKind;
20-
use rustc_span::Span;
20+
use rustc_span::{Span, Symbol};
2121
use thin_vec::ThinVec;
2222

2323
use crate::context::{AcceptContext, FinalizeContext};
@@ -33,7 +33,7 @@ pub(crate) mod transparency;
3333
pub(crate) mod util;
3434

3535
type AcceptFn<T> = fn(&mut T, &AcceptContext<'_>, &ArgParser<'_>);
36-
type AcceptMapping<T> = &'static [(&'static [rustc_span::Symbol], AcceptFn<T>)];
36+
type AcceptMapping<T> = &'static [(Symbol, AcceptFn<T>)];
3737

3838
/// An [`AttributeParser`] is a type which searches for syntactic attributes.
3939
///
@@ -72,7 +72,7 @@ pub(crate) trait AttributeParser: Default + 'static {
7272
/// [`SingleAttributeParser`] can only convert attributes one-to-one, and cannot combine multiple
7373
/// attributes together like is necessary for `#[stable()]` and `#[unstable()]` for example.
7474
pub(crate) trait SingleAttributeParser: 'static {
75-
const PATH: &'static [rustc_span::Symbol];
75+
const PATH: Symbol;
7676

7777
/// Caled when a duplicate attribute is found.
7878
///
@@ -119,7 +119,7 @@ type ConvertFn<E> = fn(ThinVec<E>) -> AttributeKind;
119119
/// [`CombineAttributeParser`] can only convert a single kind of attribute, and cannot combine multiple
120120
/// attributes together like is necessary for `#[stable()]` and `#[unstable()]` for example.
121121
pub(crate) trait CombineAttributeParser: 'static {
122-
const PATH: &'static [rustc_span::Symbol];
122+
const PATH: Symbol;
123123

124124
type Item;
125125
const CONVERT: ConvertFn<Self::Item>;

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) struct ReprParser;
2121

2222
impl CombineAttributeParser for ReprParser {
2323
type Item = (ReprAttr, Span);
24-
const PATH: &'static [rustc_span::Symbol] = &[sym::repr];
24+
const PATH: Symbol = sym::repr;
2525
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Repr;
2626

2727
fn extend<'a>(

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@ impl StabilityParser {
4343

4444
impl AttributeParser for StabilityParser {
4545
const ATTRIBUTES: AcceptMapping<Self> = &[
46-
(&[sym::stable], |this, cx, args| {
46+
(sym::stable, |this, cx, args| {
4747
reject_outside_std!(cx);
4848
if !this.check_duplicate(cx)
4949
&& let Some((feature, level)) = parse_stability(cx, args)
5050
{
5151
this.stability = Some((Stability { level, feature }, cx.attr_span));
5252
}
5353
}),
54-
(&[sym::unstable], |this, cx, args| {
54+
(sym::unstable, |this, cx, args| {
5555
reject_outside_std!(cx);
5656
if !this.check_duplicate(cx)
5757
&& let Some((feature, level)) = parse_unstability(cx, args)
5858
{
5959
this.stability = Some((Stability { level, feature }, cx.attr_span));
6060
}
6161
}),
62-
(&[sym::rustc_allowed_through_unstable_modules], |this, cx, args| {
62+
(sym::rustc_allowed_through_unstable_modules, |this, cx, args| {
6363
reject_outside_std!(cx);
6464
this.allowed_through_unstable_modules = args.name_value().and_then(|i| i.value_as_str())
6565
}),
@@ -97,7 +97,7 @@ pub(crate) struct BodyStabilityParser {
9797

9898
impl AttributeParser for BodyStabilityParser {
9999
const ATTRIBUTES: AcceptMapping<Self> =
100-
&[(&[sym::rustc_default_body_unstable], |this, cx, args| {
100+
&[(sym::rustc_default_body_unstable, |this, cx, args| {
101101
reject_outside_std!(cx);
102102
if this.stability.is_some() {
103103
cx.dcx()
@@ -117,7 +117,7 @@ impl AttributeParser for BodyStabilityParser {
117117
pub(crate) struct ConstStabilityIndirectParser;
118118
// FIXME(jdonszelmann): single word attribute group when we have these
119119
impl SingleAttributeParser for ConstStabilityIndirectParser {
120-
const PATH: &'static [rustc_span::Symbol] = &[sym::rustc_const_stable_indirect];
120+
const PATH: Symbol = sym::rustc_const_stable_indirect;
121121

122122
// ignore
123123
fn on_duplicate(_cx: &AcceptContext<'_>, _first_span: Span) {}
@@ -147,7 +147,7 @@ impl ConstStabilityParser {
147147

148148
impl AttributeParser for ConstStabilityParser {
149149
const ATTRIBUTES: AcceptMapping<Self> = &[
150-
(&[sym::rustc_const_stable], |this, cx, args| {
150+
(sym::rustc_const_stable, |this, cx, args| {
151151
reject_outside_std!(cx);
152152

153153
if !this.check_duplicate(cx)
@@ -159,7 +159,7 @@ impl AttributeParser for ConstStabilityParser {
159159
));
160160
}
161161
}),
162-
(&[sym::rustc_const_unstable], |this, cx, args| {
162+
(sym::rustc_const_unstable, |this, cx, args| {
163163
reject_outside_std!(cx);
164164
if !this.check_duplicate(cx)
165165
&& let Some((feature, level)) = parse_unstability(cx, args)
@@ -170,7 +170,7 @@ impl AttributeParser for ConstStabilityParser {
170170
));
171171
}
172172
}),
173-
(&[sym::rustc_promotable], |this, cx, _| {
173+
(sym::rustc_promotable, |this, cx, _| {
174174
reject_outside_std!(cx);
175175
this.promotable = true;
176176
}),

compiler/rustc_attr_parsing/src/attributes/transparency.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_attr_data_structures::AttributeKind;
22
use rustc_span::hygiene::Transparency;
3-
use rustc_span::sym;
3+
use rustc_span::{Span, Symbol, sym};
44

55
use super::{AcceptContext, SingleAttributeParser};
66
use crate::parser::ArgParser;
@@ -11,9 +11,9 @@ pub(crate) struct TransparencyParser;
1111
#[allow(rustc::untranslatable_diagnostic)]
1212
#[allow(rustc::diagnostic_outside_of_impl)]
1313
impl SingleAttributeParser for TransparencyParser {
14-
const PATH: &'static [rustc_span::Symbol] = &[sym::rustc_macro_transparency];
14+
const PATH: Symbol = sym::rustc_macro_transparency;
1515

16-
fn on_duplicate(cx: &crate::context::AcceptContext<'_>, first_span: rustc_span::Span) {
16+
fn on_duplicate(cx: &crate::context::AcceptContext<'_>, first_span: Span) {
1717
cx.dcx().span_err(vec![first_span, cx.attr_span], "multiple macro transparency attributes");
1818
}
1919

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ macro_rules! attribute_groups {
2727
pub(crate) static $name: ident = [$($names: ty),* $(,)?];
2828
) => {
2929
type Accepts = BTreeMap<
30-
&'static [Symbol],
30+
Symbol,
3131
Vec<Box<dyn Send + Sync + Fn(&AcceptContext<'_>, &ArgParser<'_>)>>
3232
>;
3333
type Finalizes = Vec<
@@ -267,7 +267,9 @@ impl<'sess> AttributeParser<'sess> {
267267
let (path, args) = parser.deconstruct();
268268
let parts = path.segments().map(|i| i.name).collect::<Vec<_>>();
269269

270-
if let Some(accepts) = ATTRIBUTE_MAPPING.0.get(parts.as_slice()) {
270+
if let [part] = &parts[..]
271+
&& let Some(accepts) = ATTRIBUTE_MAPPING.0.get(part)
272+
{
271273
for f in accepts {
272274
let cx = AcceptContext {
273275
group_cx: &group_cx,

0 commit comments

Comments
 (0)