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];
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;
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)
}
}
/// 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),
}
/// 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),
}
}
-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),
}
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 {
}
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)
}
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 \
}
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();
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);
}
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),
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 {