Skip to content

Commit

Permalink
rustc: Eliminate extra failing case in metadata::loader::crate_from_m…
Browse files Browse the repository at this point in the history
…etas

Closes rust-lang#2406
  • Loading branch information
catamorphism committed Jun 24, 2013
1 parent c6515ee commit 13044fb
Showing 1 changed file with 50 additions and 52 deletions.
102 changes: 50 additions & 52 deletions src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

1 comment on commit 13044fb

@brson
Copy link

@brson brson commented on 13044fb Jun 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.