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

Comments

@95th
Copy link
Contributor

@95th 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
Copy link
Member

@jonas-schievink jonas-schievink 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.

Loading

@95th
Copy link
Contributor Author

@95th 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.

Loading

@jonas-schievink
Copy link
Member

@jonas-schievink jonas-schievink 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.

Loading

@memoryruins
Copy link
Contributor

@memoryruins memoryruins commented Sep 5, 2019

Duplicate of #55022 ?

Loading

@jonas-schievink
Copy link
Member

@jonas-schievink jonas-schievink commented Sep 5, 2019

Yup, closing

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants