-
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
Purely-diverging functions cannot return impl Trait
.
#44923
Comments
@kennytm Do you know where the issue of general diverging functions cannot return |
@malbarbo there’s no problem returning “general diverging functions”, if you mean something like this: fn foo() -> impl Bar {
if bar() {
Baz::new()
} else {
panic!(“diverge”)
}
} |
@kennytm Yes, I mean that. But I asked because I remembered vaguely some limitations that I had encountered in the past. Looking at my old code, the limitation was not that... sorry. The limitation is this: fn g<T>(t: T) -> Result<impl Iterator<Item=u32>, T> {
Err(t)
} fails to compile with error:
If we change the type to
It this a know issue? Is this expected? |
I'd like to work on this. |
this and #36375 are duplicates of each other |
I think we can close this as duplicate of #36375? |
Originally reported in #34511 (comment), separated out to make it easier to track. #43869 and #44731 are examples caused by this issue.
If a function is purely diverging, any part of the return type cannot contain
impl Trait
, e.g.this fails because
!
does not implementIterator
. But I think this should be allowed even without the explicit impl, since!
can be coerced to any concrete type.The text was updated successfully, but these errors were encountered: