Skip to content

Commit 40a7fd3

Browse files
committed
fixup the entire compiler to use hir::Attribute
1 parent ffb72e9 commit 40a7fd3

File tree

103 files changed

+513
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+513
-449
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ impl AttrArgs {
16971697
match self {
16981698
AttrArgs::Empty => None,
16991699
AttrArgs::Delimited(args) => Some(args.dspan.entire()),
1700-
AttrArgs::Eq(eq_span, expr) => Some(eq_span.to(expr.span)),
1700+
AttrArgs::Eq { eq_span, value } => Some(eq_span.to(value.span)),
17011701
}
17021702
}
17031703

@@ -1707,7 +1707,7 @@ impl AttrArgs {
17071707
match self {
17081708
AttrArgs::Empty => TokenStream::default(),
17091709
AttrArgs::Delimited(args) => args.tokens.clone(),
1710-
AttrArgs::Eq(_, expr) => TokenStream::from_ast(expr),
1710+
AttrArgs::Eq { eq_span: _, value } => TokenStream::from_ast(value),
17111711
}
17121712
}
17131713
}

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Functions dealing with attributes and meta items.
22
3+
use std::fmt::Debug;
34
use std::iter;
45
use std::sync::atomic::{AtomicU32, Ordering};
56

@@ -68,7 +69,7 @@ impl AttributeExt for Attribute {
6869
fn value_span(&self) -> Option<Span> {
6970
match &self.kind {
7071
AttrKind::Normal(normal) => match &normal.item.args {
71-
AttrArgs::Eq(_, l) => Some(l.span),
72+
AttrArgs::Eq { eq_span: _, value } => Some(value.span),
7273
_ => None,
7374
},
7475
AttrKind::DocComment(..) => None,
@@ -225,13 +226,13 @@ impl AttrItem {
225226
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => {
226227
MetaItemKind::list_from_tokens(args.tokens.clone())
227228
}
228-
AttrArgs::Delimited(_) | AttrArgs::Eq(..) | AttrArgs::Empty => None,
229+
AttrArgs::Delimited(_) | AttrArgs::Eq { .. } | AttrArgs::Empty => None,
229230
}
230231
}
231232

232233
fn value_str(&self) -> Option<Symbol> {
233234
match &self.args {
234-
AttrArgs::Eq(_, expr) => match expr.kind {
235+
AttrArgs::Eq { eq_span: _, value } => match value.kind {
235236
ExprKind::Lit(token_lit) => {
236237
LitKind::from_token_lit(token_lit).ok().and_then(|lit| lit.str())
237238
}
@@ -435,10 +436,10 @@ impl MetaItemKind {
435436
MetaItemKind::list_from_tokens(tokens.clone()).map(MetaItemKind::List)
436437
}
437438
AttrArgs::Delimited(..) => None,
438-
AttrArgs::Eq(_, expr) => match expr.kind {
439+
AttrArgs::Eq { eq_span: _, value } => match value.kind {
439440
ExprKind::Lit(token_lit) => {
440441
// Turn failures to `None`, we'll get parse errors elsewhere.
441-
MetaItemLit::from_token_lit(token_lit, expr.span)
442+
MetaItemLit::from_token_lit(token_lit, value.span)
442443
.ok()
443444
.map(|lit| MetaItemKind::NameValue(lit))
444445
}
@@ -636,15 +637,15 @@ pub fn mk_attr_name_value_str(
636637
span: Span,
637638
) -> Attribute {
638639
let lit = token::Lit::new(token::Str, escape_string_symbol(val), None);
639-
let expr = P(Expr {
640+
let value = P(Expr {
640641
id: DUMMY_NODE_ID,
641642
kind: ExprKind::Lit(lit),
642643
span,
643644
attrs: AttrVec::new(),
644645
tokens: None,
645646
});
646647
let path = Path::from_ident(Ident::new(name, span));
647-
let args = AttrArgs::Eq(span, expr);
648+
let args = AttrArgs::Eq { eq_span: span, value };
648649
mk_attr(g, style, unsafety, path, args, span)
649650
}
650651

compiler/rustc_ast/src/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_span::Symbol;
22
use rustc_span::symbol::sym;
33

4-
use crate::{Attribute, attr};
4+
use crate::attr::{self, AttributeExt};
55

66
#[derive(Debug)]
77
pub enum EntryPointType {
@@ -37,7 +37,7 @@ pub enum EntryPointType {
3737
}
3838

3939
pub fn entry_point_type(
40-
attrs: &[Attribute],
40+
attrs: &[impl AttributeExt],
4141
at_root: bool,
4242
name: Option<Symbol>,
4343
) -> EntryPointType {

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
394394
match args {
395395
AttrArgs::Empty => {}
396396
AttrArgs::Delimited(args) => visit_delim_args(vis, args),
397-
AttrArgs::Eq(eq_span, expr) => {
398-
vis.visit_expr(expr);
397+
AttrArgs::Eq { eq_span, value } => {
398+
vis.visit_expr(value);
399399
vis.visit_span(eq_span);
400400
}
401401
}

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -
12341234
match args {
12351235
AttrArgs::Empty => {}
12361236
AttrArgs::Delimited(_args) => {}
1237-
AttrArgs::Eq(_eq_span, expr) => try_visit!(visitor.visit_expr(expr)),
1237+
AttrArgs::Eq { eq_span: _, value } => try_visit!(visitor.visit_expr(value)),
12381238
}
12391239
V::Result::output()
12401240
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::assert_matches::assert_matches;
22

3+
use rustc_ast::attr::AttributeExt;
34
use rustc_ast::ptr::P as AstP;
45
use rustc_ast::*;
56
use rustc_data_structures::stack::ensure_sufficient_stack;

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_ast::attr::AttributeExt;
12
use rustc_ast::ptr::P;
23
use rustc_ast::visit::AssocCtxt;
34
use rustc_ast::*;

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -976,11 +976,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
976976
// This is an inert key-value attribute - it will never be visible to macros
977977
// after it gets lowered to HIR. Therefore, we can extract literals to handle
978978
// nonterminals in `#[doc]` (e.g. `#[doc = $e]`).
979-
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => {
979+
AttrArgs::Eq { eq_span, value } => {
980980
// In valid code the value always ends up as a single literal. Otherwise, a dummy
981981
// literal suffices because the error is handled elsewhere.
982-
let lit = if let ExprKind::Lit(token_lit) = expr.kind
983-
&& let Ok(lit) = MetaItemLit::from_token_lit(token_lit, expr.span)
982+
let lit = if let ExprKind::Lit(token_lit) = value.kind
983+
&& let Ok(lit) = MetaItemLit::from_token_lit(token_lit, value.span)
984984
{
985985
lit
986986
} else {
@@ -992,10 +992,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
992992
span: DUMMY_SP,
993993
}
994994
};
995-
AttrArgs::Eq(*eq_span, AttrArgsEq::Hir(lit))
996-
}
997-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
998-
unreachable!("in literal form when lowering mac args eq: {:?}", lit)
995+
hir::AttrArgs::Eq { eq_span: *eq_span, value: lit }
999996
}
1000997
}
1001998
}
@@ -2512,7 +2509,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25122509

25132510
fn stmt_let_pat(
25142511
&mut self,
2515-
attrs: Option<&'hir [Attribute]>,
2512+
attrs: Option<&'hir [hir::Attribute]>,
25162513
span: Span,
25172514
init: Option<&'hir hir::Expr<'hir>>,
25182515
pat: &'hir hir::Pat<'hir>,

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use std::mem;
2020
use std::ops::{Deref, DerefMut};
2121

22+
use attr::AttributeExt;
2223
use itertools::{Either, Itertools};
2324
use rustc_ast::ptr::P;
2425
use rustc_ast::visit::{AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor, walk_list};
@@ -383,7 +384,7 @@ impl<'a> AstValidator<'a> {
383384
sym::forbid,
384385
sym::warn,
385386
];
386-
!arr.contains(&attr.name_or_empty()) && rustc_attr::is_builtin_attr(attr)
387+
!arr.contains(&attr.name_or_empty()) && rustc_attr::is_builtin_attr(*attr)
387388
})
388389
.for_each(|attr| {
389390
if attr.is_doc_comment() {

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_ast as ast;
2+
use rustc_ast::attr::AttributeExt;
23
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
34
use rustc_ast::{NodeId, PatKind, attr, token};
45
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features, GateIssue};

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod item;
88

99
use std::borrow::Cow;
1010

11-
use rustc_ast::attr::AttrIdGenerator;
11+
use rustc_ast::attr::{AttrIdGenerator, AttributeExt};
1212
use rustc_ast::ptr::P;
1313
use rustc_ast::token::{
1414
self, BinOpToken, CommentKind, Delimiter, IdentIsRaw, Nonterminal, Token, TokenKind,
@@ -17,9 +17,9 @@ use rustc_ast::tokenstream::{Spacing, TokenStream, TokenTree};
1717
use rustc_ast::util::classify;
1818
use rustc_ast::util::comments::{Comment, CommentStyle};
1919
use rustc_ast::{
20-
self as ast, AttrArgs, AttrArgsEq, BindingMode, BlockCheckMode, ByRef, DelimArgs, GenericArg,
21-
GenericBound, InlineAsmOperand, InlineAsmOptions, InlineAsmRegOrRegClass,
22-
InlineAsmTemplatePiece, PatKind, RangeEnd, RangeSyntax, Safety, SelfKind, Term, attr,
20+
self as ast, AttrArgs, BindingMode, BlockCheckMode, ByRef, DelimArgs, GenericArg, GenericBound,
21+
InlineAsmOperand, InlineAsmOptions, InlineAsmRegOrRegClass, InlineAsmTemplatePiece, PatKind,
22+
RangeEnd, RangeSyntax, Safety, SelfKind, Term, attr,
2323
};
2424
use rustc_span::edition::Edition;
2525
use rustc_span::source_map::{SourceMap, Spanned};
@@ -640,18 +640,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
640640
AttrArgs::Empty => {
641641
self.print_path(&item.path, false, 0);
642642
}
643-
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => {
643+
AttrArgs::Eq { eq_span: _, value } => {
644644
self.print_path(&item.path, false, 0);
645645
self.space();
646646
self.word_space("=");
647-
let token_str = self.expr_to_string(expr);
648-
self.word(token_str);
649-
}
650-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
651-
self.print_path(&item.path, false, 0);
652-
self.space();
653-
self.word_space("=");
654-
let token_str = self.meta_item_lit_to_string(lit);
647+
let token_str = self.expr_to_string(value);
655648
self.word(token_str);
656649
}
657650
}

0 commit comments

Comments
 (0)