Skip to content

Commit 0a42bad

Browse files
Remove AttrId from Attribute constructors
1 parent 804f0f3 commit 0a42bad

File tree

8 files changed

+30
-26
lines changed

8 files changed

+30
-26
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5168,7 +5168,7 @@ impl<'a> LoweringContext<'a> {
51685168
let uc_nested = attr::mk_nested_word_item(uc_ident);
51695169
attr::mk_list_item(e.span, allow_ident, vec![uc_nested])
51705170
};
5171-
attr::mk_attr_outer(e.span, attr::mk_attr_id(), allow)
5171+
attr::mk_attr_outer(e.span, allow)
51725172
};
51735173
let attrs = vec![attr];
51745174

src/libsyntax/attr/mod.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ pub use builtin::*;
66
pub use IntType::*;
77
pub use ReprAttr::*;
88
pub use StabilityLevel::*;
9+
pub use crate::ast::Attribute;
910

1011
use crate::ast;
11-
use crate::ast::{AttrId, Attribute, AttrStyle, Name, Ident, Path, PathSegment};
12+
use crate::ast::{AttrId, AttrStyle, Name, Ident, Path, PathSegment};
1213
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
1314
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
1415
use crate::mut_visit::visit_clobber;
@@ -328,13 +329,14 @@ impl Attribute {
328329
let meta = mk_name_value_item_str(
329330
Ident::with_empty_ctxt(sym::doc),
330331
dummy_spanned(Symbol::intern(&strip_doc_comment_decoration(&comment.as_str()))));
331-
let mut attr = if self.style == ast::AttrStyle::Outer {
332-
mk_attr_outer(self.span, self.id, meta)
333-
} else {
334-
mk_attr_inner(self.span, self.id, meta)
335-
};
336-
attr.is_sugared_doc = true;
337-
f(&attr)
332+
f(&Attribute {
333+
id: self.id,
334+
style: self.style,
335+
path: meta.path,
336+
tokens: meta.node.tokens(meta.span),
337+
is_sugared_doc: true,
338+
span: self.span,
339+
})
338340
} else {
339341
f(self)
340342
}
@@ -377,9 +379,9 @@ pub fn mk_attr_id() -> AttrId {
377379
}
378380

