diff options
Diffstat (limited to 'src/test/run-make-fulldeps/type-mismatch-same-crate-name')
4 files changed, 64 insertions, 0 deletions
diff --git a/src/test/run-make-fulldeps/type-mismatch-same-crate-name/Makefile b/src/test/run-make-fulldeps/type-mismatch-same-crate-name/Makefile new file mode 100644 index 000000000..802b3df46 --- /dev/null +++ b/src/test/run-make-fulldeps/type-mismatch-same-crate-name/Makefile @@ -0,0 +1,19 @@ +-include ../tools.mk + +all: + # compile two different versions of crateA + $(RUSTC) --crate-type=rlib crateA.rs -C metadata=-1 -C extra-filename=-1 + $(RUSTC) --crate-type=rlib crateA.rs -C metadata=-2 -C extra-filename=-2 + # make crateB depend on version 1 of crateA + $(RUSTC) --crate-type=rlib crateB.rs --extern crateA=$(TMPDIR)/libcrateA-1.rlib + # make crateC depend on version 2 of crateA + $(RUSTC) crateC.rs --extern crateA=$(TMPDIR)/libcrateA-2.rlib 2>&1 | \ + tr -d '\r\n' | $(CGREP) -e \ + "mismatched types.*\ + crateB::try_foo\(foo2\);.*\ + expected struct \`crateA::foo::Foo\`, found struct \`Foo\`.*\ + different versions of crate \`crateA\`.*\ + mismatched types.*\ + crateB::try_bar\(bar2\);.*\ + expected trait \`crateA::bar::Bar\`, found trait \`Bar\`.*\ + different versions of crate \`crateA\`" diff --git a/src/test/run-make-fulldeps/type-mismatch-same-crate-name/crateA.rs b/src/test/run-make-fulldeps/type-mismatch-same-crate-name/crateA.rs new file mode 100644 index 000000000..4871c8c2e --- /dev/null +++ b/src/test/run-make-fulldeps/type-mismatch-same-crate-name/crateA.rs @@ -0,0 +1,16 @@ +mod foo { + pub struct Foo; +} + +mod bar { + pub trait Bar{} + + pub fn bar() -> Box<Bar> { + unimplemented!() + } +} + +// This makes the publicly accessible path +// differ from the internal one. +pub use foo::Foo; +pub use bar::{Bar, bar}; diff --git a/src/test/run-make-fulldeps/type-mismatch-same-crate-name/crateB.rs b/src/test/run-make-fulldeps/type-mismatch-same-crate-name/crateB.rs new file mode 100644 index 000000000..24fcc7cad --- /dev/null +++ b/src/test/run-make-fulldeps/type-mismatch-same-crate-name/crateB.rs @@ -0,0 +1,4 @@ +extern crate crateA; + +pub fn try_foo(x: crateA::Foo){} +pub fn try_bar(x: Box<crateA::Bar>){} diff --git a/src/test/run-make-fulldeps/type-mismatch-same-crate-name/crateC.rs b/src/test/run-make-fulldeps/type-mismatch-same-crate-name/crateC.rs new file mode 100644 index 000000000..71b38a9f8 --- /dev/null +++ b/src/test/run-make-fulldeps/type-mismatch-same-crate-name/crateC.rs @@ -0,0 +1,25 @@ +// This tests the extra note reported when a type error deals with +// seemingly identical types. +// The main use case of this error is when there are two crates +// (generally different versions of the same crate) with the same name +// causing a type mismatch. + +// The test is nearly the same as the one in +// ui/type/type-mismatch-same-crate-name.rs +// but deals with the case where one of the crates +// is only introduced as an indirect dependency. +// and the type is accessed via a re-export. +// This is similar to how the error can be introduced +// when using cargo's automatic dependency resolution. + +extern crate crateA; + +fn main() { + let foo2 = crateA::Foo; + let bar2 = crateA::bar(); + { + extern crate crateB; + crateB::try_foo(foo2); + crateB::try_bar(bar2); + } +} |