Skip to content

Use multiline text for crate conflict diagnostics #45946

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

Merged
merged 1 commit into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
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
169 changes: 85 additions & 84 deletions src/librustc_metadata/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,98 +311,96 @@ impl<'a> Context<'a> {
&None => String::new(),
&Some(ref r) => format!(" which `{}` depends on", r.ident),
};
let mut msg = "the following crate versions were found:".to_string();
let mut err = if !self.rejected_via_hash.is_empty() {
struct_span_err!(self.sess,
self.span,
E0460,
"found possibly newer version of crate `{}`{}",
self.ident,
add)
} else if !self.rejected_via_triple.is_empty() {
struct_span_err!(self.sess,
self.span,
E0461,
"couldn't find crate `{}` with expected target triple {}{}",
self.ident,
self.triple,
add)
} else if !self.rejected_via_kind.is_empty() {
struct_span_err!(self.sess,
self.span,
E0462,
"found staticlib `{}` instead of rlib or dylib{}",
self.ident,
add)
} else if !self.rejected_via_version.is_empty() {
struct_span_err!(self.sess,
self.span,
E0514,
"found crate `{}` compiled by an incompatible version of rustc{}",
self.ident,
add)
} else {
let mut err = struct_span_err!(self.sess,
self.span,
E0463,
"can't find crate for `{}`{}",
E0460,
"found possibly newer version of crate `{}`{}",
self.ident,
add);

if (self.ident == "std" || self.ident == "core")
&& self.triple != config::host_triple() {
err.note(&format!("the `{}` target may not be installed", self.triple));
}
err.span_label(self.span, "can't find crate");
err
};

