Skip to content

Commit 778321d

Browse files
committed
Change AttrArgs::Eq into a struct variant
1 parent caa8172 commit 778321d

File tree

16 files changed

+43
-39
lines changed

16 files changed

+43
-39
lines changed

compiler/rustc_ast/src/ast.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1733,12 +1733,12 @@ pub enum AttrArgs {
17331733
/// Delimited arguments: `#[attr()/[]/{}]`.
17341734
Delimited(DelimArgs),
17351735
/// Arguments of a key-value attribute: `#[attr = "value"]`.
1736-
Eq(
1736+
Eq {
17371737
/// Span of the `=` token.
1738-
Span,
1739-
/// The "value".
1740-
AttrArgsEq,
1741-
),
1738+
eq_span: Span,
1739+
1740+
value: AttrArgsEq,
1741+
},
17421742
}
17431743

17441744
// The RHS of an `AttrArgs::Eq` starts out as an expression. Once macro
@@ -1755,8 +1755,8 @@ impl AttrArgs {
17551755
match self {
17561756
AttrArgs::Empty => None,
17571757
AttrArgs::Delimited(args) => Some(args.dspan.entire()),
1758-
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => Some(eq_span.to(expr.span)),
1759-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
1758+
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(expr) } => Some(eq_span.to(expr.span)),
1759+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
17601760
unreachable!("in literal form when getting span: {:?}", lit);
17611761
}
17621762
}
@@ -1768,8 +1768,8 @@ impl AttrArgs {
17681768
match self {
17691769
AttrArgs::Empty => TokenStream::default(),
17701770
AttrArgs::Delimited(args) => args.tokens.clone(),
1771-
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => TokenStream::from_ast(expr),
1772-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
1771+
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => TokenStream::from_ast(expr),
1772+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
17731773
unreachable!("in literal form when getting inner tokens: {:?}", lit)
17741774
}
17751775
}
@@ -1785,10 +1785,10 @@ where
17851785
match self {
17861786
AttrArgs::Empty => {}
17871787
AttrArgs::Delimited(args) => args.hash_stable(ctx, hasher),
1788-
AttrArgs::Eq(_eq_span, AttrArgsEq::Ast(expr)) => {
1788+
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => {
17891789
unreachable!("hash_stable {:?}", expr);
17901790
}
1791-
AttrArgs::Eq(eq_span, AttrArgsEq::Hir(lit)) => {
1791+
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(lit) } => {
17921792
eq_span.hash_stable(ctx, hasher);
17931793
lit.hash_stable(ctx, hasher);
17941794
}

compiler/rustc_ast/src/attr/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl AttrItem {
250250
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => {
251251
MetaItemKind::list_from_tokens(args.tokens.clone())
252252
}
253-
AttrArgs::Delimited(_) | AttrArgs::Eq(..) | AttrArgs::Empty => None,
253+
AttrArgs::Delimited(_) | AttrArgs::Eq { .. } | AttrArgs::Empty => None,
254254
}
255255
}
256256

@@ -268,7 +268,7 @@ impl AttrItem {
268268
/// ```
269269
fn value_str(&self) -> Option<Symbol> {
270270
match &self.args {
271-
AttrArgs::Eq(_, args) => args.value_str(),
271+
AttrArgs::Eq { value, .. } => value.value_str(),
272272
AttrArgs::Delimited(_) | AttrArgs::Empty => None,
273273
}
274274
}
@@ -492,7 +492,7 @@ impl MetaItemKind {
492492
MetaItemKind::list_from_tokens(tokens.clone()).map(MetaItemKind::List)
493493
}
494494
AttrArgs::Delimited(..) => None,
495-
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => match expr.kind {
495+
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => match expr.kind {
496496
ExprKind::Lit(token_lit) => {
497497
// Turn failures to `None`, we'll get parse errors elsewhere.
498498
MetaItemLit::from_token_lit(token_lit, expr.span)
@@ -501,7 +501,9 @@ impl MetaItemKind {
501501
}
502502
_ => None,
503503
},
504-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => Some(MetaItemKind::NameValue(lit.clone())),
504+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
505+
Some(MetaItemKind::NameValue(lit.clone()))
506+
}
505507
}
506508
}
507509
}
@@ -702,7 +704,7 @@ pub fn mk_attr_name_value_str(
702704
tokens: None,
703705
});
704706
let path = Path::from_ident(Ident::new(name, span));
705-
let args = AttrArgs::Eq(span, AttrArgsEq::Ast(expr));
707+
let args = AttrArgs::Eq { eq_span: span, value: AttrArgsEq::Ast(expr) };
706708
mk_attr(g, style, unsafety, path, args, span)
707709
}
708710

