Skip to content

Commit 27db3f0

Browse files
committed
Return the Vec from csearch::get_item_attrs.
Using a closure unnecessarily obfuscates the code.
1 parent 56f3554 commit 27db3f0

File tree

5 files changed

+13
-27
lines changed

5 files changed

+13
-27
lines changed

src/librustc/lint/builtin.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,8 @@ impl LintPass for UnusedResults {
774774
warned |= check_must_use(cx, &it.attrs[], s.span);
775775
}
776776
} else {
777-
csearch::get_item_attrs(&cx.sess().cstore, did, |attrs| {
778-
warned |= check_must_use(cx, &attrs[], s.span);
779-
});
777+
let attrs = csearch::get_item_attrs(&cx.sess().cstore, did);
778+
warned |= check_must_use(cx, &attrs[], s.span);
780779
}
781780
}
782781
_ => {}

src/librustc/metadata/csearch.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,11 @@ pub fn get_methods_if_impl(cstore: &cstore::CStore,
203203
decoder::get_methods_if_impl(cstore.intr.clone(), &*cdata, def.node)
204204
}
205205

206-
pub fn get_item_attrs<F>(cstore: &cstore::CStore,
207-
def_id: ast::DefId,
208-
f: F) where
209-
F: FnOnce(Vec<ast::Attribute>),
210-
{
206+
pub fn get_item_attrs(cstore: &cstore::CStore,
207+
def_id: ast::DefId)
208+
-> Vec<ast::Attribute> {
211209
let cdata = cstore.get_crate_data(def_id.krate);
212-
f(decoder::get_item_attrs(&*cdata, def_id.node));
210+
decoder::get_item_attrs(&*cdata, def_id.node)
213211
}
214212

215213
pub fn get_struct_fields(cstore: &cstore::CStore,

src/librustc/middle/ty.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5556,8 +5556,7 @@ pub fn predicates<'tcx>(
55565556
}
55575557

55585558
/// Iterate over attributes of a definition.
5559-
// (This should really be an iterator, but that would require csearch and
5560-
// decoder to use iterators instead of higher-order functions.)
5559+
// (This should really be an iterator.)
55615560
pub fn each_attr<F>(tcx: &ctxt, did: DefId, mut f: F) -> bool where
55625561
F: FnMut(&ast::Attribute) -> bool,
55635562
{
@@ -5566,12 +5565,8 @@ pub fn each_attr<F>(tcx: &ctxt, did: DefId, mut f: F) -> bool where
55665565
item.attrs.iter().all(|attr| f(attr))
55675566
} else {
55685567
info!("getting foreign attrs");
5569-
let mut cont = true;
5570-
csearch::get_item_attrs(&tcx.sess.cstore, did, |attrs| {
5571-
if cont {
5572-
cont = attrs.iter().all(|attr| f(attr));
5573-
}
5574-
});
5568+
let attrs = csearch::get_item_attrs(&tcx.sess.cstore, did);
5569+
let cont = attrs.iter().all(|attr| f(attr));
55755570
info!("done");
55765571
cont
55775572
}

src/librustc_trans/trans/base.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,8 @@ fn get_extern_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<'tcx>,
248248

249249
let f = decl_rust_fn(ccx, fn_ty, name);
250250

251-
csearch::get_item_attrs(&ccx.sess().cstore, did, |attrs| {
252-
set_llvm_fn_attrs(ccx, &attrs[], f)
253-
});
251+
let attrs = csearch::get_item_attrs(&ccx.sess().cstore, did);
252+
set_llvm_fn_attrs(ccx, &attrs[], f);
254253

255254
ccx.externs().borrow_mut().insert(name.to_string(), f);
256255
f

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,8 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
126126

127127
pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt,
128128
did: ast::DefId) -> Vec<clean::Attribute> {
129-
let mut attrs = Vec::new();
130-
csearch::get_item_attrs(&tcx.sess.cstore, did, |v| {
131-
attrs.extend(v.into_iter().map(|a| {
132-
a.clean(cx)
133-
}));
134-
});
135-
attrs
129+
let attrs = csearch::get_item_attrs(&tcx.sess.cstore, did);
130+
attrs.into_iter().map(|a| a.clean(cx)).collect()
136131
}
137132

138133
/// Record an external fully qualified name in the external_paths cache.

0 commit comments

Comments
 (0)