]> git.lizzy.rs Git - rust.git/commitdiff
Return the Vec from csearch::get_item_attrs.
authorMs2ger <ms2ger@gmail.com>
Sun, 11 Jan 2015 17:16:02 +0000 (18:16 +0100)
committerMs2ger <ms2ger@gmail.com>
Tue, 13 Jan 2015 09:28:06 +0000 (10:28 +0100)
Using a closure unnecessarily obfuscates the code.

src/librustc/lint/builtin.rs
src/librustc/metadata/csearch.rs
src/librustc/middle/ty.rs
src/librustc_trans/trans/base.rs
src/librustdoc/clean/inline.rs

index 8ed177c82a8f7c70749990544ef4c4e3e42f59a2..d95000ece5ae6f3397645c8b87fddfb72e30812f 100644 (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);
                 }
             }
             _ => {}
index 8650df46cc46d6d187949830ed49236527a925f6..0bbd11bea0a48e0daaee8a8e5b8da9b0fdef911b 100644 (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,
index cf30969ebefcc8540c3e6982c21475f57cc665e1..2cef5f8353fa9d99adfc668993334b119906a502 100644 (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
     }
index ea98d6bb74e9504b502c5f41e8aff2424aede395..fe7c0d4cf69485f3ba22928d67f53762d8ab9a2a 100644 (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
index 3e2474468adb696c8edc83717f67794a538c0973..ccaefadc1fcd963e281e00a6e788792df3f8df60 100644 (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.