compiler/rustc_ast/src/mut_visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,11 @@ fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
451451
match args {
452452
AttrArgs::Empty => {}
453453
AttrArgs::Delimited(args) => visit_delim_args(vis, args),
454-
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => {
454+
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(expr) } => {
455455
vis.visit_expr(expr);
456456
vis.visit_span(eq_span);
457457
}
458-
AttrArgs::Eq(_eq_span, AttrArgsEq::Hir(lit)) => {
458+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
459459
unreachable!("in literal form when visiting mac args eq: {:?}", lit)
460460
}
461461
}

compiler/rustc_ast/src/visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,8 @@ pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -
12731273
match args {
12741274
AttrArgs::Empty => {}
12751275
AttrArgs::Delimited(_args) => {}
1276-
AttrArgs::Eq(_eq_span, AttrArgsEq::Ast(expr)) => try_visit!(visitor.visit_expr(expr)),
1277-
AttrArgs::Eq(_eq_span, AttrArgsEq::Hir(lit)) => {
1276+
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => try_visit!(visitor.visit_expr(expr)),
1277+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
12781278
unreachable!("in literal form when walking mac args eq: {:?}", lit)
12791279
}
12801280
}

compiler/rustc_ast_lowering/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
889889
// This is an inert key-value attribute - it will never be visible to macros
890890
// after it gets lowered to HIR. Therefore, we can extract literals to handle
891891
// nonterminals in `#[doc]` (e.g. `#[doc = $e]`).
892-
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => {
892+
&AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(ref expr) } => {
893893
// In valid code the value always ends up as a single literal. Otherwise, a dummy
894894
// literal suffices because the error is handled elsewhere.
895895
let lit = if let ExprKind::Lit(token_lit) = expr.kind
@@ -905,9 +905,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
905905
span: DUMMY_SP,
906906
}
907907
};
908-
AttrArgs::Eq(*eq_span, AttrArgsEq::Hir(lit))
908+
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(lit) }
909909
}
910-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
910+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
911911
unreachable!("in literal form when lowering mac args eq: {:?}", lit)
912912
}
913913
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,14 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
648648
AttrArgs::Empty => {
649649
self.print_path(&item.path, false, 0);
650650
}
651-
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => {
651+
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => {
652652
self.print_path(&item.path, false, 0);
653653
self.space();
654654
self.word_space("=");
655655
let token_str = self.expr_to_string(expr);
656656
self.word(token_str);
657657
}
658-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
658+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
659659
self.print_path(&item.path, false, 0);
660660
self.space();
661661
self.word_space("=");

compiler/rustc_expand/src/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
732732
_ => item.to_tokens(),
733733
};
734734
let attr_item = attr.unwrap_normal_item();
735-
if let AttrArgs::Eq(..) = attr_item.args {
735+
if let AttrArgs::Eq { .. } = attr_item.args {
736736
self.cx.dcx().emit_err(UnsupportedKeyValue { span });
737737
}
738738
let inner_tokens = attr_item.args.inner_tokens();

compiler/rustc_parse/src/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ impl<'a> Parser<'a> {
13761376
AttrArgs::Delimited(args)
13771377
} else if self.eat(&token::Eq) {
13781378
let eq_span = self.prev_token.span;
1379-
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(self.parse_expr_force_collect()?))
1379+
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(self.parse_expr_force_collect()?) }
13801380
} else {
13811381
AttrArgs::Empty
13821382
})

compiler/rustc_parse/src/validate_attr.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
4343
}
4444
}
4545
_ => {
46-
if let AttrArgs::Eq(..) = attr_item.args {
46+
if let AttrArgs::Eq { .. } = attr_item.args {
4747
// All key-value attributes are restricted to meta-item syntax.
4848
match parse_meta(psess, attr) {
4949
Ok(_) => {}
@@ -70,7 +70,7 @@ pub fn parse_meta<'a>(psess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Met
7070
parse_in(psess, tokens.clone(), "meta list", |p| p.parse_meta_seq_top())?;
7171
MetaItemKind::List(nmis)
7272
}
73-
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => {
73+
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => {
7474
if let ast::ExprKind::Lit(token_lit) = expr.kind {
7575
let res = ast::MetaItemLit::from_token_lit(token_lit, expr.span);
7676
let res = match res {
@@ -116,7 +116,9 @@ pub fn parse_meta<'a>(psess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Met
116116
return Err(err);
117117
}
118118
}
119-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => MetaItemKind::NameValue(lit.clone()),
119+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
120+
MetaItemKind::NameValue(lit.clone())
121+
}
120122
},
121123
})
122124
}

