From 0a42badd4c9bfb6cb693f9a2105cc5b2cc674f63 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 30 Jul 2019 13:50:22 -0400 Subject: [PATCH] Remove AttrId from Attribute constructors --- src/librustc/hir/lowering.rs | 2 +- src/libsyntax/attr/mod.rs | 30 ++++++++++--------- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/expand.rs | 12 +++++--- src/libsyntax/parse/attr.rs | 4 +-- src/libsyntax/print/pprust.rs | 4 +-- src/libsyntax_ext/standard_library_imports.rs | 1 - src/libsyntax_ext/test_harness.rs | 1 - 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index c403fb99a97..145d044b521 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -5168,7 +5168,7 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr { 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]; diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index ec26ea8d543..11c1b1c56c7 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -6,9 +6,10 @@ 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 @@ pub fn with_desugared_doc(&self, f: F) -> T where 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), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 2b0feb7f4b3..8a7a9e712a3 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -1135,7 +1135,7 @@ fn item_ty(&self, span: Span, name: Ident, ty: P) -> P { } 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 { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 10d5da81cee..1e9e16d72f8 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1340,10 +1340,14 @@ fn visit_attribute(&mut self, at: &mut ast::Attribute) { } 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) } diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index af484c886ab..a42da112360 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -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 @@ fn parse_attribute_with_inner_parse_policy(&mut self, } 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(); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 88ff6ee9071..34a47c12452 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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); } diff --git a/src/libsyntax_ext/standard_library_imports.rs b/src/libsyntax_ext/standard_library_imports.rs index 81bb32d79a2..e1dad909776 100644 --- a/src/libsyntax_ext/standard_library_imports.rs +++ b/src/libsyntax_ext/standard_library_imports.rs @@ -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), diff --git a/src/libsyntax_ext/test_harness.rs b/src/libsyntax_ext/test_harness.rs index 848c797856e..c65922339e9 100644 --- a/src/libsyntax_ext/test_harness.rs +++ b/src/libsyntax_ext/test_harness.rs @@ -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 { -- 2.44.0