379381
/// Returns an inner attribute with the given value and span.
380-
pub fn mk_attr_inner(span: Span, id: AttrId, item: MetaItem) -> Attribute {
382+
pub fn mk_attr_inner(span: Span, item: MetaItem) -> Attribute {
381383
Attribute {
382-
id,
384+
id: mk_attr_id(),
383385
style: ast::AttrStyle::Inner,
384386
path: item.path,
385387
tokens: item.node.tokens(item.span),
@@ -389,9 +391,9 @@ pub fn mk_attr_inner(span: Span, id: AttrId, item: MetaItem) -> Attribute {
389391
}
390392

391393
/// Returns an outer attribute with the given value and span.
392-
pub fn mk_attr_outer(span: Span, id: AttrId, item: MetaItem) -> Attribute {
394+
pub fn mk_attr_outer(span: Span, item: MetaItem) -> Attribute {
393395
Attribute {
394-
id,
396+
id: mk_attr_id(),
395397
style: ast::AttrStyle::Outer,
396398
path: item.path,
397399
tokens: item.node.tokens(item.span),
@@ -400,12 +402,12 @@ pub fn mk_attr_outer(span: Span, id: AttrId, item: MetaItem) -> Attribute {
400402
}
401403
}
402404

403-
pub fn mk_sugared_doc_attr(id: AttrId, text: Symbol, span: Span) -> Attribute {
405+
pub fn mk_sugared_doc_attr(text: Symbol, span: Span) -> Attribute {
404406
let style = doc_comment_style(&text.as_str());
405407
let lit_kind = LitKind::Str(text, ast::StrStyle::Cooked);
406408
let lit = Lit::from_lit_kind(lit_kind, span);
407409
Attribute {
408-
id,
410+
id: mk_attr_id(),
409411
style,
410412
path: Path::from_ident(Ident::with_empty_ctxt(sym::doc).with_span_pos(span)),
411413
tokens: MetaItemKind::NameValue(lit).tokens(span),

src/libsyntax/ext/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
11351135
}
11361136

11371137
fn attribute(&self, sp: Span, mi: ast::MetaItem) -> ast::Attribute {
1138-
attr::mk_attr_outer(sp, attr::mk_attr_id(), mi)
1138+
attr::mk_attr_outer(sp, mi)
11391139
}
11401140

11411141
fn meta_word(&self, sp: Span, w: ast::Name) -> ast::MetaItem {

src/libsyntax/ext/expand.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,10 +1340,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13401340
}
13411341

13421342
let meta = attr::mk_list_item(DUMMY_SP, Ident::with_empty_ctxt(sym::doc), items);
1343-
match at.style {
1344-
ast::AttrStyle::Inner => *at = attr::mk_attr_inner(at.span, at.id, meta),
1345-
ast::AttrStyle::Outer => *at = attr::mk_attr_outer(at.span, at.id, meta),
1346-
}
1343+
*at = attr::Attribute {
1344+
span: at.span,
1345+
id: at.id,
1346+
style: at.style,
1347+
path: meta.path,
1348+
tokens: meta.node.tokens(meta.span),
1349+
is_sugared_doc: false,
1350+
};
13471351
} else {
13481352
noop_visit_attribute(at, self)
13491353
}

src/libsyntax/parse/attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a> Parser<'a> {
5353
just_parsed_doc_comment = false;
5454
}
5555
token::DocComment(s) => {
56-
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.token.span);
56+
let attr = attr::mk_sugared_doc_attr(s, self.token.span);
5757
if attr.style != ast::AttrStyle::Outer {
5858
let mut err = self.fatal("expected outer doc comment");
5959
err.note("inner doc comments like this (starting with \
@@ -239,7 +239,7 @@ impl<'a> Parser<'a> {
239239
}
240240
token::DocComment(s) => {
241241
// we need to get the position of this token before we bump.
242-
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.token.span);
242+
let attr = attr::mk_sugared_doc_attr(s, self.token.span);
243243
if attr.style == ast::AttrStyle::Inner {
244244
attrs.push(attr);
245245
self.bump();

src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
123123
let pi_nested = attr::mk_nested_word_item(ast::Ident::with_empty_ctxt(sym::prelude_import));
124124
let list = attr::mk_list_item(
125125
DUMMY_SP, ast::Ident::with_empty_ctxt(sym::feature), vec![pi_nested]);
126-
let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), list);
126+
let fake_attr = attr::mk_attr_inner(DUMMY_SP, list);
127127
s.print_attribute(&fake_attr);
128128

129129
// #![no_std]
130130
let no_std_meta = attr::mk_word_item(ast::Ident::with_empty_ctxt(sym::no_std));
131-
let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), no_std_meta);
131+
let fake_attr = attr::mk_attr_inner(DUMMY_SP, no_std_meta);
132132
s.print_attribute(&fake_attr);
133133
}
134134

src/libsyntax_ext/standard_library_imports.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ pub fn inject(
4242
krate.module.items.insert(0, P(ast::Item {
4343
attrs: vec![attr::mk_attr_outer(
4444
DUMMY_SP,
45-
attr::mk_attr_id(),
4645
attr::mk_word_item(ast::Ident::with_empty_ctxt(sym::macro_use))
4746
)],
4847
vis: dummy_spanned(ast::VisibilityKind::Inherited),

src/libsyntax_ext/test_harness.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ impl MutVisitor for EntryPointCleaner {
161161
let allow_dead_code_item = attr::mk_list_item(DUMMY_SP, allow_ident,
162162
vec![dc_nested]);
163163
let allow_dead_code = attr::mk_attr_outer(DUMMY_SP,
164-
attr::mk_attr_id(),
165164
allow_dead_code_item);
166165

167166
ast::Item {

0 commit comments

Comments
 (0)