-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
todo! and unimplemented! does not work with impl Trait return types #69882
Comments
This is expected behavior since |
Given that 4 bugs have been opened in such a short period of time for the same reason, I don't think that a wontfix, works as intented is the right approach. At minimum an alternative should be provided in the help message from the compiler, but I personnaly think that |
rust/src/librustc_interface/util.rs Lines 587 to 594 in 567ad74
|
Reopening this to have a canonical issue to direct people to. This is still working as expected for the moment though. |
Actually, let's classify this as a diagnostics enhancement |
Is there any suggested work-around for this? It sure seems like the bottom type ought (by definition) to type-check as anything, but as a practical matter, is there any placeholder at all that can be used as a return value from an unimplemented function whose signature demands an impl trait? |
@jeffs in the general case, no, because there could be no type that implements the trait: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=beb24c95bf6be2a8b48f6381c2b7ad6d |
I don't get what the example shows; you can add |
It shows that it's impossible to return a placeholder type because there might not be a type that impls the trait. |
|
No that wouldn't be enough. The trait might also have associated types or constants, which would have to be implemented as well. |
Error message could definitely be improved. Currently this code: trait Trait {}
fn magic() -> impl Trait {
panic!()
} Results in
Which is really confusing. Using
Why is it not shown in the first case? |
I want to fix this. Unfortunately if you had an I could try to just fix the diagnostic, but it feels like just piling on hacks (the fact that this works if My preferred solution would be to just always error like in the vec case |
A concrete example that would be unsound or at least ICE the compiler is https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ea0e808536f4373dc7be9f002159fa1d If we just didn't register any hidden type, the If we used This gets worse when we'll have type alias impl trait, as then you can directly name the opaque type and access associated items directly without jumping through hoops like in my playground. We could special case |
This code
does not compile because
the trait
SomeTraitis not implemented for ()
But such code
compiles correctly. Can this problem be resolved to use both todo!() and impl Trait?
The text was updated successfully, but these errors were encountered: