-
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
Type inference/resolution error in the presence of Pointee::Metadata in recursive data-structure #111821
Comments
A slightly trimmed example leads to a shorter error message: #![feature(ptr_metadata)]
use core::ptr::Pointee;
struct Node<T> {
element: T,
next: <Node<T> as Pointee>::Metadata,
prev: <Node<T> as Pointee>::Metadata,
} Error message:
|
Regressed in #92248, cc @compiler-errors. Changing the struct's tail makes the error go away: #![feature(ptr_metadata)]
use core::ptr::Pointee;
struct Node<T> {
element: T,
next: <Node<T> as Pointee>::Metadata,
prev: <Node<T> as Pointee>::Metadata,
_tail: (),
} bisect results
|
Yeah, this is basically a cycle that the current trait solver is not smart enough to solve. The struct must be sized for the tail of the struct to resolve (to I'm not sure if this is worth fixing with the current trait solver, since it can be worked around as you said above by adding a dummy struct tail that you know is sized, like For what it's worth, it works in the new trait solver ( |
@compiler-errors I certainly have no problem waiting for the new trait solver, though I fear other people hitting this roadblock may be similarly confused. Do you think it would be worth investing a bit on the diagnostic side in the meantime? If the diagnostics could suggest the work-around, it would make it much more reasonable to just keep it as is for now. Of course, this all depends how soon the new trait solver is slated to come through. If it'll be there in a release or two, it's pointless to invest in the current situation. If it'll be another year before it's there, I think it'd be worthwhile. |
I've heard from @BoxyUwU that it's at least 6 months away and probably closer to a year and a half. |
@compiler-errors @BoxyUwU is there a label for issues that are fixed with -Ztrait-solver=next? if not, I think it makes sense to add one. |
The following code causes the latest nightly (2023-05-16) to choke, it can also be seen on the playground.
Credits to Chayim Friedman for this reduced example.
And the compiler, much confused it appears, spits out the following error:
The compiler accepts the code:
NonNull<E>
inTypedHandle
.?Sized
bound is removed fromE
inTypedHandle
.where NodeHandle<T>: Sized
bound is added onNode
.Given the messages, and the fixes, it appears that the compiler fails to realize that
<E as Pointee>::Metadata
is alwaysSized
, regardless of whetherE
isSized
or not, even thoughMetadata
is necessarilySized
since its bounds do not specify?Sized
. This in turn would lead the compiler to expect thatTypedHandle
may be unsized, and thus reject any code where it is not the last field of a struct.The text was updated successfully, but these errors were encountered: