Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5a3ac64

Browse files
committedJan 19, 2025
renamings
1 parent 6bb3b1f commit 5a3ac64

File tree

17 files changed

+272
-245
lines changed

17 files changed

+272
-245
lines changed
 

‎,

-1
This file was deleted.

‎compiler/rustc_ast_lowering/src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
use rustc_ast::node_id::NodeMap;
4545
use rustc_ast::{self as ast, *};
46-
use rustc_attr_parsing::{AttributeParseContext, OmitDoc};
46+
use rustc_attr_parsing::{AttributeParser, OmitDoc};
4747
use rustc_data_structures::captures::Captures;
4848
use rustc_data_structures::fingerprint::Fingerprint;
4949
use rustc_data_structures::sorted_map::SortedMap;
@@ -60,7 +60,8 @@ use rustc_macros::extension;
6060
use rustc_middle::span_bug;
6161
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
6262
use rustc_session::parse::{add_feature_diagnostics, feature_err};
63-
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym};
63+
use rustc_span::symbol::{Ident, Symbol, kw, sym};
64+
use rustc_span::{DUMMY_SP, DesugaringKind, Span};
6465
use smallvec::{SmallVec, smallvec};
6566
use thin_vec::ThinVec;
6667
use tracing::{debug, instrument, trace};
@@ -135,7 +136,7 @@ struct LoweringContext<'a, 'hir> {
135136
allow_for_await: Lrc<[Symbol]>,
136137
allow_async_fn_traits: Lrc<[Symbol]>,
137138

138-
attribute_parse_context: AttributeParseContext<'hir>,
139+
attribute_parse_context: AttributeParser<'hir>,
139140
}
140141

141142
impl<'a, 'hir> LoweringContext<'a, 'hir> {
@@ -181,7 +182,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
181182
// interact with `gen`/`async gen` blocks
182183
allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),
183184

184-
attribute_parse_context: AttributeParseContext::new(
185+
attribute_parse_context: AttributeParser::new(
185186
tcx.sess,
186187
tcx.features(),
187188
registered_tools,
@@ -1995,17 +1996,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19951996
fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
19961997
match c.value.kind {
19971998
ExprKind::Underscore => {
1998-
if !self.tcx.features().generic_arg_infer() {
1999+
if self.tcx.features().generic_arg_infer() {
2000+
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span));
2001+
self.arena
2002+
.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
2003+
} else {
19992004
feature_err(
20002005
&self.tcx.sess,
20012006
sym::generic_arg_infer,
20022007
c.value.span,
20032008
fluent_generated::ast_lowering_underscore_array_length_unstable,
20042009
)
20052010
.stash(c.value.span, StashKey::UnderscoreForArrayLengths);
2011+
self.lower_anon_const_to_const_arg(c)
20062012
}
2007-
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span));
2008-
self.arena.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
20092013
}
20102014
_ => self.lower_anon_const_to_const_arg(c),
20112015
}

‎compiler/rustc_attr_data_structures/src/attributes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ impl Deprecation {
126126
}
127127
}
128128

129-
// TODO: improve these docs
130129
/// Attributes represent parsed, *built in* attributes. That means,
131130
/// attributes that are not actually ever expanded. They're instead used as markers,
132131
/// to guide the compilation process in various way in most every stage of the compiler.

‎compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@ use std::iter;
33
use rustc_attr_data_structures::AttributeKind;
44
use rustc_span::{Span, Symbol, sym};
55

6-
use super::{CombineAttributeGroup, ConvertFn};
7-
use crate::context::AttributeAcceptContext;
6+
use super::{CombineAttributeParser, ConvertFn};
7+
use crate::context::AcceptContext;
88
use crate::parser::ArgParser;
99
use crate::session_diagnostics;
1010

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

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

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

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

