about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2013-06-24 12:38:14 -0700
committerCorey Richardson <corey@octayn.net>2013-06-26 18:08:34 -0400
commit2b17e4775c816b59d92e166b8a8db039aaa7ba85 (patch)
tree857dbbf387f96144bd34127575c2c43091d38eea /src
parent2234f61038f5a91fce0d7f4765eec55fc4b0c622 (diff)
downloadrust-2b17e4775c816b59d92e166b8a8db039aaa7ba85.tar.gz
rust-2b17e4775c816b59d92e166b8a8db039aaa7ba85.zip
rustc: Eliminate extra failing case in metadata::loader::crate_from_metas
Closes #2406
Diffstat (limited to 'src')
-rw-r--r--src/librustc/metadata/loader.rs102
1 files changed, 50 insertions, 52 deletions
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs
index f6ad676546d..17aad969e32 100644
--- a/src/librustc/metadata/loader.rs
+++ b/src/librustc/metadata/loader.rs
@@ -89,70 +89,68 @@ fn find_library_crate_aux(
     filesearch: @filesearch::FileSearch
 ) -> Option<(~str, @~[u8])> {
     let crate_name = crate_name_from_metas(cx.metas);
-    let prefix: ~str = prefix + crate_name + "-";
-    let suffix: ~str = /*bad*/copy suffix;
+    let prefix = prefix + crate_name + "-";
 
     let mut matches = ~[];
-    filesearch::search(filesearch, |path| {
+    filesearch::search(filesearch, |path| -> Option<()> {
         debug!("inspecting file %s", path.to_str());
-        let f: ~str = path.filename().get();
-        if !(f.starts_with(prefix) && f.ends_with(suffix)) {
-            debug!("skipping %s, doesn't look like %s*%s", path.to_str(),
-                   prefix, suffix);
-            option::None::<()>
-        } else {
-            debug!("%s is a candidate", path.to_str());
-            match get_metadata_section(cx.os, path) {
-              option::Some(cvec) => {
-                if !crate_matches(cvec, cx.metas, cx.hash) {
-                    debug!("skipping %s, metadata doesn't match",
-                           path.to_str());
-                    option::None::<()>
-                } else {
-                    debug!("found %s with matching metadata", path.to_str());
-                    matches.push((path.to_str(), cvec));
-                    option::None::<()>
+        match path.filename() {
+            Some(ref f) if f.starts_with(prefix) && f.ends_with(suffix) => {
+                debug!("%s is a candidate", path.to_str());
+                match get_metadata_section(cx.os, path) {
+                    Some(cvec) =>
+                        if !crate_matches(cvec, cx.metas, cx.hash) {
+                            debug!("skipping %s, metadata doesn't match",
+                                   path.to_str());
+                            None
+                        } else {
+                            debug!("found %s with matching metadata", path.to_str());
+                            matches.push((path.to_str(), cvec));
+                            None
+                        },
+                    _ => {
+                        debug!("could not load metadata for %s", path.to_str());
+                        None
+                    }
                 }
-              }
-              _ => {
-                debug!("could not load metadata for %s", path.to_str());
-                option::None::<()>
-              }
             }
-        }
-    });
+            _ => {
+                debug!("skipping %s, doesn't look like %s*%s", path.to_str(),
+                       prefix, suffix);
+                None
+            }
+        }});
 
-    if matches.is_empty() {
-        None
-    } else if matches.len() == 1u {
-        Some(/*bad*/copy matches[0])
-    } else {
-        cx.diag.span_err(
-            cx.span, fmt!("multiple matching crates for `%s`", crate_name));
-        cx.diag.handler().note("candidates:");
-        for matches.iter().advance |&(ident, data)| {
-            cx.diag.handler().note(fmt!("path: %s", ident));
-            let attrs = decoder::get_crate_attributes(data);
-            note_linkage_attrs(cx.intr, cx.diag, attrs);
+    match matches.len() {
+        0 => None,
+        1 => Some(matches[0]),
+        _ => {
+            cx.diag.span_err(
+                    cx.span, fmt!("multiple matching crates for `%s`", crate_name));
+                cx.diag.handler().note("candidates:");
+                for matches.each |&(ident, data)| {
+                    cx.diag.handler().note(fmt!("path: %s", ident));
+                    let attrs = decoder::get_crate_attributes(data);
+                    note_linkage_attrs(cx.intr, cx.diag, attrs);
+                }
+                cx.diag.handler().abort_if_errors();
+                None
+            }
         }
-        cx.diag.handler().abort_if_errors();
-        None
-    }
 }
 
 pub fn crate_name_from_metas(metas: &[@ast::meta_item]) -> @str {
-    let name_items = attr::find_meta_items_by_name(metas, "name");
-    match name_items.last_opt() {
-        Some(i) => {
-            match attr::get_meta_item_value_str(*i) {
-                Some(n) => n,
-                // FIXME (#2406): Probably want a warning here since the user
-                // is using the wrong type of meta item.
-                _ => fail!()
-            }
+    for metas.each |m| {
+        match m.node {
+            ast::meta_name_value(s, ref l) if s == @"name" =>
+                match l.node {
+                    ast::lit_str(s) => return s,
+                    _ => ()
+                },
+            _ => ()
         }
-        None => fail!("expected to find the crate name")
     }
+    fail!("expected to find the crate name")
 }
 
 pub fn note_linkage_attrs(intr: @ident_interner,