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

Provide more information on duplicate lang item error. #73449

Merged
merged 2 commits into from
Jul 2, 2020
Merged
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
2 changes: 2 additions & 0 deletions src/librustc_metadata/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
@@ -239,6 +239,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,

syms
}

crate_extern_paths => { cdata.source().paths().cloned().collect() }
}

pub fn provide(providers: &mut Providers<'_>) {
4 changes: 4 additions & 0 deletions src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1042,6 +1042,10 @@ rustc_queries! {
eval_always
desc { "looking up the extra filename for a crate" }
}
query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
eval_always
desc { "looking up the paths for extern crates" }
}
}

TypeChecking {
1 change: 1 addition & 0 deletions src/librustc_middle/ty/query/mod.rs
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ use rustc_span::{Span, DUMMY_SP};
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::ops::Deref;
use std::path::PathBuf;
use std::sync::Arc;

#[macro_use]
22 changes: 22 additions & 0 deletions src/librustc_passes/lang_items.rs
Original file line number Diff line number Diff line change
@@ -146,6 +146,28 @@ impl LanguageItemCollector<'tcx> {
));
}
}
let mut note_def = |which, def_id: DefId| {
let crate_name = self.tcx.crate_name(def_id.krate);
let note = if def_id.is_local() {
format!("{} definition in the local crate (`{}`)", which, crate_name)
} else {
let paths: Vec<_> = self
.tcx
.crate_extern_paths(def_id.krate)
.iter()
.map(|p| p.display().to_string())
.collect();
format!(
"{} definition in `{}` loaded from {}",
which,
crate_name,
paths.join(", ")
)
};
err.note(&note);
};
note_def("first", original_def_id);
note_def("second", item_def_id);
}
err.emit();
}
1 change: 1 addition & 0 deletions src/test/ui/duplicate_entry_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// normalize-stderr-test "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
// note-pattern: first defined in crate `std`.

// Test for issue #31788 and E0152
4 changes: 3 additions & 1 deletion src/test/ui/duplicate_entry_error.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0152]: found duplicate lang item `panic_impl`
--> $DIR/duplicate_entry_error.rs:10:1
--> $DIR/duplicate_entry_error.rs:11:1
|
LL | / fn panic_impl(info: &PanicInfo) -> ! {
LL | |
@@ -8,6 +8,8 @@ LL | | }
| |_^
|
= note: the lang item is first defined in crate `std` (which `duplicate_entry_error` depends on)
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
= note: second definition in the local crate (`duplicate_entry_error`)

error: aborting due to previous error

1 change: 1 addition & 0 deletions src/test/ui/error-codes/E0152.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// normalize-stderr-test "loaded from .*liballoc-.*.rlib" -> "loaded from SYSROOT/liballoc-*.rlib"
#![feature(lang_items)]

#[lang = "owned_box"]
4 changes: 3 additions & 1 deletion src/test/ui/error-codes/E0152.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
error[E0152]: found duplicate lang item `owned_box`
--> $DIR/E0152.rs:4:1
--> $DIR/E0152.rs:5:1
|
LL | struct Foo;
| ^^^^^^^^^^^
|
= note: the lang item is first defined in crate `alloc` (which `std` depends on)
= note: first definition in `alloc` loaded from SYSROOT/liballoc-*.rlib
= note: second definition in the local crate (`E0152`)

error: aborting due to previous error

1 change: 1 addition & 0 deletions src/test/ui/panic-handler/panic-handler-std.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// normalize-stderr-test "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
// error-pattern: found duplicate lang item `panic_impl`


6 changes: 4 additions & 2 deletions src/test/ui/panic-handler/panic-handler-std.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
error[E0152]: found duplicate lang item `panic_impl`
--> $DIR/panic-handler-std.rs:7:1
--> $DIR/panic-handler-std.rs:8:1
|
LL | / fn panic(info: PanicInfo) -> ! {
LL | | loop {}
LL | | }
| |_^
|
= note: the lang item is first defined in crate `std` (which `panic_handler_std` depends on)
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
= note: second definition in the local crate (`panic_handler_std`)

error: argument should be `&PanicInfo`
--> $DIR/panic-handler-std.rs:7:16
--> $DIR/panic-handler-std.rs:8:16
|
LL | fn panic(info: PanicInfo) -> ! {
| ^^^^^^^^^