Fix trait method resolution on an adjusted never type#156047
Fix trait method resolution on an adjusted never type#156047JonathanBrouwer wants to merge 2 commits intorust-lang:mainfrom
Conversation
|
|
There was a problem hiding this comment.
Note that this PR allows more code to compile on stable, for example see this test.
There was a problem hiding this comment.
If this is a problem we could delay the problem by putting this change behind the never_type feature gate
There was a problem hiding this comment.
I think this a reasonable change, I would expect us to emit a FCW here, I don't want to support this permanently or more importantly, this may overlap with other kinds of inference fallback in the future, so we generally don't want users to rely on this
This comment has been minimized.
This comment has been minimized.
75d6b9a to
d72e38a
Compare
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
d72e38a to
3787326
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| } | ||
|
|
||
| declare_lint! { | ||
| /// The `trait_method_on_coerced_never_type` lint detects situations in which a never type, which |
There was a problem hiding this comment.
I'm really unsure of what the correct terminology is, both for the lint definition and the diagnostic, so please give feedback on this
There was a problem hiding this comment.
IMO the proper way to say it would be "method_call_on_diverging_infer_variable" and "detects situations in which a method is called on a value resulting from a never-to-any coercion, without necessary information to infer a type for it", but I'm not sure how much we want to surface this internal language...
| "detects trait method calls on an coerced never type", | ||
| @future_incompatible = FutureIncompatibleInfo { | ||
| reason: fcw!(FutureReleaseError #156047), | ||
| report_in_deps: true, |
There was a problem hiding this comment.
I decided on a lint with level Warn with report_in_deps: true. If something else is desired, let me know
3787326 to
a8f68d6
Compare
This comment has been minimized.
This comment has been minimized.
a8f68d6 to
2dd2577
Compare
This comment has been minimized.
This comment has been minimized.
2dd2577 to
388ae0f
Compare
| } | ||
|
|
||
| declare_lint! { | ||
| /// The `trait_method_on_coerced_never_type` lint detects situations in which a never type, which |
There was a problem hiding this comment.
IMO the proper way to say it would be "method_call_on_diverging_infer_variable" and "detects situations in which a method is called on a value resulting from a never-to-any coercion, without necessary information to infer a type for it", but I'm not sure how much we want to surface this internal language...
| /// Calling trait methods on a coerced `!` was previously disallowed for the never type, | ||
| /// but it did work for empty enums such as `Infallible` since these don't coerce. | ||
| /// This means that changing the definition of `Infallible` to become a type alias to `!` (a long-term goal), | ||
| /// would break code that called a trait method on `Infallible`, in such a way that the `!` would coerce. | ||
| /// | ||
| /// Therefore, to aid in the transition of changing `Infallible` to a type alias, this is temporarily allowed with a FCW. |
There was a problem hiding this comment.
Please also add a note that calling a method on ! is never useful (it's unreachable code) and propose removing the method call / using the never to any coercion.
Also mention that if people want to support MSRVs before Infallible = !, the proper fix is to match e {} as DesiredType.
View all comments
Fixes #143349
r? @WaffleLapkin
cc @lcnr