Skip to content

Cannot return never type as impl Trait (like unimplemented!() stub) #71715

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

Closed
ilyavennik opened this issue Apr 30, 2020 · 3 comments
Closed

Cannot return never type as impl Trait (like unimplemented!() stub) #71715

ilyavennik opened this issue Apr 30, 2020 · 3 comments
Labels
C-bug Category: This is a bug.

Comments

@ilyavennik
Copy link

I tried this code:

trait Foo {
    fn foo(&self);
}

impl Foo for i32 {
    fn foo(&self) {
        println!("<Foo as i32>::foo")
    }
}

fn bar() -> impl Foo {
    42
}

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

I expected to see this happen: successful compilation. Instead, this happened: compilation error:

error[E0277]: the trait bound `(): Foo` is not satisfied
  --> src/lib.rs:15:13
   |
15 | fn baz() -> impl Foo {
   |             ^^^^^^^^ the trait `Foo` is not implemented for `()`
16 |     unimplemented!()
   |     ---------------- this returned value is of type `!`
   |
   = note: the return type of a function must have a statically known size

Meta

rustc --version --verbose:

rustc 1.43.0 (4fb7144ed 2020-04-20)
binary: rustc
commit-hash: 4fb7144ed159f94491249e86d5bbd033b5d60550
commit-date: 2020-04-20
host: x86_64-unknown-linux-gnu
release: 1.43.0
LLVM version: 9.0
@ilyavennik ilyavennik added the C-bug Category: This is a bug. label Apr 30, 2020
@jonas-schievink
Copy link
Contributor

Duplicate of #69882

@jonas-schievink jonas-schievink marked this as a duplicate of #69882 Apr 30, 2020
@ilyavennik
Copy link
Author

I looked at that problem. But I still did not understand how I can mark a function as unimplemented.

@jonas-schievink
Copy link
Contributor

I suggest you ask on https://users.rust-lang.org/, since this issue tracker is only really for bug reports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants