Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: Eliminate extra failing case in metadata::loader::crate_from_metas #7367

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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