compiler/rustc_resolve/src/rustdoc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub fn attrs_to_doc_fragments<'a>(
220220

221221
fn span_for_value(attr: &ast::Attribute) -> Span {
222222
if let ast::AttrKind::Normal(normal) = &attr.kind
223-
&& let ast::AttrArgs::Eq(_, ast::AttrArgsEq::Hir(meta)) = &normal.item.args
223+
&& let ast::AttrArgs::Eq { value: ast::AttrArgsEq::Hir(meta), .. } = &normal.item.args
224224
{
225225
meta.span.with_ctxt(attr.span.ctxt())
226226
} else {

compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ impl<'tcx> OnUnimplementedDirective {
639639
let report_span = match &item.args {
640640
AttrArgs::Empty => item.path.span,
641641
AttrArgs::Delimited(args) => args.dspan.entire(),
642-
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => eq_span.to(expr.span),
643-
AttrArgs::Eq(span, AttrArgsEq::Hir(expr)) => span.to(expr.span),
642+
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(expr) } => eq_span.to(expr.span),
643+
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(expr) } => eq_span.to(expr.span),
644644
};
645645

646646
if let Some(item_def_id) = item_def_id.as_local() {

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ fn filter_doc_attr(normal: &mut ast::NormalAttr, is_inline: bool) {
26492649
});
26502650
args.tokens = TokenStream::new(tokens);
26512651
}
2652-
ast::AttrArgs::Empty | ast::AttrArgs::Eq(..) => {}
2652+
ast::AttrArgs::Empty | ast::AttrArgs::Eq { .. } => {}
26532653
}
26542654
}
26552655

src/tools/clippy/clippy_lints/src/attrs/should_panic_without_expect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::sym;
99

1010
pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) {
1111
if let AttrKind::Normal(normal_attr) = &attr.kind {
12-
if let AttrArgs::Eq(_, AttrArgsEq::Ast(_)) = &normal_attr.item.args {
12+
if let AttrArgs::Eq { value: AttrArgsEq::Ast(_), .. } = &normal_attr.item.args {
1313
// `#[should_panic = ".."]` found, good
1414
return;
1515
}

src/tools/clippy/clippy_lints/src/doc/include_in_doc_without_cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
1212
if !attr.span.from_expansion()
1313
&& let AttrKind::Normal(ref normal) = attr.kind
1414
&& normal.item.path == sym::doc
15-
&& let AttrArgs::Eq(_, AttrArgsEq::Hir(ref meta)) = normal.item.args
15+
&& let AttrArgs::Eq { value: AttrArgsEq::Hir(ref meta), .. } = normal.item.args
1616
&& !attr.span.contains(meta.span)
1717
// Since the `include_str` is already expanded at this point, we can only take the
1818
// whole attribute snippet and then modify for our suggestion.

src/tools/clippy/clippy_lints/src/large_include_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl LateLintPass<'_> for LargeIncludeFile {
9696
&& let AttrKind::Normal(ref normal) = attr.kind
9797
&& let Some(doc) = attr.doc_str()
9898
&& doc.as_str().len() as u64 > self.max_file_size
99-
&& let AttrArgs::Eq(_, AttrArgsEq::Hir(ref meta)) = normal.item.args
99+
&& let AttrArgs::Eq { value: AttrArgsEq::Hir(ref meta), .. } = normal.item.args
100100
&& !attr.span.contains(meta.span)
101101
// Since the `include_str` is already expanded at this point, we can only take the
102102
// whole attribute snippet and then modify for our suggestion.

src/tools/clippy/clippy_utils/src/ast_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,8 @@ pub fn eq_attr_args(l: &AttrArgs, r: &AttrArgs) -> bool {
872872
match (l, r) {
873873
(Empty, Empty) => true,
874874
(Delimited(la), Delimited(ra)) => eq_delim_args(la, ra),
875-
(Eq(_, AttrArgsEq::Ast(le)), Eq(_, AttrArgsEq::Ast(re))) => eq_expr(le, re),
876-
(Eq(_, AttrArgsEq::Hir(ll)), Eq(_, AttrArgsEq::Hir(rl))) => ll.kind == rl.kind,
875+
(Eq { value: AttrArgsEq::Ast(le), .. }, Eq{ value: AttrArgsEq::Ast(re), .. }) => eq_expr(le, re),
876+
(Eq { value: AttrArgsEq::Hir(ll), .. }, Eq{ value: AttrArgsEq::Hir(rl), .. }) => ll.kind == rl.kind,
877877
_ => false,
878878
}
879879
}

0 commit comments

Comments
 (0)