-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Fix trait method resolution on an adjusted never type #156047
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f44f6c
Fix trait method resolution on an adjusted never type
JonathanBrouwer ba62168
Add FCW lint `trait_method_on_coerced_never_type`
JonathanBrouwer e234c7f
Use `sub_unification_table_root_var` instead of `root_var` to check t…
JonathanBrouwer 7074f12
Cleanup lint emitting code
JonathanBrouwer be50f89
Change lint name to METHOD_CALL_ON_DIVERGING_INFER_VAR
JonathanBrouwer 62c7143
Don't run doctest because it doesn't compile on stage1
JonathanBrouwer 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
Some comments aren't visible on the classic Files Changed page.
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
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
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 |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| //! regression test for issue #2151 | ||
| //@ check-pass | ||
| // Regression test for https://github.com/rust-lang/rust/issues/143349 | ||
|
|
||
| fn main() { | ||
| let x = panic!(); //~ ERROR type annotations needed | ||
| let x = panic!(); | ||
| x.clone(); | ||
| //~^ WARN [method_call_on_diverging_infer_var] | ||
| //~| WARN previously accepted | ||
| } |
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 |
|---|---|---|
| @@ -1,16 +1,25 @@ | ||
| error[E0282]: type annotations needed | ||
| --> $DIR/clone-never.rs:4:9 | ||
| warning: method call on a diverging inference variable | ||
| --> $DIR/clone-never.rs:6:7 | ||
| | | ||
| LL | let x = panic!(); | ||
| | ^ | ||
| LL | x.clone(); | ||
| | - type must be known at this point | ||
| | ^^^^^ | ||
| | | ||
| help: consider giving `x` an explicit type | ||
| | | ||
| LL | let x: /* Type */ = panic!(); | ||
| | ++++++++++++ | ||
| = help: consider providing a type annotation | ||
| = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
| = note: for more information, see issue #156047 <https://github.com/rust-lang/rust/issues/156047> | ||
| = note: `#[warn(method_call_on_diverging_infer_var)]` (part of `#[warn(future_incompatible)]`) on by default | ||
|
|
||
| warning: 1 warning emitted | ||
|
|
||
| error: aborting due to 1 previous error | ||
| Future incompatibility report: Future breakage diagnostic: | ||
| warning: method call on a diverging inference variable | ||
| --> $DIR/clone-never.rs:6:7 | ||
| | | ||
| LL | x.clone(); | ||
| | ^^^^^ | ||
| | | ||
| = help: consider providing a type annotation | ||
| = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
| = note: for more information, see issue #156047 <https://github.com/rust-lang/rust/issues/156047> | ||
| = note: `#[warn(method_call_on_diverging_infer_var)]` (part of `#[warn(future_incompatible)]`) on by default | ||
|
|
||
| For more information about this error, try `rustc --explain E0282`. |
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,66 @@ | ||
| //@ check-pass | ||
| // Regression test for https://github.com/rust-lang/rust/issues/143349 | ||
|
|
||
| #![feature(never_type)] | ||
|
|
||
| trait Trait { | ||
| fn method(&self); | ||
| } | ||
| impl Trait for ! { | ||
| fn method(&self) { | ||
| todo!() | ||
| } | ||
| } | ||
|
|
||
| struct Adhoc; | ||
| struct Error; | ||
|
|
||
| #[doc(hidden)] | ||
| trait AdhocKind: Sized { | ||
| #[inline] | ||
| fn anyhow_kind(&self) -> Adhoc { | ||
| Adhoc | ||
| } | ||
| } | ||
|
|
||
| impl<T> AdhocKind for &T where T: ?Sized + Send + Sync + 'static {} | ||
|
|
||
| impl Adhoc { | ||
| #[cold] | ||
| fn new<M>(self, message: M) -> Error | ||
| where | ||
| M: Send + Sync + 'static, | ||
| { | ||
| Error | ||
| } | ||
| } | ||
|
|
||
| fn temp<T>() -> Result<T, ()> { todo!() } | ||
|
|
||
| fn main() -> Result<(), ()> { | ||
| let x = loop {}; | ||
| x.method(); | ||
| //~^ WARN [method_call_on_diverging_infer_var] | ||
| //~| WARN previously accepted | ||
|
|
||
| { loop {} }.method(); | ||
| //~^ WARN [method_call_on_diverging_infer_var] | ||
| //~| WARN previously accepted | ||
|
|
||
| let e = match loop {} { | ||
| y => y.method(), | ||
| //~^ WARN [method_call_on_diverging_infer_var] | ||
| //~| WARN previously accepted | ||
| }; | ||
|
|
||
| let error = match loop {} { | ||
| error => (&error).anyhow_kind().new(error), | ||
| //~^ WARN [method_call_on_diverging_infer_var] | ||
| //~| WARN previously accepted | ||
| }; | ||
|
|
||
| let res = temp()?; | ||
| res.method(); | ||
| //~^ WARN [method_call_on_diverging_infer_var] | ||
| //~| WARN previously accepted | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make a suggestion to go from
x.method()tox as ReturnTypeOfTheMethod?View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gaining access to the return type seems to be quite difficult here, I might give this another try later but any suggestions are appreciated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something can be done by calling
self.probe_for_nameafterself.demand_eqtype, with that you can figure out which method will be called:But I can't quite figure out how to get from that to a type...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to get the type (at least in the simple case where the method return type doesn't depend on any generics), but I don't think this helps, as there doesn't seem to be a way to get the right spans (and in real code it's inside of
anyhow!macro...).