-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Should bounds on mut trait objects be covariant? #14985
Comments
cc me |
1 similar comment
cc me |
Actually, I was thinking: if we were to permit multiple arbitrary traits (as I would eventually like to do) to occur in object expressions, then it is not clear that |
triage: P-backcompat-lang (1.0 beta) |
Forgot about this little corner case. Hopefully now that #18737 is closed this should be easier to fix. |
Let me elaborate my plan (which... so far ... seems to be working). Just removing the subtype relation alone breaks code because various bits of code rely on the ability to upcast the region bound (i.e., |
for `&mut (Trait+'a)` to `&mut (Trait+'b)` if `'a:'b`. Fixes rust-lang#14985.
…ping Remove incorrect subtyping for `&mut Trait` and introduce coercion for `&mut (Trait+'a)` to `&mut (Trait+'b)` if `'a:'b`. Fixes rust-lang#14985. r? @nrc
Currently if
Trait1
andTrait2
are traits, then&mut Trait1+Trait2 <: &mut Trait1
. I.e., mutable trait objects are covariant. All other mutable references are invariant, that is&mut T <: &mut T'
iffT /equiv T'
.Should trait objects also be invariant?
See also #12470, which is a similar issue but about lifetimes in the same situation (which must be invariant and not contravariant).
The text was updated successfully, but these errors were encountered: