Remove AttrId from Attribute constructors

This commit is contained in:
Mark Rousskov 2019-07-30 13:50:22 -04:00
parent 804f0f3c20
commit 0a42badd4c
8 changed files with 30 additions and 26 deletions

View file

@ -5168,7 +5168,7 @@ impl<'a> LoweringContext<'a> {
let uc_nested = attr::mk_nested_word_item(uc_ident);
attr::mk_list_item(e.span, allow_ident, vec![uc_nested])
};
attr::mk_attr_outer(e.span, attr::mk_attr_id(), allow)
attr::mk_attr_outer(e.span, allow)
};
let attrs = vec![attr];

View file

@ -6,9 +6,10 @@ pub use builtin::*;
pub use IntType::*;
pub use ReprAttr::*;
pub use StabilityLevel::*;
pub use crate::ast::Attribute;
use crate::ast;
use crate::ast::{AttrId, Attribute, AttrStyle, Name, Ident, Path, PathSegment};
use crate::ast::{AttrId, AttrStyle, Name, Ident, Path, PathSegment};
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
use crate::mut_visit::visit_clobber;
@ -328,13 +329,14 @@ impl Attribute {
let meta = mk_name_value_item_str(
Ident::with_empty_ctxt(sym::doc),
dummy_spanned(Symbol::intern(&strip_doc_comment_decoration(&comment.as_str()))));
let mut attr = if self.style == ast::AttrStyle::Outer {
mk_attr_outer(self.span, self.id, meta)
} else {
mk_attr_inner(self.span, self.id, meta)
};
attr.is_sugared_doc = true;
f(&attr)
f(&Attribute {
id: self.id,
style: self.style,
path: meta.path,
tokens: meta.node.tokens(meta.span),
is_sugared_doc: true,
span: self.span,
})
} else {
f(self)
}
@ -377,9 +379,9 @@ pub fn mk_attr_id() -> AttrId {
}
/// Returns an inner attribute with the given value and span.
pub fn mk_attr_inner(span: Span, id: AttrId, item: MetaItem) -> Attribute {
pub fn mk_attr_inner(span: Span, item: MetaItem) -> Attribute {
Attribute {
id,
id: mk_attr_id(),
style: ast::AttrStyle::Inner,
path: item.path,
tokens: item.node.tokens(item.span),
@ -389,9 +391,9 @@ pub fn mk_attr_inner(span: Span, id: AttrId, item: MetaItem) -> Attribute {
}
/// Returns an outer attribute with the given value and span.
pub fn mk_attr_outer(span: Span, id: AttrId, item: MetaItem) -> Attribute {
pub fn mk_attr_outer(span: Span, item: MetaItem) -> Attribute {
Attribute {
id,
id: mk_attr_id(),
style: ast::AttrStyle::Outer,
path: item.path,
tokens: item.node.tokens(item.span),
@ -400,12 +402,12 @@ pub fn mk_attr_outer(span: Span, id: AttrId, item: MetaItem) -> Attribute {
}
}
pub fn mk_sugared_doc_attr(id: AttrId, text: Symbol, span: Span) -> Attribute {
pub fn mk_sugared_doc_attr(text: Symbol, span: Span) -> Attribute {
let style = doc_comment_style(&text.as_str());
let lit_kind = LitKind::Str(text, ast::StrStyle::Cooked);
let lit = Lit::from_lit_kind(lit_kind, span);
Attribute {
id,
id: mk_attr_id(),
style,
path: Path::from_ident(Ident::with_empty_ctxt(sym::doc).with_span_pos(span)),
tokens: MetaItemKind::NameValue(lit).tokens(span),

View file

@ -1135,7 +1135,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn attribute(&self, sp: Span, mi: ast::MetaItem) -> ast::Attribute {
attr::mk_attr_outer(sp, attr::mk_attr_id(), mi)
attr::mk_attr_outer(sp, mi)
}
fn meta_word(&self, sp: Span, w: ast::Name) -> ast::MetaItem {

View file

@ -1340,10 +1340,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
}
let meta = attr::mk_list_item(DUMMY_SP, Ident::with_empty_ctxt(sym::doc), items);
match at.style {
ast::AttrStyle::Inner => *at = attr::mk_attr_inner(at.span, at.id, meta),
ast::AttrStyle::Outer => *at = attr::mk_attr_outer(at.span, at.id, meta),
}
*at = attr::Attribute {
span: at.span,
id: at.id,
style: at.style,
path: meta.path,
tokens: meta.node.tokens(meta.span),
is_sugared_doc: false,
};
} else {
noop_visit_attribute(at, self)
}

View file

@ -53,7 +53,7 @@ impl<'a> Parser<'a> {
just_parsed_doc_comment = false;
}
token::DocComment(s) => {
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.token.span);
let attr = attr::mk_sugared_doc_attr(s, self.token.span);
if attr.style != ast::AttrStyle::Outer {
let mut err = self.fatal("expected outer doc comment");
err.note("inner doc comments like this (starting with \
@ -239,7 +239,7 @@ impl<'a> Parser<'a> {
}
token::DocComment(s) => {
// we need to get the position of this token before we bump.
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.token.span);
let attr = attr::mk_sugared_doc_attr(s, self.token.span);
if attr.style == ast::AttrStyle::Inner {
attrs.push(attr);
self.bump();

View file

@ -123,12 +123,12 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
let pi_nested = attr::mk_nested_word_item(ast::Ident::with_empty_ctxt(sym::prelude_import));
let list = attr::mk_list_item(
DUMMY_SP, ast::Ident::with_empty_ctxt(sym::feature), vec![pi_nested]);
let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), list);
let fake_attr = attr::mk_attr_inner(DUMMY_SP, list);
s.print_attribute(&fake_attr);
// #![no_std]
let no_std_meta = attr::mk_word_item(ast::Ident::with_empty_ctxt(sym::no_std));
let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), no_std_meta);
let fake_attr = attr::mk_attr_inner(DUMMY_SP, no_std_meta);
s.print_attribute(&fake_attr);
}

View file

@ -42,7 +42,6 @@ pub fn inject(
krate.module.items.insert(0, P(ast::Item {
attrs: vec![attr::mk_attr_outer(
DUMMY_SP,
attr::mk_attr_id(),
attr::mk_word_item(ast::Ident::with_empty_ctxt(sym::macro_use))
)],
vis: dummy_spanned(ast::VisibilityKind::Inherited),

View file

@ -161,7 +161,6 @@ impl MutVisitor for EntryPointCleaner {
let allow_dead_code_item = attr::mk_list_item(DUMMY_SP, allow_ident,
vec![dc_nested]);
let allow_dead_code = attr::mk_attr_outer(DUMMY_SP,
attr::mk_attr_id(),
allow_dead_code_item);
ast::Item {