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

syntax: Remove traits AttrMetaMethods, AttributeMethods, and AttrNestedMetaItemMethods #35917

Merged
merged 5 commits into from
Aug 30, 2016
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
18 changes: 11 additions & 7 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use session::Session;

use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax::visit;
use syntax::visit::Visitor;

Expand Down Expand Up @@ -52,18 +51,22 @@ impl<'a> CheckAttrVisitor<'a> {
return;
}
};

for word in words {
let word: &str = &word.name();
let message = match word {
let name = match word.name() {
Some(word) => word,
None => continue,
};

let message = match &*name {
"C" => {
if target != Target::Struct && target != Target::Enum {
"attribute should be applied to struct or enum"
"attribute should be applied to struct or enum"
} else {
continue
}
}
"packed" |
"simd" => {
"packed" | "simd" => {
if target != Target::Struct {
"attribute should be applied to struct"
} else {
Expand All @@ -74,13 +77,14 @@ impl<'a> CheckAttrVisitor<'a> {
"i32" | "u32" | "i64" | "u64" |
"isize" | "usize" => {
if target != Target::Enum {
"attribute should be applied to enum"
"attribute should be applied to enum"
} else {
continue
}
}
_ => continue,
};

span_err!(self.sess, attr.span, E0517, "{}", message);
}
}
Expand Down
23 changes: 20 additions & 3 deletions src/librustc/hir/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//! and returns a piece of the same type.

use hir::*;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
use syntax::ast::MetaItemKind;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_};
use syntax::ast::{NestedMetaItem, NestedMetaItemKind, MetaItem, MetaItemKind};
use hir;
use syntax_pos::Span;
use syntax::codemap::{respan, Spanned};
Expand All @@ -38,6 +38,10 @@ pub trait Folder : Sized {
noop_fold_meta_items(meta_items, self)
}

fn fold_meta_list_item(&mut self, list_item: NestedMetaItem) -> NestedMetaItem {
noop_fold_meta_list_item(list_item, self)
}

fn fold_meta_item(&mut self, meta_item: P<MetaItem>) -> P<MetaItem> {
noop_fold_meta_item(meta_item, self)
}
Expand Down Expand Up @@ -486,13 +490,26 @@ pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T) -> Option<Attr
})
}

pub fn noop_fold_meta_list_item<T: Folder>(li: NestedMetaItem, fld: &mut T)
-> NestedMetaItem {
Spanned {
node: match li.node {
NestedMetaItemKind::MetaItem(mi) => {
NestedMetaItemKind::MetaItem(fld.fold_meta_item(mi))
},
NestedMetaItemKind::Literal(lit) => NestedMetaItemKind::Literal(lit)
},
span: fld.new_span(li.span)
}
}

