-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distinguish crates with the same name in type errors
Previously, errors for crates with the same name would only distinguish them by the span of the source: ``` note: `HashMap<_, _, _, _>` is defined in crate `hashbrown` --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.12.3/src/map.rs:188:1 note: `HashMap<u32, u32>` is defined in crate `hashbrown` --> /Users/jyn/.local/lib/cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.12.3/src/map.rs:188:1 ``` When the same version of the crate is loaded twice, this isn't particularly helpful. Additionally show where the .rlib was loaded from (in this case one was loaded from the sysroot and the other from a cargo target dir).
- Loading branch information
Showing
7 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Test that we emit useful diagnostics when the same crate is loaded from the sysroot and --extern. | ||
# This can't be a run-make test because it needs the aux-file to itself have a dependency passed with --extern | ||
# (and just bare `--extern hashbrown` errors too early, while compiling `uses_hashbrown.rs`). | ||
|
||
include ../tools.mk | ||
define SED_REGEX | ||
s#[^ ]*registry/src/index.crates.io[^ ]*/src#CARGO_REGISTRY/hashbrown-VERSION/src#; | ||
s#[^ ]*/build/[^ ]*/lib/rustlib/[^ ]*#BUILD_DIR/HOST/stageN/lib/rustlib/TARGET/lib/libhashbrown.rlib#; | ||
s#[^ ]*/build/[^ ]*/test/run-make/#BUILD_DIR/HOST/test/run-make/# | ||
s#[^ ]*tests/run-make/#TEST_DIR/# | ||
endef | ||
export SED_REGEX | ||
|
||
all: | ||
$(RUSTC) hashbrown.rs --crate-type lib | ||
$(RUSTC) uses-hashbrown.rs --extern hashbrown=$(TMPDIR)/libhashbrown.rlib --crate-type lib | ||
$(RUSTC) mismatch.rs --extern uses_hashbrown=$(TMPDIR)/libuses_hashbrown.rlib 2>$(TMPDIR)/stderr.txt || true | ||
sed -e "$$SED_REGEX" < $(TMPDIR)/stderr.txt > $(TMPDIR)/normalized.txt | ||
$(RUSTC_TEST_OP) $(TMPDIR)/normalized.txt expected.txt | ||
$(CGREP) "loaded from" < $(TMPDIR)/stderr.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
error[E0308]: mismatched types | ||
--> mismatch.rs:5:25 | ||
| | ||
5 | uses_hashbrown::foo(hashbrown::HashMap::default()) | ||
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `HashMap`, found `HashMap<_, _, _, _>` | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: `hashbrown::HashMap<_, _, _, _>` and `hashbrown::HashMap` have similar names, but are actually distinct types | ||
note: `hashbrown::HashMap<_, _, _, _>` is defined in crate `hashbrown` | ||
--> CARGO_REGISTRY/hashbrown-VERSION/src/map.rs:190:1 | ||
| | ||
190 | pub struct HashMap<K, V, S = DefaultHashBuilder, A: Allocator = Global> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: `hashbrown` was loaded from BUILD_DIR/HOST/stageN/lib/rustlib/TARGET/lib/libhashbrown.rlib | ||
note: `hashbrown::HashMap` is defined in crate `hashbrown` | ||
--> TEST_DIR/type-mismatch-sysroot-crate/hashbrown.rs:4:1 | ||
| | ||
4 | pub struct HashMap; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
= note: `hashbrown` was loaded from BUILD_DIR/HOST/test/run-make/type-mismatch-sysroot-crate/type-mismatch-sysroot-crate/libhashbrown.rlib | ||
= note: perhaps two different versions of crate `hashbrown` are being used? | ||
note: function defined here | ||
--> TEST_DIR/type-mismatch-sysroot-crate/uses-hashbrown.rs:1:8 | ||
| | ||
1 | pub fn foo(_: hashbrown::HashMap) {} | ||
| ^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub struct HashMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![feature(rustc_private)] | ||
extern crate hashbrown; | ||
|
||
fn main() { | ||
uses_hashbrown::foo(hashbrown::HashMap::default()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub fn foo(_: hashbrown::HashMap) {} |