if !self.rejected_via_triple.is_empty() {
let mismatches = self.rejected_via_triple.iter();
for (i, &CrateMismatch { ref path, ref got }) in mismatches.enumerate() {
err.note(&format!("crate `{}`, path #{}, triple {}: {}",
self.ident,
i + 1,
got,
path.display()));
}
}
if !self.rejected_via_hash.is_empty() {
err.note("perhaps that crate needs to be recompiled?");
let mismatches = self.rejected_via_hash.iter();
for (i, &CrateMismatch { ref path, .. }) in mismatches.enumerate() {
err.note(&format!("crate `{}` path #{}: {}", self.ident, i + 1, path.display()));
for &CrateMismatch { ref path, .. } in mismatches {
msg.push_str(&format!("\ncrate `{}`: {}", self.ident, path.display()));
}
match self.root {
&None => {}
&Some(ref r) => {
for (i, path) in r.paths().iter().enumerate() {
err.note(&format!("crate `{}` path #{}: {}",
r.ident,
i + 1,
path.display()));
for path in r.paths().iter() {
msg.push_str(&format!("\ncrate `{}`: {}", r.ident, path.display()));
}
}
}
}
if !self.rejected_via_kind.is_empty() {
err.note(&msg);
err
} else if !self.rejected_via_triple.is_empty() {
let mut err = struct_span_err!(self.sess,
self.span,
E0461,
"couldn't find crate `{}` \
with expected target triple {}{}",
self.ident,
self.triple,
add);
let mismatches = self.rejected_via_triple.iter();
for &CrateMismatch { ref path, ref got } in mismatches {
msg.push_str(&format!("\ncrate `{}`, target triple {}: {}",
self.ident,
got,
path.display()));
}
err.note(&msg);
err
} else if !self.rejected_via_kind.is_empty() {
let mut err = struct_span_err!(self.sess,
self.span,
E0462,
"found staticlib `{}` instead of rlib or dylib{}",
self.ident,
add);
err.help("please recompile that crate using --crate-type lib");
let mismatches = self.rejected_via_kind.iter();
for (i, &CrateMismatch { ref path, .. }) in mismatches.enumerate() {
err.note(&format!("crate `{}` path #{}: {}", self.ident, i + 1, path.display()));
for &CrateMismatch { ref path, .. } in mismatches {
msg.push_str(&format!("\ncrate `{}`: {}", self.ident, path.display()));
}
}
if !self.rejected_via_version.is_empty() {
err.note(&msg);
err
} else if !self.rejected_via_version.is_empty() {
let mut err = struct_span_err!(self.sess,
self.span,
E0514,
"found crate `{}` compiled by an incompatible version \
of rustc{}",
self.ident,
add);
err.help(&format!("please recompile that crate using this compiler ({})",
rustc_version()));
let mismatches = self.rejected_via_version.iter();
for (i, &CrateMismatch { ref path, ref got }) in mismatches.enumerate() {
err.note(&format!("crate `{}` path #{}: {} compiled by {:?}",
self.ident,
i + 1,
path.display(),
got));
for &CrateMismatch { ref path, ref got } in mismatches {
msg.push_str(&format!("\ncrate `{}` compiled by {}: {}",
self.ident,
got,
path.display()));
}
}
err.note(&msg);
err
} else {
let mut err = struct_span_err!(self.sess,
self.span,
E0463,
"can't find crate for `{}`{}",
self.ident,
add);

if (self.ident == "std" || self.ident == "core")
&& self.triple != config::host_triple() {
err.note(&format!("the `{}` target may not be installed", self.triple));
}
err.span_label(self.span, "can't find crate");
err
};

if !self.rejected_via_filename.is_empty() {
let dylibname = self.dylibname();
let mismatches = self.rejected_via_filename.iter();
Expand Down Expand Up @@ -534,16 +532,23 @@ impl<'a> Context<'a> {
E0464,
"multiple matching crates for `{}`",
self.crate_name);
err.note("candidates:");
for (_, lib) in libraries {
if let Some((ref p, _)) = lib.dylib {
err.note(&format!("path: {}", p.display()));
}
if let Some((ref p, _)) = lib.rlib {
err.note(&format!("path: {}", p.display()));
let candidates = libraries.iter().filter_map(|(_, lib)| {
let crate_name = &lib.metadata.get_root().name.as_str();
match &(&lib.dylib, &lib.rlib) {
&(&Some((ref pd, _)), &Some((ref pr, _))) => {
Some(format!("\ncrate `{}`: {}\n{:>padding$}",
crate_name,
pd.display(),
pr.display(),
padding=8 + crate_name.len()))
}
&(&Some((ref p, _)), &None) | &(&None, &Some((ref p, _))) => {
Some(format!("\ncrate `{}`: {}", crate_name, p.display()))
}
&(&None, &None) => None,
}
note_crate_name(&mut err, &lib.metadata.get_root().name.as_str());
}
}).collect::<String>();
err.note(&format!("candidates:{}", candidates));
err.emit();
None
}
Expand Down Expand Up @@ -815,10 +820,6 @@ impl<'a> Context<'a> {
}
}

pub fn note_crate_name(err: &mut DiagnosticBuilder, name: &str) {
err.note(&format!("crate name: {}", name));
}

// Just a small wrapper to time how long reading metadata takes.
fn get_metadata_section(target: &Target,
flavor: CrateFlavor,
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/changing-crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

extern crate a;
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
//~| NOTE: the following crate versions were found
//~| NOTE: perhaps that crate needs to be recompiled
//~| NOTE: crate `a` path #1:
//~| NOTE: crate `b` path #1:

fn main() {}
3 changes: 1 addition & 2 deletions src/test/compile-fail/svh-change-lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
extern crate a;
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
//~| NOTE: perhaps that crate needs to be recompiled
//~| NOTE: crate `a` path #1:
//~| NOTE: crate `b` path #1:
//~| NOTE: the following crate versions were found:

fn main() {
b::foo()
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/svh-change-significant-cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
extern crate a;
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
//~| NOTE: perhaps that crate needs to be recompiled
//~| NOTE: crate `a` path #1:
//~| NOTE: crate `b` path #1:
//~| NOTE: the following crate versions were found:

fn main() {
b::foo()
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/svh-change-trait-bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
extern crate a;
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
//~| NOTE: perhaps that crate needs to be recompiled
//~| NOTE: crate `a` path #1:
//~| NOTE: crate `b` path #1:
//~| NOTE: the following crate versions were found:

fn main() {
b::foo()
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/svh-change-type-arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
extern crate a;
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
//~| NOTE: perhaps that crate needs to be recompiled
//~| NOTE: crate `a` path #1:
//~| NOTE: crate `b` path #1:
//~| NOTE: the following crate versions were found:

fn main() {
b::foo()
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/svh-change-type-ret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
extern crate a;
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
//~| NOTE: perhaps that crate needs to be recompiled
//~| NOTE: crate `a` path #1:
//~| NOTE: crate `b` path #1:
//~| NOTE: the following crate versions were found:

fn main() {
b::foo()
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/svh-change-type-static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
extern crate a;
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
//~| NOTE: perhaps that crate needs to be recompiled
//~| NOTE: crate `a` path #1:
//~| NOTE: crate `b` path #1:
//~| NOTE: the following crate versions were found:

fn main() {
b::foo()
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/svh-use-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
extern crate uta;
extern crate utb; //~ ERROR: found possibly newer version of crate `uta` which `utb` depends
//~| NOTE: perhaps that crate needs to be recompiled?
//~| NOTE: crate `uta` path #1:
//~| NOTE: crate `utb` path #1:
//~| NOTE: the following crate versions were found:

fn main() {
utb::foo()
Expand Down
5 changes: 2 additions & 3 deletions src/test/run-make/many-crates-but-no-match/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ all:
$(RUSTC) -L $(A2) -L $(A3) crateC.rs >$(LOG) 2>&1 || true
grep "found possibly newer version of crate \`crateA\` which \`crateB\` depends on" $(LOG)
grep "note: perhaps that crate needs to be recompiled?" $(LOG)
grep "note: crate \`crateA\` path #1:" $(LOG)
grep "note: crate \`crateA\` path #2:" $(LOG)
grep "note: crate \`crateB\` path #1:" $(LOG)
grep "crate \`crateA\`:" $(LOG) # this will match two entries
grep "crate \`crateB\`:" $(LOG)