Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more libsyntax::attr cleanup #63272

Merged
merged 3 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5176,11 +5176,10 @@ impl<'a> LoweringContext<'a> {
let attr = {
// `allow(unreachable_code)`
let allow = {
let allow_ident = Ident::with_empty_ctxt(sym::allow).with_span_pos(e.span);
let uc_ident = Ident::with_empty_ctxt(sym::unreachable_code)
.with_span_pos(e.span);
let allow_ident = Ident::new(sym::allow, e.span);
let uc_ident = Ident::new(sym::unreachable_code, e.span);
let uc_nested = attr::mk_nested_word_item(uc_ident);
attr::mk_list_item(e.span, allow_ident, vec![uc_nested])
attr::mk_list_item(allow_ident, vec![uc_nested])
};
attr::mk_attr_outer(allow)
};
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/clean/cfg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ fn test_parse_ok() {
fn test_parse_err() {
with_default_globals(|| {
let mi = attr::mk_name_value_item(
DUMMY_SP,
Ident::from_str("foo"),
LitKind::Bool(false),
DUMMY_SP,
Expand Down
11 changes: 6 additions & 5 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,17 @@ impl Attribute {

pub fn mk_name_value_item_str(ident: Ident, value: Spanned<Symbol>) -> MetaItem {
let lit_kind = LitKind::Str(value.node, ast::StrStyle::Cooked);
mk_name_value_item(ident.span.to(value.span), ident, lit_kind, value.span)
mk_name_value_item(ident, lit_kind, value.span)
}

pub fn mk_name_value_item(span: Span, ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {
pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {
let lit = Lit::from_lit_kind(lit_kind, lit_span);
let span = ident.span.to(lit_span);
MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::NameValue(lit) }
}

pub fn mk_list_item(span: Span, ident: Ident, items: Vec<NestedMetaItem>) -> MetaItem {
MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::List(items) }
pub fn mk_list_item(ident: Ident, items: Vec<NestedMetaItem>) -> MetaItem {
MetaItem { path: Path::from_ident(ident), span: ident.span, node: MetaItemKind::List(items) }
}

pub fn mk_word_item(ident: Ident) -> MetaItem {
Expand All @@ -367,7 +368,7 @@ pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem {
NestedMetaItem::MetaItem(mk_word_item(ident))
}

pub fn mk_attr_id() -> AttrId {
crate fn mk_attr_id() -> AttrId {
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;

Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,13 +879,12 @@ impl<'a> ExtCtxt<'a> {

pub fn meta_list(&self, sp: Span, name: ast::Name, mis: Vec<ast::NestedMetaItem>)
-> ast::MetaItem {
attr::mk_list_item(sp, Ident::new(name, sp), mis)
attr::mk_list_item(Ident::new(name, sp), mis)
}

pub fn meta_name_value(&self, span: Span, name: ast::Name, lit_kind: ast::LitKind)
-> ast::MetaItem {
attr::mk_name_value_item(span, Ident::new(name, span),
lit_kind, span)
attr::mk_name_value_item(Ident::new(name, span), lit_kind, span)
}

pub fn item_use(&self, sp: Span,
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
];

let include_ident = Ident::with_empty_ctxt(sym::include);
let item = attr::mk_list_item(DUMMY_SP, include_ident, include_info);
let item = attr::mk_list_item(include_ident, include_info);
items.push(ast::NestedMetaItem::MetaItem(item));
}
Err(e) => {
Expand Down Expand Up @@ -1333,7 +1333,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
}
}

let meta = attr::mk_list_item(DUMMY_SP, Ident::with_empty_ctxt(sym::doc), items);
let meta = attr::mk_list_item(Ident::with_empty_ctxt(sym::doc), items);
*at = attr::Attribute {
span: at.span,
id: at.id,
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::tokenstream::{self, TokenStream, TokenTree};

use rustc_target::spec::abi::{self, Abi};
use syntax_pos::{self, BytePos};
use syntax_pos::{DUMMY_SP, FileName, Span};
use syntax_pos::{FileName, Span};

use std::borrow::Cow;

Expand Down Expand Up @@ -124,8 +124,7 @@ pub fn print_crate<'a>(cm: &'a SourceMap,

// #![feature(prelude_import)]
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 list = attr::mk_list_item(ast::Ident::with_empty_ctxt(sym::feature), vec![pi_nested]);
let fake_attr = attr::mk_attr_inner(list);
s.print_attribute(&fake_attr);

Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax_ext/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ impl MutVisitor for EntryPointCleaner {
item.map(|ast::Item {id, ident, attrs, node, vis, span, tokens}| {
let allow_ident = Ident::with_empty_ctxt(sym::allow);
let dc_nested = attr::mk_nested_word_item(Ident::from_str("dead_code"));
let allow_dead_code_item = attr::mk_list_item(DUMMY_SP, allow_ident,
vec![dc_nested]);
let allow_dead_code_item = attr::mk_list_item(allow_ident, vec![dc_nested]);
let allow_dead_code = attr::mk_attr_outer(allow_dead_code_item);

ast::Item {
Expand Down