about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-11-24 04:03:36 +0000
committerbors <bors@rust-lang.org>2017-11-24 04:03:36 +0000
commiteb44c89641f6b570d2ec934f5b43f865b31d7dcb (patch)
treee6bd34e837beb76ae8734b9b2ab6f96ffdc0424b /src
parent93426613a78a9e4477071d69dcccd6d4217e5c1d (diff)
parent5eb5e91d7b483edc903ca9c35bdd925d578f45e7 (diff)
downloadrust-eb44c89641f6b570d2ec934f5b43f865b31d7dcb.tar.gz
rust-eb44c89641f6b570d2ec934f5b43f865b31d7dcb.zip
Auto merge of #45946 - estebank:crate-conflict-diag, r=arielb1
Use multiline text for crate conflict diagnostics

After:
```
error[E0464]: multiple matching crates for `libc`
 --> /checkout/src/rustc/dlmalloc_shim/../../dlmalloc/src/linux.rs:1:1
  |
1 | extern crate libc;
  | ^^^^^^^^^^^^^^^^^^
  |
  = note: candidates:
          crate `libc`: /checkout/obj/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-658d35794c10b003.rlib
          crate `libc`: /checkout/obj/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-f32a17a3111b01aa.rlib
```
Before:
```
error[E0464]: multiple matching crates for `libc`
 --> /checkout/src/rustc/dlmalloc_shim/../../dlmalloc/src/linux.rs:1:1
  |
1 | extern crate libc;
  | ^^^^^^^^^^^^^^^^^^
  |
  = note: candidates:
  = note: path: /checkout/obj/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-658d35794c10b003.rlib
  = note: crate name: libc
  = note: path: /checkout/obj/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-f32a17a3111b01aa.rlib
  = note: crate name: libc
```
Diffstat (limited to 'src')
-rw-r--r--src/librustc_metadata/locator.rs169
-rw-r--r--src/test/compile-fail/changing-crates.rs3
-rw-r--r--src/test/compile-fail/svh-change-lit.rs3
-rw-r--r--src/test/compile-fail/svh-change-significant-cfg.rs3
-rw-r--r--src/test/compile-fail/svh-change-trait-bound.rs3
-rw-r--r--src/test/compile-fail/svh-change-type-arg.rs3
-rw-r--r--src/test/compile-fail/svh-change-type-ret.rs3
-rw-r--r--src/test/compile-fail/svh-change-type-static.rs3
-rw-r--r--src/test/compile-fail/svh-use-trait.rs3
-rw-r--r--src/test/run-make/many-crates-but-no-match/Makefile5
10 files changed, 95 insertions, 103 deletions
diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs
index 19f7cb0ee23..8abccb503d6 100644
--- a/src/librustc_metadata/locator.rs
+++ b/src/librustc_metadata/locator.rs
@@ -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();
@@ -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
             }
@@ -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,
diff --git a/src/test/compile-fail/changing-crates.rs b/src/test/compile-fail/changing-crates.rs
index f74855a0849..89310706b52 100644
--- a/src/test/compile-fail/changing-crates.rs
+++ b/src/test/compile-fail/changing-crates.rs
@@ -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() {}
diff --git a/src/test/compile-fail/svh-change-lit.rs b/src/test/compile-fail/svh-change-lit.rs
index 1638caaa923..f24a3905cc3 100644
--- a/src/test/compile-fail/svh-change-lit.rs
+++ b/src/test/compile-fail/svh-change-lit.rs
@@ -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()
diff --git a/src/test/compile-fail/svh-change-significant-cfg.rs b/src/test/compile-fail/svh-change-significant-cfg.rs
index 99523ca699f..7a197fc6ae9 100644
--- a/src/test/compile-fail/svh-change-significant-cfg.rs
+++ b/src/test/compile-fail/svh-change-significant-cfg.rs
@@ -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()
diff --git a/src/test/compile-fail/svh-change-trait-bound.rs b/src/test/compile-fail/svh-change-trait-bound.rs
index dcf4859792d..560feb960f6 100644
--- a/src/test/compile-fail/svh-change-trait-bound.rs
+++ b/src/test/compile-fail/svh-change-trait-bound.rs
@@ -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()
diff --git a/src/test/compile-fail/svh-change-type-arg.rs b/src/test/compile-fail/svh-change-type-arg.rs
index 7e51ca456b2..b8928c09562 100644
--- a/src/test/compile-fail/svh-change-type-arg.rs
+++ b/src/test/compile-fail/svh-change-type-arg.rs
@@ -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()
diff --git a/src/test/compile-fail/svh-change-type-ret.rs b/src/test/compile-fail/svh-change-type-ret.rs
index 54ca87d84c1..14973baafbd 100644
--- a/src/test/compile-fail/svh-change-type-ret.rs
+++ b/src/test/compile-fail/svh-change-type-ret.rs
@@ -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()
diff --git a/src/test/compile-fail/svh-change-type-static.rs b/src/test/compile-fail/svh-change-type-static.rs
index ea90faaf610..cac95b4df8c 100644
--- a/src/test/compile-fail/svh-change-type-static.rs
+++ b/src/test/compile-fail/svh-change-type-static.rs
@@ -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()
diff --git a/src/test/compile-fail/svh-use-trait.rs b/src/test/compile-fail/svh-use-trait.rs
index c0a5a0a17eb..c875fa8a0b2 100644
--- a/src/test/compile-fail/svh-use-trait.rs
+++ b/src/test/compile-fail/svh-use-trait.rs
@@ -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()
diff --git a/src/test/run-make/many-crates-but-no-match/Makefile b/src/test/run-make/many-crates-but-no-match/Makefile
index 239b689b526..0371dff1585 100644
--- a/src/test/run-make/many-crates-but-no-match/Makefile
+++ b/src/test/run-make/many-crates-but-no-match/Makefile
@@ -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)