-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Allow shortening lifetime in CoerceUnsized for &mut #149219
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
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
|
I don't quite understand the errors here... |
|
IIUC, the errors are because when implementing https://github.com/rust-lang/rust/blob/94b49fd998d6723e0a9240a7cff5f9df37b84dd8/compiler/rustc_hir_analysis/src/coherence/builtin.rs#L485-502 (the error is produced on line 557, lines 485-492 describe the check) Since rust/compiler/rustc_hir_analysis/src/coherence/builtin.rs Lines 522 to 533 in 94b49fd
|
This modifies the &mut -> &mut CoerceUnsized impl so that, it can
shorten the lifetime.
Note that there are already two impls that allow shortening the lifetime
like this (the &mut T -> &U and the &T -> &U impls). So this change
makes the impls consistent with each other.
I initially tried to also do the same to the CoerceUnsized impl for
core::cell::{Ref, RefMut}. However, this can't be done because
Ref and RefMut "store" the lifetime and the data in different fields,
and CoerceUnsized can only coerce one field.
I don't know if there is a visible effect in stable code or not.
6bfef63 to
cfcd9bf
Compare
|
I changed the PR to just edit the impl for |
This modifies the &mut -> &mut CoerceUnsized impl so that, it can shorten the lifetime.
Note that there are already two impls that allow shortening the lifetime like this (the &mut T -> &U and the &T -> &U impls). So this change makes the impls consistent with each other.
I initially tried to also do the same to the CoerceUnsized impl for core::cell::{Ref, RefMut}. However, this can't be done because Ref and RefMut "store" the lifetime and the data in different fields, and CoerceUnsized can only coerce one field.
I don't know if there is a visible effect in stable code or not.