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

Comments

@95th
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

commented Aug 21, 2019

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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Member

commented Aug 22, 2019

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

This comment has been minimized.

Copy link
Contributor

commented Sep 5, 2019

Duplicate of #55022 ?

@jonas-schievink

This comment has been minimized.

Copy link
Member

commented Sep 5, 2019

Yup, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.