diff options
| author | bors <bors@rust-lang.org> | 2015-01-13 21:29:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-13 21:29:00 +0000 |
| commit | c366e433c14c49eee9144e6010a5fc54cbcdd341 (patch) | |
| tree | 58d851401afbf237f96d6a913220b25eb2255d95 /src/librustc | |
| parent | 4fd1e6235dd241939475f79c8f58a455f5996690 (diff) | |
| parent | 756466bfd0fd457623378ab461164dbaaa9ce971 (diff) | |
auto merge of #20957 : Ms2ger/rust/closures, r=alexcrichton
Returning the vectors directly makes the code a lot cleaner.
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/lint/builtin.rs | 5 | ||||
| -rw-r--r-- | src/librustc/metadata/csearch.rs | 10 | ||||
| -rw-r--r-- | src/librustc/metadata/decoder.rs | 10 | ||||
| -rw-r--r-- | src/librustc/middle/traits/error_reporting.rs | 8 | ||||
| -rw-r--r-- | src/librustc/middle/ty.rs | 45 |
5 files changed, 24 insertions, 54 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 8ed177c82a8..d95000ece5a 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -774,9 +774,8 @@ impl LintPass for UnusedResults { warned |= check_must_use(cx, &it.attrs[], s.span); } } else { - csearch::get_item_attrs(&cx.sess().cstore, did, |attrs| { - warned |= check_must_use(cx, &attrs[], s.span); - }); + let attrs = csearch::get_item_attrs(&cx.sess().cstore, did); + warned |= check_must_use(cx, &attrs[], s.span); } } _ => {} diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index cfff7c9935b..0bbd11bea0a 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -203,13 +203,11 @@ pub fn get_methods_if_impl(cstore: &cstore::CStore, decoder::get_methods_if_impl(cstore.intr.clone(), &*cdata, def.node) } -pub fn get_item_attrs<F>(cstore: &cstore::CStore, - def_id: ast::DefId, - f: F) where - F: FnOnce(Vec<ast::Attribute>), -{ +pub fn get_item_attrs(cstore: &cstore::CStore, + def_id: ast::DefId) + -> Vec<ast::Attribute> { let cdata = cstore.get_crate_data(def_id.krate); - decoder::get_item_attrs(&*cdata, def_id.node, f) + decoder::get_item_attrs(&*cdata, def_id.node) } pub fn get_struct_fields(cstore: &cstore::CStore, diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 5ac8f908bf1..dfbff715688 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1025,18 +1025,16 @@ pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd, ret } -pub fn get_item_attrs<F>(cdata: Cmd, - orig_node_id: ast::NodeId, - f: F) where - F: FnOnce(Vec<ast::Attribute>), -{ +pub fn get_item_attrs(cdata: Cmd, + orig_node_id: ast::NodeId) + -> Vec<ast::Attribute> { // The attributes for a tuple struct are attached to the definition, not the ctor; // we assume that someone passing in a tuple struct ctor is actually wanting to // look at the definition let node_id = get_tuple_struct_definition_if_ctor(cdata, orig_node_id); let node_id = node_id.map(|x| x.node).unwrap_or(orig_node_id); let item = lookup_item(node_id, cdata.data()); - f(get_attributes(item)); + get_attributes(item) } pub fn get_struct_field_attrs(cdata: Cmd) -> HashMap<ast::NodeId, Vec<ast::Attribute>> { diff --git a/src/librustc/middle/traits/error_reporting.rs b/src/librustc/middle/traits/error_reporting.rs index 6b4dd101286..e9ef214543d 100644 --- a/src/librustc/middle/traits/error_reporting.rs +++ b/src/librustc/middle/traits/error_reporting.rs @@ -70,7 +70,7 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>, span: Span) -> Option<String> { let def_id = trait_ref.def_id; let mut report = None; - ty::each_attr(infcx.tcx, def_id, |item| { + for item in ty::get_attrs(infcx.tcx, def_id).iter() { if item.check_name("rustc_on_unimplemented") { let err_sp = if item.meta().span == DUMMY_SP { span @@ -136,11 +136,9 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>, eg `#[rustc_on_unimplemented = \"foo\"]`", trait_str).as_slice()); } - false - } else { - true + break; } - }); + } report } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index cf30969ebef..236aa3818c7 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -68,7 +68,7 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet}; use util::nodemap::{FnvHashMap}; use arena::TypedArena; -use std::borrow::BorrowFrom; +use std::borrow::{BorrowFrom, Cow}; use std::cell::{Cell, RefCell}; use std::cmp::{self, Ordering}; use std::fmt::{self, Show}; @@ -76,6 +76,7 @@ use std::hash::{Hash, Writer, SipHasher, Hasher}; use std::mem; use std::ops; use std::rc::Rc; +use std::vec::CowVec; use collections::enum_set::{EnumSet, CLike}; use std::collections::{HashMap, HashSet}; use syntax::abi; @@ -5555,40 +5556,20 @@ pub fn predicates<'tcx>( vec } -/// Iterate over attributes of a definition. -// (This should really be an iterator, but that would require csearch and -// decoder to use iterators instead of higher-order functions.) -pub fn each_attr<F>(tcx: &ctxt, did: DefId, mut f: F) -> bool where - F: FnMut(&ast::Attribute) -> bool, -{ +/// Get the attributes of a definition. +pub fn get_attrs<'tcx>(tcx: &'tcx ctxt, did: DefId) + -> CowVec<'tcx, ast::Attribute> { if is_local(did) { let item = tcx.map.expect_item(did.node); - item.attrs.iter().all(|attr| f(attr)) + Cow::Borrowed(&item.attrs[]) } else { - info!("getting foreign attrs"); - let mut cont = true; - csearch::get_item_attrs(&tcx.sess.cstore, did, |attrs| { - if cont { - cont = attrs.iter().all(|attr| f(attr)); - } - }); - info!("done"); - cont + Cow::Owned(csearch::get_item_attrs(&tcx.sess.cstore, did)) } } /// Determine whether an item is annotated with an attribute pub fn has_attr(tcx: &ctxt, did: DefId, attr: &str) -> bool { - let mut found = false; - each_attr(tcx, did, |item| { - if item.check_name(attr) { - found = true; - false - } else { - true - } - }); - found + get_attrs(tcx, did).iter().any(|item| item.check_name(attr)) } /// Determine whether an item is annotated with `#[repr(packed)]` @@ -5605,13 +5586,9 @@ pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool { pub fn lookup_repr_hints(tcx: &ctxt, did: DefId) -> Rc<Vec<attr::ReprAttr>> { memoized(&tcx.repr_hint_cache, did, |did: DefId| { Rc::new(if did.krate == LOCAL_CRATE { - let mut acc = Vec::new(); - ty::each_attr(tcx, did, |meta| { - acc.extend(attr::find_repr_attrs(tcx.sess.diagnostic(), - meta).into_iter()); - true - }); - acc + get_attrs(tcx, did).iter().flat_map(|meta| { + attr::find_repr_attrs(tcx.sess.diagnostic(), meta).into_iter() + }).collect() } else { csearch::get_repr_attrs(&tcx.sess.cstore, did) }) |