pub fn noop_fold_meta_item<T: Folder>(mi: P<MetaItem>, fld: &mut T) -> P<MetaItem> {
mi.map(|Spanned { node, span }| {
Spanned {
node: match node {
MetaItemKind::Word(id) => MetaItemKind::Word(id),
MetaItemKind::List(id, mis) => {
MetaItemKind::List(id, mis.move_map(|e| fld.fold_meta_item(e)))
MetaItemKind::List(id, mis.move_map(|e| fld.fold_meta_list_item(e)))
}
MetaItemKind::NameValue(id, s) => MetaItemKind::NameValue(id, s),
},
Expand Down
12 changes: 5 additions & 7 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use util::nodemap::FnvHashMap;
use std::cmp;
use std::default::Default as StdDefault;
use std::mem;
use syntax::attr::{self, AttrMetaMethods};
use syntax::attr;
use syntax::parse::token::InternedString;
use syntax::ast;
use syntax_pos::Span;
Expand Down Expand Up @@ -372,12 +372,10 @@ pub fn gather_attr(attr: &ast::Attribute)
return out;
};

for meta in metas {
out.push(if meta.is_word() {
Ok((meta.name().clone(), level, meta.span))
} else {
Err(meta.span)
});
for li in metas {
out.push(li.word().map_or(Err(li.span), |word| {
Ok((word.name().clone(), level, word.span))
}));
}

out
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use middle::weak_lang_items;
use util::nodemap::FnvHashMap;

use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax::parse::token::InternedString;
use hir::intravisit::Visitor;
use hir;
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/recursion_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use session::Session;
use syntax::ast;
use syntax::attr::AttrMetaMethods;

pub fn update_recursion_limit(sess: &Session, krate: &ast::Crate) {
for attr in &krate.attrs {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use syntax_pos::{Span, DUMMY_SP};
use syntax::ast;
use syntax::ast::{NodeId, Attribute};
use syntax::feature_gate::{GateIssue, emit_feature_err, find_lang_feature_accepted_version};
use syntax::attr::{self, Stability, Deprecation, AttrMetaMethods};
use syntax::attr::{self, Stability, Deprecation};
use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap};

use hir;
Expand Down
10 changes: 6 additions & 4 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use middle::cstore;

use syntax::ast::{self, IntTy, UintTy};
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::parse;
use syntax::parse::token::InternedString;
use syntax::feature_gate::UnstableFeatures;
Expand Down Expand Up @@ -1773,8 +1772,9 @@ mod tests {
use std::path::PathBuf;
use std::rc::Rc;
use super::{OutputType, OutputTypes, Externs, PanicStrategy};
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::{ast, attr};
use syntax::parse::token::InternedString;
use syntax::codemap::dummy_spanned;

fn optgroups() -> Vec<OptGroup> {
super::rustc_optgroups().into_iter()
Expand Down Expand Up @@ -1803,7 +1803,9 @@ mod tests {
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore));
let cfg = build_configuration(&sess, cfg);
assert!((attr::contains_name(&cfg[..], "test")));
assert!(attr::contains(&cfg, &dummy_spanned(ast::MetaItemKind::Word({
InternedString::new("test")
}))));
}

// When the user supplies --test and --cfg test, don't implicitly add
Expand Down
1 change: 0 additions & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use util::nodemap::{FnvHashMap, FnvHashSet};
use std::cmp;
use std::fmt;
use syntax::ast;
use syntax::attr::{AttributeMethods, AttrMetaMethods};
use syntax_pos::Span;
use errors::DiagnosticBuilder;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::rc::Rc;
use std::slice;
use std::vec::IntoIter;
use syntax::ast::{self, CrateNum, Name, NodeId};
use syntax::attr::{self, AttrMetaMethods};
use syntax::attr;
use syntax::parse::token::InternedString;
use syntax_pos::{DUMMY_SP, Span};

Expand Down
1 change: 0 additions & 1 deletion src/librustc_borrowck/borrowck/fragments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use rustc::middle::mem_categorization as mc;
use std::mem;
use std::rc::Rc;
use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax_pos::{Span, DUMMY_SP};

#[derive(PartialEq, Eq, PartialOrd, Ord)]
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_borrowck/borrowck/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use borrowck::BorrowckCtxt;

use syntax::ast::{self, MetaItem};
use syntax::attr::AttrMetaMethods;
use syntax::ptr::P;
use syntax_pos::{Span, DUMMY_SP};

Expand Down Expand Up @@ -43,8 +42,9 @@ fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<P<MetaItem
if attr.check_name("rustc_mir") {
let items = attr.meta_item_list();
for item in items.iter().flat_map(|l| l.iter()) {
if item.check_name(name) {
return Some(item.clone())
match item.meta_item() {
Some(mi) if mi.check_name(name) => return Some(mi.clone()),
_ => continue
}
}
}
Expand Down Expand Up @@ -126,8 +126,6 @@ fn do_dataflow<'a, 'tcx, BD>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
bd: BD) -> DataflowResults<BD>
where BD: BitDenotation<Idx=MovePathIndex, Ctxt=MoveDataParamEnv<'tcx>> + DataflowOperator
{
use syntax::attr::AttrMetaMethods;

let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option<String> {
if let Some(item) = has_rustc_mir_with(attrs, name) {
if let Some(s) = item.value_str() {
Expand Down
1 change: 0 additions & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use std::fmt;
use std::mem;
use std::rc::Rc;
use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax_pos::{MultiSpan, Span};
use errors::DiagnosticBuilder;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use std::fs;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use syntax::{ast, diagnostics, visit};
use syntax::attr::{self, AttrMetaMethods};
use syntax::attr;
use syntax::parse::{self, PResult, token};
use syntax::util::node_count::NodeCounter;
use syntax;
Expand Down
13 changes: 7 additions & 6 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ use std::thread;
use rustc::session::early_error;

use syntax::{ast, json};
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
use syntax::parse::{self, PResult};
Expand Down Expand Up @@ -655,17 +654,19 @@ impl RustcDefaultCalls {
if !allow_unstable_cfg && GatedCfg::gate(&*cfg).is_some() {
continue;
}

if cfg.is_word() {
println!("{}", cfg.name());
} else if cfg.is_value_str() {
if let Some(s) = cfg.value_str() {
println!("{}=\"{}\"", cfg.name(), s);
}
} else if let Some(s) = cfg.value_str() {
println!("{}=\"{}\"", cfg.name(), s);
} else if cfg.is_meta_item_list() {
// Right now there are not and should not be any
// MetaItemKind::List items in the configuration returned by
// `build_configuration`.
panic!("MetaItemKind::List encountered in default cfg")
panic!("Found an unexpected list in cfg attribute '{}'!", cfg.name())
} else {
// There also shouldn't be literals.
panic!("Found an unexpected literal in cfg attribute '{}'!", cfg.name())
}
}
}
Expand Down
38 changes: 23 additions & 15 deletions src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ use std::env;
use std::fs::File;
use std::io::Write;
use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax::parse::token::InternedString;
use syntax_pos::Span;

Expand Down Expand Up @@ -116,31 +115,40 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
for attr in self.tcx.get_attrs(def_id).iter() {
if attr.check_name(IF_THIS_CHANGED) {
let mut id = None;
for meta_item in attr.meta_item_list().unwrap_or_default() {
if meta_item.is_word() && id.is_none() {
id = Some(meta_item.name().clone());
} else {
// FIXME better-encapsulate meta_item (don't directly access `node`)
span_bug!(meta_item.span(), "unexpected meta-item {:?}", meta_item.node)
for list_item in attr.meta_item_list().unwrap_or_default() {
match list_item.word() {
Some(word) if id.is_none() => {
id = Some(word.name().clone())
},
_ => {
// FIXME better-encapsulate meta_item (don't directly access `node`)
span_bug!(list_item.span(), "unexpected list-item {:?}", list_item.node)
}
}
}

let id = id.unwrap_or(InternedString::new(ID));
self.if_this_changed.entry(id)
.or_insert(FnvHashSet())
.insert((attr.span, def_id, DepNode::Hir(def_id)));
} else if attr.check_name(THEN_THIS_WOULD_NEED) {
let mut dep_node_interned = None;
let mut id = None;
for meta_item in attr.meta_item_list().unwrap_or_default() {
if meta_item.is_word() && dep_node_interned.is_none() {
dep_node_interned = Some(meta_item.name().clone());
} else if meta_item.is_word() && id.is_none() {
id = Some(meta_item.name().clone());
} else {
// FIXME better-encapsulate meta_item (don't directly access `node`)
span_bug!(meta_item.span(), "unexpected meta-item {:?}", meta_item.node)
for list_item in attr.meta_item_list().unwrap_or_default() {
match list_item.word() {
Some(word) if dep_node_interned.is_none() => {
dep_node_interned = Some(word.name().clone());
},
Some(word) if id.is_none() => {
id = Some(word.name().clone())
},
_ => {
// FIXME better-encapsulate meta_item (don't directly access `node`)
span_bug!(list_item.span(), "unexpected meta-item {:?}", list_item.node)
}
}
}

let dep_node = match dep_node_interned {
Some(ref n) => {
match DepNode::from_label_string(&n[..], def_id) {
Expand Down
1 change: 0 additions & 1 deletion src/librustc_incremental/calculate_svh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//! at the beginning.

use syntax::ast;
use syntax::attr::AttributeMethods;
use std::hash::{Hash, SipHasher, Hasher};
use rustc::dep_graph::DepNode;
use rustc::hir;
Expand Down
15 changes: 9 additions & 6 deletions src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::hir::intravisit::Visitor;
use rustc_data_structures::fnv::FnvHashSet;
use syntax::ast::{self, Attribute, MetaItem};
use syntax::attr::AttrMetaMethods;
use syntax::ast::{self, Attribute, NestedMetaItem};
use syntax::parse::token::InternedString;
use rustc::ty::TyCtxt;

Expand Down Expand Up @@ -71,13 +70,17 @@ pub struct DirtyCleanVisitor<'a, 'tcx:'a> {
}

impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
fn expect_associated_value(&self, item: &MetaItem) -> InternedString {
fn expect_associated_value(&self, item: &NestedMetaItem) -> InternedString {
if let Some(value) = item.value_str() {
value
} else {
self.tcx.sess.span_fatal(
item.span,
&format!("associated value expected for `{}`", item.name()));
let msg = if let Some(name) = item.name() {
format!("associated value expected for `{}`", name)
} else {
"expected an associated value".to_string()
};

self.tcx.sess.span_fatal(item.span, &msg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/bad_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use lint::{LateContext, LintContext, LintArray};
use lint::{LintPass, LateLintPass};

use syntax::ast;
use syntax::attr::{self, AttrMetaMethods};
use syntax::attr;
use syntax_pos::Span;

use rustc::hir::{self, PatKind};
Expand Down
Loading