-
Notifications
You must be signed in to change notification settings - Fork 13.8k
compiler: Hint at multiple crate versions if trait impl is for wrong ADT #146874
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
Merged
+168
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 Foo; |
This file contains hidden or 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 Foo; |
This file contains hidden or 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,15 @@ | ||
struct Bar; | ||
|
||
impl From<Bar> for foo::Foo { | ||
fn from(_: Bar) -> Self { | ||
foo::Foo | ||
} | ||
} | ||
|
||
fn main() { | ||
// The user might wrongly expect this to work since From<Bar> for Foo | ||
// implies Into<Foo> for Bar. What the user missed is that different | ||
// versions of Foo exist in the dependency graph, and the impl is for the | ||
// wrong version. | ||
re_export_foo::into_foo(Bar); | ||
} |
This file contains hidden or 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,24 @@ | ||
error[E0277]: the trait bound `re_export_foo::foo::Foo: From<Bar>` is not satisfied | ||
--> main.rs:14:29 | ||
| | ||
LL | re_export_foo::into_foo(Bar); | ||
| ----------------------- ^^^ the trait `From<Bar>` is not implemented for `re_export_foo::foo::Foo` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
help: item with same name found | ||
--> $DIR/foo-v1.rs:1:1 | ||
| | ||
LL | pub struct Foo; | ||
| ^^^^^^^^^^^^^^ | ||
= note: perhaps two different versions of crate `foo` are being used? | ||
= note: required for `Bar` to implement `Into<re_export_foo::foo::Foo>` | ||
note: required by a bound in `into_foo` | ||
--> $DIR/re-export-foo.rs:3:25 | ||
| | ||
LL | pub fn into_foo(_: impl Into<foo::Foo>) {} | ||
| ^^^^^^^^^^^^^^ required by this bound in `into_foo` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains hidden or 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,3 @@ | ||
pub use foo; | ||
|
||
pub fn into_foo(_: impl Into<foo::Foo>) {} |
This file contains hidden or 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,45 @@ | ||
//@ needs-target-std | ||
|
||
use run_make_support::{Rustc, cwd, diff, rust_lib_name, rustc}; | ||
|
||
fn rustc_with_common_args() -> Rustc { | ||
let mut rustc = rustc(); | ||
rustc.remap_path_prefix(cwd(), "$DIR"); | ||
rustc.edition("2018"); // Don't require `extern crate` | ||
rustc | ||
} | ||
|
||
fn main() { | ||
rustc_with_common_args() | ||
.input("foo-v1.rs") | ||
.crate_type("rlib") | ||
.crate_name("foo") | ||
.extra_filename("-v1") | ||
.metadata("-v1") | ||
.run(); | ||
|
||
rustc_with_common_args() | ||
.input("foo-v2.rs") | ||
.crate_type("rlib") | ||
.crate_name("foo") | ||
.extra_filename("-v2") | ||
.metadata("-v2") | ||
.run(); | ||
|
||
rustc_with_common_args() | ||
.input("re-export-foo.rs") | ||
.crate_type("rlib") | ||
.extern_("foo", rust_lib_name("foo-v2")) | ||
.run(); | ||
|
||
let stderr = rustc_with_common_args() | ||
.input("main.rs") | ||
.extern_("foo", rust_lib_name("foo-v1")) | ||
.extern_("re_export_foo", rust_lib_name("re_export_foo")) | ||
.library_search_path(cwd()) | ||
.ui_testing() | ||
.run_fail() | ||
.stderr_utf8(); | ||
|
||
diff().expected_file("main.stderr").normalize(r"\\", "/").actual_text("(rustc)", &stderr).run(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.