3939
fn parse_unstable<'a>(
40-
cx: &AttributeAcceptContext<'_>,
40+
cx: &AcceptContext<'_>,
4141
args: &'a ArgParser<'a>,
4242
symbol: Symbol,
4343
) -> impl IntoIterator<Item = Symbol> {

‎compiler/rustc_attr_parsing/src/attributes/confusables.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ use rustc_attr_data_structures::AttributeKind;
22
use rustc_span::{Span, Symbol, sym};
33
use thin_vec::ThinVec;
44

5-
use super::{AttributeGroup, AttributeMapping};
6-
use crate::context::AttributeGroupContext;
5+
use super::{AcceptMapping, AttributeParser};
6+
use crate::context::FinalizeContext;
77
use crate::session_diagnostics;
88

9-
// TODO: turn into CombineGroup?
109
#[derive(Default)]
11-
pub(crate) struct ConfusablesGroup {
10+
pub(crate) struct ConfusablesParser {
1211
confusables: ThinVec<Symbol>,
1312
first_span: Option<Span>,
1413
}
1514

16-
impl AttributeGroup for ConfusablesGroup {
17-
const ATTRIBUTES: AttributeMapping<Self> = &[(&[sym::rustc_confusables], |this, cx, args| {
15+
impl AttributeParser for ConfusablesParser {
16+
const ATTRIBUTES: AcceptMapping<Self> = &[(&[sym::rustc_confusables], |this, cx, args| {
1817
let Some(list) = args.list() else {
1918
// FIXME(jdonszelmann): error when not a list? Bring validation code here.
2019
// NOTE: currently subsequent attributes are silently ignored using
@@ -46,7 +45,7 @@ impl AttributeGroup for ConfusablesGroup {
4645
this.first_span.get_or_insert(cx.attr_span);
4746
})];
4847

49-
fn finalize(self, _cx: &AttributeGroupContext<'_>) -> Option<AttributeKind> {
48+
fn finalize(self, _cx: &FinalizeContext<'_>) -> Option<AttributeKind> {
5049
if self.confusables.is_empty() {
5150
return None;
5251
}

‎compiler/rustc_attr_parsing/src/attributes/deprecation.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ use rustc_attr_data_structures::{AttributeKind, DeprecatedSince, Deprecation};
22
use rustc_span::symbol::Ident;
33
use rustc_span::{Span, Symbol, sym};
44

5-
use super::SingleAttributeGroup;
5+
use super::SingleAttributeParser;
66
use super::util::parse_version;
7-
use crate::context::AttributeAcceptContext;
7+
use crate::context::AcceptContext;
88
use crate::parser::ArgParser;
99
use crate::session_diagnostics;
1010
use crate::session_diagnostics::UnsupportedLiteralReason;
1111

12-
pub(crate) struct DeprecationGroup;
12+
pub(crate) struct DeprecationParser;
1313

1414
fn get(
15-
cx: &AttributeAcceptContext<'_>,
15+
cx: &AcceptContext<'_>,
1616
ident: Ident,
1717
param_span: Span,
1818
arg: &ArgParser<'_>,
@@ -46,10 +46,10 @@ fn get(
4646
}
4747
}
4848

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

52-
fn on_duplicate(cx: &AttributeAcceptContext<'_>, first_span: rustc_span::Span) {
52+
fn on_duplicate(cx: &AcceptContext<'_>, first_span: rustc_span::Span) {
5353
// FIXME(jdonszelmann): merge with errors from check_attrs.rs
5454
cx.emit_err(session_diagnostics::UnusedMultiple {
5555
this: cx.attr_span,
@@ -58,7 +58,7 @@ impl SingleAttributeGroup for DeprecationGroup {
5858
});
5959
}
6060

61-
fn convert(cx: &AttributeAcceptContext<'_>, args: &ArgParser<'_>) -> Option<AttributeKind> {
61+
fn convert(cx: &AcceptContext<'_>, args: &ArgParser<'_>) -> Option<AttributeKind> {
6262
let features = cx.features();
6363

6464
let mut since = None;
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
//! [`AttributeGroup`]s are groups of attributes (groups can be size 1) that are parsed together.
2-
//! An [`AttributeGroup`] implementation defines its parser.
3-
//!
4-
//! You can find more docs on what groups are on [`AttributeGroup`] itself.
5-
//! However, for many types of attributes, implementing [`AttributeGroup`] is not necessary.
1+
//! You can find more docs on what groups are on [`AttributeParser`] itself.
2+
//! However, for many types of attributes, implementing [`AttributeParser`] is not necessary.
63
//! It allows for a lot of flexibility you might not want.
74
//!
8-
//! Specifically, you care about managing the state of your [AttributeGroup] state machine
9-
//! yourself. In this case you can choose to implement:
5+
//! Specifically, you might not care about managing the state of your [`AttributeParser`]
6+
//! state machine yourself. In this case you can choose to implement:
107
//!
11-
//! - [`SingleAttributeGroup`]: makes it easy to implement an attribute which should error if it
8+
//! - [`SingleAttributeParser`]: makes it easy to implement an attribute which should error if it
129
//! appears more than once in a list of attributes
13-
//! - [`CombineAttributeGroup`]: makes it easy to implement an attribute which should combine the
10+
//! - [`CombineAttributeParser`]: makes it easy to implement an attribute which should combine the
1411
//! contents of attributes, if an attribute appear multiple times in a list
1512
//!
1613
//! Attributes should be added to [`ATTRIBUTE_GROUP_MAPPING`](crate::context::ATTRIBUTE_GROUP_MAPPING) to be parsed.
@@ -21,7 +18,7 @@ use rustc_attr_data_structures::AttributeKind;
2118
use rustc_span::Span;
2219
use thin_vec::ThinVec;
2320

24-
use crate::context::{AttributeAcceptContext, AttributeGroupContext};
21+
use crate::context::{AcceptContext, FinalizeContext};
2522
use crate::parser::ArgParser;
2623

2724
pub(crate) mod allow_unstable;
@@ -33,60 +30,68 @@ pub(crate) mod stability;
3330
pub(crate) mod transparency;
3431
pub(crate) mod util;
3532

36-
type AttributeHandler<T> = fn(&mut T, &AttributeAcceptContext<'_>, &ArgParser<'_>);
37-
type AttributeMapping<T> = &'static [(&'static [rustc_span::Symbol], AttributeHandler<T>)];
33+
type AcceptFn<T> = fn(&mut T, &AcceptContext<'_>, &ArgParser<'_>);
34+
type AcceptMapping<T> = &'static [(&'static [rustc_span::Symbol], AcceptFn<T>)];
3835

39-
/// An [`AttributeGroup`] is a type which searches for syntactic attributes.
36+
/// An [`AttributeParser`] is a type which searches for syntactic attributes.
4037
///
41-
/// Groups are often tiny state machines. [`Default::default`]
42-
/// creates a new instance that sits in some kind of initial state, usually that the
38+
/// Parsers are often tiny state machines that gets to see all syntactical attributes on an item.
39+
/// [`Default::default`] creates a fresh instance that sits in some kind of initial state, usually that the
4340
/// attribute it is looking for was not yet seen.
4441
///
45-
/// Then, it defines what paths this group will accept in [`AttributeGroup::ATTRIBUTES`].
42+
/// Then, it defines what paths this group will accept in [`AttributeParser::ATTRIBUTES`].
4643
/// These are listed as pairs, of symbols and function pointers. The function pointer will
47-
/// be called when that attribute is found on an item, which can influence the state.
44+
/// be called when that attribute is found on an item, which can influence the state of the little
45+
/// state machine.
46+
///
47+
/// Finally, after all attributes on an item have been seen, and possibly been accepted,
48+
/// the [`finalize`](AttributeParser::finalize) functions for all attribute parsers are called. Each can then report
49+
/// whether it has seen the attribute it has been looking for.
4850
///
49-
/// Finally, all `finalize` functions are called, for each piece of state,
50-
pub(crate) trait AttributeGroup: Default + 'static {
51-
/// The symbols for the attributes that this extractor can extract.
51+
/// The state machine is automatically reset to parse attributes on the next item.
52+
pub(crate) trait AttributeParser: Default + 'static {
53+
/// The symbols for the attributes that this parser is interested in.
5254
///
5355
/// If an attribute has this symbol, the `accept` function will be called on it.
54-
const ATTRIBUTES: AttributeMapping<Self>;
56+
const ATTRIBUTES: AcceptMapping<Self>;
5557

56-
/// The extractor has gotten a chance to accept the attributes on an item,
57-
/// now produce an attribute.
58-
fn finalize(self, cx: &AttributeGroupContext<'_>) -> Option<AttributeKind>;
58+
/// The parser has gotten a chance to accept the attributes on an item,
59+
/// here it can produce an attribute.
60+
fn finalize(self, cx: &FinalizeContext<'_>) -> Option<AttributeKind>;
5961
}
6062

61-
/// A slightly simpler and more restricted way to convert attributes which you can implement for
62-
/// unit types. Assumes that a single attribute can only appear a single time on an item
63-
/// [`SingleGroup<T> where T: SingleAttributeGroup`](Single) creates an [`AttributeGroup`] from any [`SingleAttributeGroup`].
63+
/// Alternative to [`AttributeParser`] that automatically handles state management.
64+
/// A slightly simpler and more restricted way to convert attributes.
65+
/// Assumes that an attribute can only appear a single time on an item,
66+
/// and errors when it sees more.
67+
///
68+
/// [`Single<T> where T: SingleAttributeParser`](Single) implements [`AttributeParser`].
6469
///
65-
/// [`SingleGroup`] can only convert attributes one-to-one, and cannot combine multiple
70+
/// [`SingleAttributeParser`] can only convert attributes one-to-one, and cannot combine multiple
6671
/// attributes together like is necessary for `#[stable()]` and `#[unstable()]` for example.
67-
pub(crate) trait SingleAttributeGroup: 'static {
72+
pub(crate) trait SingleAttributeParser: 'static {
6873
const PATH: &'static [rustc_span::Symbol];
6974

7075
/// Caled when a duplicate attribute is found.
7176
///
7277
/// `first_span` is the span of the first occurrence of this attribute.
73-
fn on_duplicate(cx: &AttributeAcceptContext<'_>, first_span: Span);
78+
// FIXME(jdonszelmann): default error
79+
fn on_duplicate(cx: &AcceptContext<'_>, first_span: Span);
7480

75-
/// The extractor has gotten a chance to accept the attributes on an item,
76-
/// now produce an attribute.
77-
fn convert(cx: &AttributeAcceptContext<'_>, args: &ArgParser<'_>) -> Option<AttributeKind>;
81+
/// Converts a single syntactical attribute to a single semantic attribute, or [`AttributeKind`]
82+
fn convert(cx: &AcceptContext<'_>, args: &ArgParser<'_>) -> Option<AttributeKind>;
7883
}
7984

80-
pub(crate) struct Single<T: SingleAttributeGroup>(PhantomData<T>, Option<(AttributeKind, Span)>);
85+
pub(crate) struct Single<T: SingleAttributeParser>(PhantomData<T>, Option<(AttributeKind, Span)>);
8186

82-
impl<T: SingleAttributeGroup> Default for Single<T> {
87+
impl<T: SingleAttributeParser> Default for Single<T> {
8388
fn default() -> Self {
8489
Self(Default::default(), Default::default())
8590
}
8691
}
8792

88-
impl<T: SingleAttributeGroup> AttributeGroup for Single<T> {
89-
const ATTRIBUTES: AttributeMapping<Self> = &[(T::PATH, |group: &mut Single<T>, cx, args| {
93+
impl<T: SingleAttributeParser> AttributeParser for Single<T> {
94+
const ATTRIBUTES: AcceptMapping<Self> = &[(T::PATH, |group: &mut Single<T>, cx, args| {
9095
if let Some((_, s)) = group.1 {
9196
T::on_duplicate(cx, s);
9297
return;
@@ -97,50 +102,49 @@ impl<T: SingleAttributeGroup> AttributeGroup for Single<T> {
97102
}
98103
})];
99104

100-
fn finalize(self, _cx: &AttributeGroupContext<'_>) -> Option<AttributeKind> {
105+
fn finalize(self, _cx: &FinalizeContext<'_>) -> Option<AttributeKind> {
101106
Some(self.1?.0)
102107
}
103108
}
104109

105110
type ConvertFn<E> = fn(ThinVec<E>) -> AttributeKind;
106111

107-
/// A slightly simpler and more restricted way to convert attributes which you can implement for
108-
/// unit types. If multiple attributes appear on an element, combines the values of each into a
112+
/// Alternative to [`AttributeParser`] that automatically handles state management.
113+
/// If multiple attributes appear on an element, combines the values of each into a
109114
/// [`ThinVec`].
110-
/// [`CombineGroup<T> where T: CombineAttributeGroup`](Combine) creates an [`AttributeGroup`] from any [`CombineAttributeGroup`].
115+
/// [`Combine<T> where T: CombineAttributeParser`](Combine) implements [`AttributeParser`].
111116
///
112-
/// [`CombineAttributeGroup`] can only convert a single kind of attribute, and cannot combine multiple
117+
/// [`CombineAttributeParser`] can only convert a single kind of attribute, and cannot combine multiple
113118
/// attributes together like is necessary for `#[stable()]` and `#[unstable()]` for example.
114-
pub(crate) trait CombineAttributeGroup: 'static {
119+
pub(crate) trait CombineAttributeParser: 'static {
115120
const PATH: &'static [rustc_span::Symbol];
116121

117122
type Item;
118123
const CONVERT: ConvertFn<Self::Item>;
119124

120-
/// The extractor has gotten a chance to accept the attributes on an item,
121-
/// now produce an attribute.
125+
/// Converts a single syntactical attribute to a number of elements of the semantic attribute, or [`AttributeKind`]
122126
fn extend<'a>(
123-
cx: &'a AttributeAcceptContext<'a>,
127+
cx: &'a AcceptContext<'a>,
124128
args: &'a ArgParser<'a>,
125129
) -> impl IntoIterator<Item = Self::Item> + 'a;
126130
}
127131

128-
pub(crate) struct Combine<T: CombineAttributeGroup>(
132+
pub(crate) struct Combine<T: CombineAttributeParser>(
129133
PhantomData<T>,
130-
ThinVec<<T as CombineAttributeGroup>::Item>,
134+
ThinVec<<T as CombineAttributeParser>::Item>,
131135
);
132136

133-
impl<T: CombineAttributeGroup> Default for Combine<T> {
137+
impl<T: CombineAttributeParser> Default for Combine<T> {
134138
fn default() -> Self {
135139
Self(Default::default(), Default::default())
136140
}
137141
}
138142

139-
impl<T: CombineAttributeGroup> AttributeGroup for Combine<T> {
140-
const ATTRIBUTES: AttributeMapping<Self> =
143+
impl<T: CombineAttributeParser> AttributeParser for Combine<T> {
144+
const ATTRIBUTES: AcceptMapping<Self> =
141145
&[(T::PATH, |group: &mut Combine<T>, cx, args| group.1.extend(T::extend(cx, args)))];
142146

143-
fn finalize(self, _cx: &AttributeGroupContext<'_>) -> Option<AttributeKind> {
147+
fn finalize(self, _cx: &FinalizeContext<'_>) -> Option<AttributeKind> {
144148
if self.1.is_empty() { None } else { Some(T::CONVERT(self.1)) }
145149
}
146150
}
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.