-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Tracking issue for future-incompatibility lint where_clauses_object_safety #51443
Copy link
Copy link
Closed
Labels
A-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemC-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 RFCT-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.
Metadata
Metadata
Assignees
Labels
A-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemC-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 RFCT-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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Idea
This is the summary issue for the
WHERE_CLAUSES_OBJECT_SAFETYfuture-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 (https://github.com/rust-lang/rfcs/blob/master/text/1122-language-semver.md).What is the warning for?
As was discovered in #50781 a combination of implementing a trait directly for a
dyntype and where clauses involvingSelfcan punch a hole in our dyn-capability rules rules. See the minimization:The fix applied in #50966 is to tighten the dyn-capability rules to make
Xnot dyn-capable in this case, in general making any trait that containsSelfin where clauses not dyn-capable, much like we disallowSelfin arguments or return type. Few root regressions appeared in the crater run and those were fixable, though some crates being unmaintained complicates things.However that fix is heavy handed and disallows things we actually wish to support, still we went ahead with the warning as a stop gap while we look for a better, more targeted fix. The original issue contains some discussion of alternative fixes. With tight chalk integration, we could do some clever things.
Other alternatives discussed for the short-term:
impl Foo for dyn Bar + ..whether that impl is causing trouble. This seems to be a dead end because it's hard to tell whichdyntypes are targeted by a blanket impl such asimpl<U: ?Sized + Bounds> Trait for U.dyn Foo: Traitthen to castTintodyn Foowe require thatT: Traitmust also hold", probably for everyTraitsuch thatSelf: Traitappears in where clauses in the traits methods. This would alleviate the warning forSelf: Traitwhere clauses. This may be practical to implement now, but seems subtle, we'd need to give it more thought.When will this warning become a hard error?
Hopefully we will develop a finer-grained rule and this warning will never be an error.
How to fix this?
Either drop the where clause or stop using
dyntypes with the affected trait. If this is not viable, that's probably ok, it's very unlikely that your code is actually unsound. But please do report your case here so take we may take it into consideration and see how to better support it!