Skip to content
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

Closed
kennytm opened this issue Sep 29, 2017 · 6 comments
Closed

Purely-diverging functions cannot return impl Trait. #44923

kennytm opened this issue Sep 29, 2017 · 6 comments
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@kennytm
Copy link
Member

kennytm commented Sep 29, 2017

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.

fn do_it_later_but_cannot() -> impl Iterator<Item=u8> { //~ ERROR E0227
    unimplemented!()
}

this fails because ! does not implement Iterator. But I think this should be allowed even without the explicit impl, since ! can be coerced to any concrete type.

@malbarbo
Copy link
Contributor

@kennytm Do you know where the issue of general diverging functions cannot return impl Trait are being tracked?

@kennytm
Copy link
Member Author

kennytm commented Sep 29, 2017

@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”)
    }
}

@malbarbo
Copy link
Contributor

@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:

fn g<T>(t: T) -> Result<impl Iterator<Item=u32>, T>
                        ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `_`

If we change the type to impl Clone, the error changes to:

fn g<T>(t: T) -> Result<impl Clone, T>
                        ^^^^^^^^^^
note: the return type of a function must have a statically known size

It this a know issue? Is this expected?

@TimNN TimNN added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. labels Oct 1, 2017
@Aaron1011
Copy link
Member

I'd like to work on this.

@hanna-kruppe
Copy link
Contributor

this and #36375 are duplicates of each other

@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Apr 9, 2018
@ishitatsuyuki
Copy link
Contributor

I think we can close this as duplicate of #36375?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants