-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Tracking issue for future-incompatibility lint resolve_trait_on_defaulted_unit #39216
Copy link
Copy link
Closed
Labels
C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-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 RFCS-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-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 RFCS-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Idea
This is the summary issue for the
resolve_trait_on_defaulted_unitfuture-compatibility warning and other related errors. The goal of this page is describe why this change was made and how you can fix code that is affected by it. It also provides a place to ask questions or register a complaint if you feel the change should not be made. For more information on the policy around future-compatibility warnings, see our breaking change policy guidelines.What is this lint about
Ordinarily, when a user doesn't specify the type of an expression and the type cannot be inferred, rust will raise an error. For example, consider this code:
Because we haven't specified the type of
_the compiler doesn't know what type of value the user is asking for a default of. And so we get this error:However, due to an unfortunate quirk in Rust's type inference algorithms it is sometimes possible to sneak situations like this past the compiler. In these cases, the unspecified type is defaulted to
(). For an example of this, you can try deserializing an unspecified type with serde:In this case, the code will compile and will deserialize a value of type
().This behaviour is set to change with the eventual rolling-out of
feature(never_type). Where defaulting is still used types will instead default to!. In the best case, code that currently relies on unspecified types defaulting to()will stop compiling. In the worst case, code will continue to compile but may execute differently, as in the above example where a!will be deserialised instead.The
resolve_trait_on_defaulted_unitwarning is raised wherever the compiler thinks your program's behaviour may depend on the current defaulting rules.How to fix this warning/error
Be specific about what type you're using. In the serde example above this could be done by simply adding a type annotation:
Current status
resolve_trait_on_defaulted_unitlint as warn-by-defaultresolve_trait_on_defaulted_unitlint deny-by-defaultresolve_trait_on_defaulted_unitlint a hard error