Skip to content

Commit 3a5c4b6

Browse files
committed
Rename some attribute types for consistency.
- `AttributesData` -> `AttrsTarget` - `AttrTokenTree::Attributes` -> `AttrTokenTree::AttrsTarget` - `FlatToken::AttrTarget` -> `FlatToken::AttrsTarget`
1 parent 9d33a8f commit 3a5c4b6

File tree

6 files changed

+42
-44
lines changed

6 files changed

+42
-44
lines changed

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ fn visit_attr_tt<T: MutVisitor>(tt: &mut AttrTokenTree, vis: &mut T) {
704704
visit_attr_tts(tts, vis);
705705
visit_delim_span(dspan, vis);
706706
}
707-
AttrTokenTree::Attributes(AttributesData { attrs, tokens }) => {
707+
AttrTokenTree::AttrsTarget(AttrsTarget { attrs, tokens }) => {
708708
visit_attrs(attrs, vis);
709709
visit_lazy_tts_opt_mut(Some(tokens), vis);
710710
}

compiler/rustc_ast/src/tokenstream.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ pub enum AttrTokenTree {
170170
Delimited(DelimSpan, DelimSpacing, Delimiter, AttrTokenStream),
171171
/// Stores the attributes for an attribute target,
172172
/// along with the tokens for that attribute target.
173-
/// See `AttributesData` for more information
174-
Attributes(AttributesData),
173+
/// See `AttrsTarget` for more information
174+
AttrsTarget(AttrsTarget),
175175
}
176176

177177
impl AttrTokenStream {
@@ -180,7 +180,7 @@ impl AttrTokenStream {
180180
}
181181

182182
/// Converts this `AttrTokenStream` to a plain `Vec<TokenTree>`.
183-
/// During conversion, `AttrTokenTree::Attributes` get 'flattened'
183+
/// During conversion, `AttrTokenTree::AttrsTarget` get 'flattened'
184184
/// back to a `TokenStream` of the form `outer_attr attr_target`.
185185
/// If there are inner attributes, they are inserted into the proper
186186
/// place in the attribute target tokens.
@@ -199,13 +199,13 @@ impl AttrTokenStream {
199199
TokenStream::new(stream.to_token_trees()),
200200
))
201201
}
202-
AttrTokenTree::Attributes(data) => {
203-
let idx = data
202+
AttrTokenTree::AttrsTarget(target) => {
203+
let idx = target
204204
.attrs
205205
.partition_point(|attr| matches!(attr.style, crate::AttrStyle::Outer));
206-
let (outer_attrs, inner_attrs) = data.attrs.split_at(idx);
206+
let (outer_attrs, inner_attrs) = target.attrs.split_at(idx);
207207

208-
let mut target_tokens = data.tokens.to_attr_token_stream().to_token_trees();
208+
let mut target_tokens = target.tokens.to_attr_token_stream().to_token_trees();
209209
if !inner_attrs.is_empty() {
210210
let mut found = false;
211211
// Check the last two trees (to account for a trailing semi)
@@ -262,7 +262,7 @@ impl AttrTokenStream {
262262
/// have an `attrs` field containing the `#[cfg(FALSE)]` attr,
263263
/// and a `tokens` field storing the (unparsed) tokens `struct Foo {}`
264264
#[derive(Clone, Debug, Encodable, Decodable)]
265-
pub struct AttributesData {
265+
pub struct AttrsTarget {
266266
/// Attributes, both outer and inner.
267267
/// These are stored in the original order that they were parsed in.
268268
pub attrs: AttrVec,
@@ -444,9 +444,9 @@ impl TokenStream {
444444
let attr_stream = if attrs.is_empty() {
445445
tokens.to_attr_token_stream()
446446
} else {
447-
let attr_data =
448-
AttributesData { attrs: attrs.iter().cloned().collect(), tokens: tokens.clone() };
449-
AttrTokenStream::new(vec![AttrTokenTree::Attributes(attr_data)])
447+
let target =
448+
AttrsTarget { attrs: attrs.iter().cloned().collect(), tokens: tokens.clone() };
449+
AttrTokenStream::new(vec![AttrTokenTree::AttrsTarget(target)])
450450
};
451451
TokenStream::new(attr_stream.to_token_trees())
452452
}

compiler/rustc_builtin_macros/src/cfg_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl CfgEval<'_> {
193193

194194
// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
195195
// to the captured `AttrTokenStream` (specifically, we capture
196-
// `AttrTokenTree::AttributesData` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
196+
// `AttrTokenTree::AttrsTarget` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
197197
let mut parser = Parser::new(&self.0.sess.psess, orig_tokens, None);
198198
parser.capture_cfg = true;
199199
match parse_annotatable_with(&mut parser) {

compiler/rustc_expand/src/config.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a> StripUnconfigured<'a> {
172172
fn configure_tokens(&self, stream: &AttrTokenStream) -> AttrTokenStream {
173173
fn can_skip(stream: &AttrTokenStream) -> bool {
174174
stream.0.iter().all(|tree| match tree {
175-
AttrTokenTree::Attributes(_) => false,
175+
AttrTokenTree::AttrsTarget(_) => false,
176176
AttrTokenTree::Token(..) => true,
177177
AttrTokenTree::Delimited(.., inner) => can_skip(inner),
178178
})
@@ -186,14 +186,14 @@ impl<'a> StripUnconfigured<'a> {
186186
.0
187187
.iter()
188188
.flat_map(|tree| match tree.clone() {
189-
AttrTokenTree::Attributes(mut data) => {
190-
data.attrs.flat_map_in_place(|attr| self.process_cfg_attr(&attr));
189+
AttrTokenTree::AttrsTarget(mut target) => {
190+
target.attrs.flat_map_in_place(|attr| self.process_cfg_attr(&attr));
191191

192-
if self.in_cfg(&data.attrs) {
193-
data.tokens = LazyAttrTokenStream::new(
194-
self.configure_tokens(&data.tokens.to_attr_token_stream()),
192+
if self.in_cfg(&target.attrs) {
193+
target.tokens = LazyAttrTokenStream::new(
194+
self.configure_tokens(&target.tokens.to_attr_token_stream()),
195195
);
196-
Some(AttrTokenTree::Attributes(data)).into_iter()
196+
Some(AttrTokenTree::AttrsTarget(target)).into_iter()
197197
} else {
198198
None.into_iter()
199199
}

compiler/rustc_parse/src/parser/attr_wrapper.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken};
22
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
3-
use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, AttributesData, DelimSpacing};
3+
use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, AttrsTarget, DelimSpacing};
44
use rustc_ast::tokenstream::{DelimSpan, LazyAttrTokenStream, Spacing, ToAttrTokenStream};
55
use rustc_ast::{self as ast};
66
use rustc_ast::{AttrVec, Attribute, HasAttrs, HasTokens};
@@ -145,22 +145,22 @@ impl ToAttrTokenStream for LazyAttrTokenStreamImpl {
145145
// start position, we ensure that any replace range which encloses
146146
// another replace range will capture the *replaced* tokens for the inner
147147
// range, not the original tokens.
148-
for (range, attr_data) in replace_ranges.into_iter().rev() {
148+
for (range, target) in replace_ranges.into_iter().rev() {
149149
assert!(!range.is_empty(), "Cannot replace an empty range: {range:?}");
150150

151-
// Replace the tokens in range with zero or one `FlatToken::AttrTarget`s, plus
151+
// Replace the tokens in range with zero or one `FlatToken::AttrsTarget`s, plus
152152
// enough `FlatToken::Empty`s to fill up the rest of the range. This keeps the
153153
// total length of `tokens` constant throughout the replacement process, allowing
154154
// us to use all of the `ReplaceRanges` entries without adjusting indices.
155-
let attr_data_len = attr_data.is_some() as usize;
155+
let target_len = target.is_some() as usize;
156156
tokens.splice(
157157
(range.start as usize)..(range.end as usize),
158-
attr_data
158+
target
159159
.into_iter()
160-
.map(|attr_data| (FlatToken::AttrTarget(attr_data), Spacing::Alone))
160+
.map(|target| (FlatToken::AttrsTarget(target), Spacing::Alone))
161161
.chain(
162162
iter::repeat((FlatToken::Empty, Spacing::Alone))
163-
.take(range.len() - attr_data_len),
163+
.take(range.len() - target_len),
164164
),
165165
);
166166
}
@@ -346,13 +346,12 @@ impl<'a> Parser<'a> {
346346
{
347347
assert!(!self.break_last_token, "Should not have unglued last token with cfg attr");
348348

349-
// Replace the entire AST node that we just parsed, including attributes,
350-
// with `attr_data`. If this AST node is inside an item
351-
// that has `#[derive]`, then this will allow us to cfg-expand this
352-
// AST node.
349+
// Replace the entire AST node that we just parsed, including attributes, with
350+
// `target`. If this AST node is inside an item that has `#[derive]`, then this will
351+
// allow us to cfg-expand this AST node.
353352
let start_pos = if has_outer_attrs { attrs.start_pos } else { start_pos };
354-
let attr_data = AttributesData { attrs: final_attrs.iter().cloned().collect(), tokens };
355-
self.capture_state.replace_ranges.push((start_pos..end_pos, Some(attr_data)));
353+
let target = AttrsTarget { attrs: final_attrs.iter().cloned().collect(), tokens };
354+
self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target)));
356355
self.capture_state.replace_ranges.extend(inner_attr_replace_ranges);
357356
}
358357

@@ -414,11 +413,11 @@ fn make_attr_token_stream(
414413
.expect("Bottom token frame is missing!")
415414
.inner
416415
.push(AttrTokenTree::Token(token, spacing)),
417-
FlatToken::AttrTarget(data) => stack
416+
FlatToken::AttrsTarget(target) => stack
418417
.last_mut()
419418
.expect("Bottom token frame is missing!")
420419
.inner
421-
.push(AttrTokenTree::Attributes(data)),
420+
.push(AttrTokenTree::AttrsTarget(target)),
422421
FlatToken::Empty => {}
423422
}
424423
token_and_spacing = iter.next();

compiler/rustc_parse/src/parser/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use path::PathStyle;
2020

2121
use rustc_ast::ptr::P;
2222
use rustc_ast::token::{self, Delimiter, IdentIsRaw, Nonterminal, Token, TokenKind};
23-
use rustc_ast::tokenstream::{AttributesData, DelimSpacing, DelimSpan, Spacing};
23+
use rustc_ast::tokenstream::{AttrsTarget, DelimSpacing, DelimSpan, Spacing};
2424
use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor};
2525
use rustc_ast::util::case::Case;
2626
use rustc_ast::{
@@ -203,13 +203,13 @@ struct ClosureSpans {
203203
}
204204

205205
/// Indicates a range of tokens that should be replaced by
206-
/// the tokens in the provided `AttributesData`. This is used in two
206+
/// the tokens in the provided `AttrsTarget`. This is used in two
207207
/// places during token collection:
208208
///
209209
/// 1. During the parsing of an AST node that may have a `#[derive]`
210210
/// attribute, we parse a nested AST node that has `#[cfg]` or `#[cfg_attr]`
211211
/// In this case, we use a `ReplaceRange` to replace the entire inner AST node
212-
/// with `FlatToken::AttrTarget`, allowing us to perform eager cfg-expansion
212+
/// with `FlatToken::AttrsTarget`, allowing us to perform eager cfg-expansion
213213
/// on an `AttrTokenStream`.
214214
///
215215
/// 2. When we parse an inner attribute while collecting tokens. We
@@ -219,7 +219,7 @@ struct ClosureSpans {
219219
/// the first macro inner attribute to invoke a proc-macro).
220220
/// When create a `TokenStream`, the inner attributes get inserted
221221
/// into the proper place in the token stream.
222-
type ReplaceRange = (Range<u32>, Option<AttributesData>);
222+
type ReplaceRange = (Range<u32>, Option<AttrsTarget>);
223223

224224
/// Controls how we capture tokens. Capturing can be expensive,
225225
/// so we try to avoid performing capturing in cases where
@@ -1608,11 +1608,10 @@ enum FlatToken {
16081608
/// A token - this holds both delimiter (e.g. '{' and '}')
16091609
/// and non-delimiter tokens
16101610
Token(Token),
1611-
/// Holds the `AttributesData` for an AST node. The
1612-
/// `AttributesData` is inserted directly into the
1613-
/// constructed `AttrTokenStream` as
1614-
/// an `AttrTokenTree::Attributes`.
1615-
AttrTarget(AttributesData),
1611+
/// Holds the `AttrsTarget` for an AST node. The `AttrsTarget` is inserted
1612+
/// directly into the constructed `AttrTokenStream` as an
1613+
/// `AttrTokenTree::AttrsTarget`.
1614+
AttrsTarget(AttrsTarget),
16161615
/// A special 'empty' token that is ignored during the conversion
16171616
/// to an `AttrTokenStream`. This is used to simplify the
16181617
/// handling of replace ranges.

0 commit comments

Comments
 (0)