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

unimplemented macro doesnt compile with RPIT #63794

Closed
95th opened this issue Aug 21, 2019 · 5 comments
Closed

unimplemented macro doesnt compile with RPIT #63794

95th opened this issue Aug 21, 2019 · 5 comments
Labels
A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@95th
Copy link
Contributor

95th commented Aug 21, 2019

I believe the following should compile but doesn't.

trait Foo {}

fn bar() -> impl Foo {
    unimplemented!()
}

I get the following error:

 --> src/main.rs:7:13
  |
7 | fn bar() -> impl Foo {
  |             ^^^^^^^^ the trait `Foo` is not implemented for `()`
  |
  = note: the return type of a function must have a statically known size

However, this compiles:

fn bar<X: Foo>() -> X {
    unimplemented!()
}

Could anybody confirm if this is a bug or I am missing something very obvious?

@jonas-schievink jonas-schievink added A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Aug 21, 2019
@jonas-schievink
Copy link
Contributor

This isn't really a bug, at least. The type impl Foo stands for needs to be inferred somehow, and right now the compiler defaults to () in this situation. With #![feature(never_type)] it would default to !, with the same result (right now).

In the second example, the type is just a type parameter specified by the caller, so no issue occurs.

@95th
Copy link
Contributor Author

95th commented Aug 22, 2019

@jonas-schievink The compiler shouldn't default to () for impl Foo. So doesn't that make it a bug?
Also, with never type !, the trait bound !: Foo is not satisfied.

This would mean that you can't leave functions having impl trait return types unimplemented.

@jonas-schievink
Copy link
Contributor

What type should it choose, then? I don't think this is an easy question to answer in all cases.

Diverging control flow (which is what you get after a panic) can generally be of any type, since the code is unreachable. Rustc falls back to assigning () if there is no known, concrete type to assign (this has been the case since before 1.0, I believe). This doesn't really have much to do with impl Trait, specifically.

That said, it would be nice to get this example working somehow, since unimplemented!() would be quite useful.

@memoryruins
Copy link
Contributor

Duplicate of #55022 ?

@jonas-schievink
Copy link
Contributor

Yup, closing

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-feature-request Category: A feature request, i.e: not implemented / a PR. 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

3 participants