-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Unsizing coercion does not normalize associated types in structs. #75899
Comments
FWIW, this can be worked around with explicit |
Not sure if I should nominate this for compiler team or lang team, but let's try compiler team first. |
This was discussed during today's compiler meeting removing nomination. @eddyb please feel free to keep the discussion going on Zulip or even re-nominating it if you consider a re-discussion important. |
I'd like to work on this. I haven't worked on the compiler yet, so not sure I'll be able to fix this in a reasonable time. But since it's labelled @rustbot claim |
@WaffleLapkin I'm not sure if that E-easy label is really accurate! That said, you could try to drop by in #wg-traits on Zulip at some point during one of my morning office hours times, if that works for you (9am-10 US Eastern Time, every day but Tuesday), and we could talk it over. |
is this the same as #50213? |
@SoniEx2 yes, that's the same thing, unsize coercion doesn't properly consider associated types. (maybe it's time for me to return to this 👀 ) |
if there's anything we can do to help, feel free to poke us; we want this for uazu/qcell#37. =^-^= |
It's been some time this issue was touched, so let me take a look at it. |
Example code I'd expect to work (playground):
(in case the example above seems artificial, the realistic one I've reduced this from involves using an associated trait to add
Option
around sized types, but notdyn Trait
, sinceOption<dyn Trait>
wouldn't itself work)I'd expect
coerce_newtype
to work because<T as Noop>::Assoc: Unsize<<dyn Trait as Noop>::Assoc>
should hold, after normalization toT: Unsize<dyn Trait>
(which holds here becauseT: Trait
), but nothing performs that normalization before coercion gives up entirely.Unlike
CoerceUnsized
(where I've been wary of associated types in the past), there should be no weird interactions here, we should be able to largely treat thestruct
as a tuple (and we already ensure the type parameter being changed doesn't show up anywhere else in thestruct
, anyway).The
coerce
andcoerce_tuple
examples get to normalize before asking the trait system about anyCoerceUnsized
orUnsized
obligations - I wonder if we could just normalizetrait_pred
here?rust/src/librustc_typeck/check/coercion.rs
Line 603 in 3d6a3ed
But we would have to be careful, because we are in a speculative operation, so we would have to use
normalize_associated_types_in_as_infer_ok
, like this other piece of coercion logic:rust/src/librustc_typeck/check/coercion.rs
Lines 732 to 733 in 3d6a3ed
cc @mystor (author of the
object-provider
crate where this could be useful) @nikomatsakisThe text was updated successfully, but these errors were encountered: