-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Better error reporting for T: ?Sized
types when impl Receiver for MyType<T>
is implicitly sized
#134390
Comments
Well, if you put that unmet obligation into an |
Unfortunately it doesn't seem to have figured out its way through to the
for this test case. I'll poke at why that's the case. |
On second though, you probably won't have the compiler choose the a specific Receiver impl since there's also a blanket impl for Deref types. |
This does actually appear to be the real issue here. The error message still doesn't provide the hint even when it doesn't originate from an autoderef: #![feature(arbitrary_self_types)]
struct SmartPtr<'a, T: ?Sized>(&'a T);
impl<T> std::ops::Receiver for SmartPtr<'_, T> {
type Target = T;
}
fn takes_receiver(_: impl std::ops::Receiver) {}
fn main() {
let x: SmartPtr<str> = SmartPtr("fooey");
takes_receiver(x)
} gives
Note the lack of a |
Yeah, unfortunately to the compiler it's not obviously clear that we should prefer a more specific impl over a blanket. For the trait solver, if neither impl applies they're basically just... equally invalid. For diagnostics, it seems like a special case that's motivated for this example but could also be misleading in other places, especially when the blanket impls and concrete impls get more complex and "close" to overlapping. |
In that case, I think this issue generalizes to examples like this which have nothing to do with trait MyTrait {}
trait BaseTraitForBlanketImpl {}
struct Wrapper<T>(T);
impl<T: MyTrait> MyTrait for Wrapper<T> {}
impl<T: BaseTraitForBlanketImpl> MyTrait for T {}
fn take_mytrait(_: impl MyTrait) {}
fn main() {
take_mytrait(Wrapper(5));
} generates
but with the non-applicable blanket impl removed, it gives a more specific error:
edit: jinx |
One option would be to prefer impls whose type-without params (e.g. This would also only work for generic record types, not type aliases (because e.g. |
Originally from @adetaylor:
I'm looking for advice on the diagnostics around the
Sized
ness of a receiver, and I'm hoping @estebank can advise (or of course anyone else @wesleywiser @compiler-errors ).The background (for Esteban):
MySmartPtr
, above) which wish to act as method receivers must implement a new traitReceiver
The case I want to generate an error for: see this code but, in short, someone implements
Receiver
forT
but notT: ?Sized
.Questions. Even partial answers to some questions might point me in the right direction.
Overall approach
self
doesn't implementReceiver
. But how can I determine if some missing?Sized
bound is the problem?a. Re-run the resolution process with some simulated fake sized
Self
type? See if the obligation resolves in that case, and if so, show a diagnostic.b. Simulate that some
impl<T> Receiver for T
block is actuallyimpl <T: ?Sized> Receiver for T
, elsewhere in the program or even in another crate. See if the obligation resolves in that case, and if so, show a diagnostic.c. Suggest "ensure any Receiver implementations cover !Sized" without actually checking that this is the problem. This might give lots of false positives.
@adetaylor: I've split this out into its own issue. Let's try to avoid discussion on tracking issues. It's really not the purpose of a tracking issue, and we've locked tracking issues in the past for exactly the same reason (it often pings like... 40 people who are subscribed to the issue).
These days tracking issues carry the note:
The text was updated successfully, but these errors were encountered: