forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#42826 - Yorwba:type-mismatch-same-absolute-…
…paths, r=arielb1 Note different versions of same crate when absolute paths of different types match. The current check to address rust-lang#22750 only works when the paths of the mismatched types relative to the current crate are equal, but this does not always work if one of the types is only included through an indirect dependency. If reexports are involved, the indirectly included path can e.g. [contain private modules](rust-lang#22750 (comment)). This PR takes care of these cases by also comparing the *absolute* path, which is equal if the type hasn't moved in the module hierarchy between versions. A more coarse check would be to compare only the crate names instead of full paths, but that might lead to too many false positives. Additionally, I believe it would be helpful to show where the differing crates came from, i.e. the information in `rustc::middle::cstore::CrateSource`, but I'm not sure yet how to nicely display all of that, so I'm leaving it to a future PR.
- Loading branch information
Showing
5 changed files
with
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | \ | ||
grep -z \ | ||
"mismatched types.*\ | ||
crateB::try_foo(foo2);.*\ | ||
expected struct \`crateA::foo::Foo\`, found struct \`crateA::Foo\`.*\ | ||
different versions of crate \`crateA\`.*\ | ||
mismatched types.*\ | ||
crateB::try_bar(bar2);.*\ | ||
expected trait \`crateA::bar::Bar\`, found trait \`crateA::Bar\`.*\ | ||
different versions of crate \`crateA\`" |
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,26 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
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}; |
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,14 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
extern crate crateA; | ||
|
||
pub fn try_foo(x: crateA::Foo){} | ||
pub fn try_bar(x: Box<crateA::Bar>){} |
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,35 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// 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 | ||
// compile-fail/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 reexport. | ||
// 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); | ||
} | ||
} |