Return the Vec from csearch::get_item_attrs.

Using a closure unnecessarily obfuscates the code.
This commit is contained in:
Ms2ger 2015-01-11 18:16:02 +01:00
parent 56f3554f52
commit 27db3f0585
5 changed files with 13 additions and 27 deletions

View File

@ -774,9 +774,8 @@ fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
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);
}
}
_ => {}

View File

@ -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);
f(decoder::get_item_attrs(&*cdata, def_id.node));
decoder::get_item_attrs(&*cdata, def_id.node)
}
pub fn get_struct_fields(cstore: &cstore::CStore,

View File

@ -5556,8 +5556,7 @@ pub fn predicates<'tcx>(
}
/// 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.)
// (This should really be an iterator.)
pub fn each_attr<F>(tcx: &ctxt, did: DefId, mut f: F) -> bool where
F: FnMut(&ast::Attribute) -> bool,
{
@ -5566,12 +5565,8 @@ pub fn each_attr<F>(tcx: &ctxt, did: DefId, mut f: F) -> bool where
item.attrs.iter().all(|attr| f(attr))
} 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));
}
});
let attrs = csearch::get_item_attrs(&tcx.sess.cstore, did);
let cont = attrs.iter().all(|attr| f(attr));
info!("done");
cont
}

View File

@ -248,9 +248,8 @@ fn get_extern_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<'tcx>,
let f = decl_rust_fn(ccx, fn_ty, name);
csearch::get_item_attrs(&ccx.sess().cstore, did, |attrs| {
set_llvm_fn_attrs(ccx, &attrs[], f)
});
let attrs = csearch::get_item_attrs(&ccx.sess().cstore, did);
set_llvm_fn_attrs(ccx, &attrs[], f);
ccx.externs().borrow_mut().insert(name.to_string(), f);
f

View File

@ -126,13 +126,8 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt,
did: ast::DefId) -> Vec<clean::Attribute> {
let mut attrs = Vec::new();
csearch::get_item_attrs(&tcx.sess.cstore, did, |v| {
attrs.extend(v.into_iter().map(|a| {
a.clean(cx)
}));
});
attrs
let attrs = csearch::get_item_attrs(&tcx.sess.cstore, did);
attrs.into_iter().map(|a| a.clean(cx)).collect()
}
/// Record an external fully qualified name in the external_paths cache.