-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking Issue for Rust 2024: Make ! fall back to ! #123748
Copy link
Copy link
Closed
Labels
A-edition-2024Area: The 2024 editionArea: The 2024 editionC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-never_type`#![feature(never_type)]``#![feature(never_type)]`S-tracking-ready-for-editionStatus: This issue is ready for inclusion in the edition.Status: This issue is ready for inclusion in the edition.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-edition-2024Area: The 2024 editionArea: The 2024 editionC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-never_type`#![feature(never_type)]``#![feature(never_type)]`S-tracking-ready-for-editionStatus: This issue is ready for inclusion in the edition.Status: This issue is ready for inclusion in the edition.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is a tracking issue for the change to make fallback fall back from
!to!(rather than to()) in Rust 2024. This is part of a plan that leads to eventually stabilizing the never (!) type.What this change means
This change means that
!does not spontaneously decay to(). For example, consider this code:todo!()"returns"!, but before this change this!decayed to()when being returned from the closure. In general, this can happen at any coercion site, if the type is not set by something else.If your code is broken with errors like
`!: Trait` is not satisfied, then you need to make sure the type is specified explicitly. For example:Before this change
!fromreturndecays to(), meaning thatcreate_zstwill also return(), and since()implementsFrom<()>this was fine. With this change however,!fromreturnkeeps being!and inference makescreate_zstalso return!, however!does not implementFrom<()>causing a compilation error.The easiest fix is to specify the type explicitly:
However, this can also be a sign that you don't care what the type is, and maybe the better solution is to refactor the code.
Also note that this "create something or return" pattern can also be caused by
?with code like this:Because
deserialize's output type is not bound to be anything, it gets inferred from?'s desugaring that includes areturn. (there is a separate initiative to stop?from affecting inference like this: #122412)About tracking issues
Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
!fall back to!#123508unsafefunctions.?guiding inference.!'s docs #124419Unresolved Questions
unsafefunction)deny-by-defaultor a hard error in Rust 2024.NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFEa deny-by-default lint in edition 2024 #126881Related
!#123482!fall back to!#123508NeverToAny#123571!'s docs #124419DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK#126367NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFEa deny-by-default lint in edition 2024 #126881