Skip to content

Commit d8b6aa6

Browse files
committed
Use cfg_attr as a name more.
In various functions where the attribute being processed is known to be a `#[cfg_attr(...)]` attribute. I find this a helpful reminder.
1 parent fee1525 commit d8b6aa6

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

compiler/rustc_expand/src/config.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ impl<'a> StripUnconfigured<'a> {
253253
/// Gives a compiler warning when the `cfg_attr` contains no attributes and
254254
/// is in the original source file. Gives a compiler error if the syntax of
255255
/// the attribute is incorrect.
256-
pub(crate) fn expand_cfg_attr(&self, attr: &Attribute, recursive: bool) -> Vec<Attribute> {
256+
pub(crate) fn expand_cfg_attr(&self, cfg_attr: &Attribute, recursive: bool) -> Vec<Attribute> {
257257
let Some((cfg_predicate, expanded_attrs)) =
258-
rustc_parse::parse_cfg_attr(attr, &self.sess.psess)
258+
rustc_parse::parse_cfg_attr(cfg_attr, &self.sess.psess)
259259
else {
260260
return vec![];
261261
};
@@ -264,7 +264,7 @@ impl<'a> StripUnconfigured<'a> {
264264
if expanded_attrs.is_empty() {
265265
self.sess.psess.buffer_lint(
266266
rustc_lint_defs::builtin::UNUSED_ATTRIBUTES,
267-
attr.span,
267+
cfg_attr.span,
268268
ast::CRATE_NODE_ID,
269269
BuiltinLintDiag::CfgAttrNoAttributes,
270270
);
@@ -280,16 +280,16 @@ impl<'a> StripUnconfigured<'a> {
280280
// `#[cfg_attr(false, cfg_attr(true, some_attr))]`.
281281
expanded_attrs
282282
.into_iter()
283-
.flat_map(|item| self.process_cfg_attr(&self.expand_cfg_attr_item(attr, item)))
283+
.flat_map(|item| self.process_cfg_attr(&self.expand_cfg_attr_item(cfg_attr, item)))
284284
.collect()
285285
} else {
286-
expanded_attrs.into_iter().map(|item| self.expand_cfg_attr_item(attr, item)).collect()
286+
expanded_attrs.into_iter().map(|item| self.expand_cfg_attr_item(cfg_attr, item)).collect()
287287
}
288288
}
289289

290290
fn expand_cfg_attr_item(
291291
&self,
292-
attr: &Attribute,
292+
cfg_attr: &Attribute,
293293
(item, item_span): (ast::AttrItem, Span),
294294
) -> Attribute {
295295
// We are taking an attribute of the form `#[cfg_attr(pred, attr)]`
@@ -300,11 +300,11 @@ impl<'a> StripUnconfigured<'a> {
300300

301301
// Use the `#` in `#[cfg_attr(pred, attr)]` as the `#` token
302302
// for `attr` when we expand it to `#[attr]`
303-
let mut orig_trees = attr.token_trees().into_iter();
303+
let mut orig_trees = cfg_attr.token_trees().into_iter();
304304
let TokenTree::Token(pound_token @ Token { kind: TokenKind::Pound, .. }, _) =
305305
orig_trees.next().unwrap().clone()
306306
else {
307-
panic!("Bad tokens for attribute {attr:?}");
307+
panic!("Bad tokens for attribute {cfg_attr:?}");
308308
};
309309

310310
// We don't really have a good span to use for the synthesized `[]`
@@ -318,12 +318,12 @@ impl<'a> StripUnconfigured<'a> {
318318
.unwrap_or_else(|| panic!("Missing tokens for {item:?}"))
319319
.to_attr_token_stream(),
320320
);
321-
let trees = if attr.style == AttrStyle::Inner {
321+
let trees = if cfg_attr.style == AttrStyle::Inner {
322322
// For inner attributes, we do the same thing for the `!` in `#![some_attr]`
323323
let TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _) =
324324
orig_trees.next().unwrap().clone()
325325
else {
326-
panic!("Bad tokens for attribute {attr:?}");
326+
panic!("Bad tokens for attribute {cfg_attr:?}");
327327
};
328328
vec![
329329
AttrTokenTree::Token(pound_token, Spacing::Joint),
@@ -338,7 +338,7 @@ impl<'a> StripUnconfigured<'a> {
338338
&self.sess.psess.attr_id_generator,
339339
item,
340340
tokens,
341-
attr.style,
341+
cfg_attr.style,
342342
item_span,
343343
);
344344
if attr.has_name(sym::crate_type) {

compiler/rustc_parse/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ pub fn fake_token_stream_for_crate(psess: &ParseSess, krate: &ast::Crate) -> Tok
157157
}
158158

159159
pub fn parse_cfg_attr(
160-
attr: &Attribute,
160+
cfg_attr: &Attribute,
161161
psess: &ParseSess,
162162
) -> Option<(MetaItem, Vec<(AttrItem, Span)>)> {
163163
const CFG_ATTR_GRAMMAR_HELP: &str = "#[cfg_attr(condition, attribute, other_attribute, ...)]";
164164
const CFG_ATTR_NOTE_REF: &str = "for more information, visit \
165165
<https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>";
166166

167-
match attr.get_normal_item().args {
167+
match cfg_attr.get_normal_item().args {
168168
ast::AttrArgs::Delimited(ast::DelimArgs { dspan, delim, ref tokens })
169169
if !tokens.is_empty() =>
170170
{
@@ -180,7 +180,7 @@ pub fn parse_cfg_attr(
180180
}
181181
_ => {
182182
psess.dcx().emit_err(errors::MalformedCfgAttr {
183-
span: attr.span,
183+
span: cfg_attr.span,
184184
sugg: CFG_ATTR_GRAMMAR_HELP,
185185
});
186186
}

0 commit comments

Comments
 (0)