]> git.lizzy.rs Git - rust.git/commitdiff
Remove AttrId from Attribute constructors
authorMark Rousskov <mark.simulacrum@gmail.com>
Tue, 30 Jul 2019 17:50:22 +0000 (13:50 -0400)
committerMark Rousskov <mark.simulacrum@gmail.com>
Wed, 31 Jul 2019 12:55:37 +0000 (08:55 -0400)
src/librustc/hir/lowering.rs
src/libsyntax/attr/mod.rs
src/libsyntax/ext/build.rs
src/libsyntax/ext/expand.rs
src/libsyntax/parse/attr.rs
src/libsyntax/print/pprust.rs
src/libsyntax_ext/standard_library_imports.rs
src/libsyntax_ext/test_harness.rs

index c403fb99a97676b53ae217a90254eba43aa5f92a..145d044b521308cf06347ac11f0dbc90df4a15d2 100644 (file)
@@ -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];
 
index ec26ea8d543d36f3c7680774018333a397612599..11c1b1c56c71ba7384af058fe2db5616f5078d04 100644 (file)
@@ -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<T, F>(&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),
index 2b0feb7f4b36754628bcb58dedab19a9e91f2bc8..8a7a9e712a303b0294894467ca6fa25378489f73 100644 (file)
@@ -1135,7 +1135,7 @@ fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> P<ast::Item> {
     }
 
     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 {
index 10d5da81ceef3ccb0ba5d073f827ea5cf088a77c..1e9e16d72f8297dab1add89b8c4d60b2918ff2cc 100644 (file)
@@ -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)
         }
index af484c886ab35b7d796995d6eea834fd2938251d..a42da1123600a999fb6ac1343a2fa6cd3524f52f 100644 (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 @@ 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();
index 88ff6ee9071014deb7efefb3b46af59be7ba269c..34a47c124528a06760f1db2d5f9ae3df062eced8 100644 (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);
     }
 
index 81bb32d79a2aa84eead684dbbe190065925ea2de..e1dad909776765bf5ddc0f2fdb97b0aa51bd9709 100644 (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),
index 848c797856ea9c39d3f99f55612d8a8973d2cac6..c65922339e9f5e388b2f0efaf96fd269eef99cdb 100644 (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 {