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

Suggested fix for E0759 does not compile (rustc --explain E0759) #86061

Closed
nroi opened this issue Jun 6, 2021 · 0 comments · Fixed by #86077
Closed

Suggested fix for E0759 does not compile (rustc --explain E0759) #86061

nroi opened this issue Jun 6, 2021 · 0 comments · Fixed by #86077

Comments

@nroi
Copy link

nroi commented Jun 6, 2021

I ran into the compiler error E0759, so I entered the following to gain more information:

rustc --explain E0759

The explanation page shows the following code snippet, suggested as a fix:

fn foo(x: &i32) -> impl Debug + 'static { // ok!
    x
}

But the code snippet does not compile. When I create the following main.rs file:

use std::fmt::Debug;

fn foo(x: &i32) -> impl Debug + 'static { // ok!
    x
}

fn main() {
    println!("Hello, world!");
}

then compilation fails with the message

error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement.

Since the code snippet is a suggested fix, I would have expected this code to compile without issues.

I have tried this with the current nightly version:

rustc --version --verbose:

rustc 1.54.0-nightly (6c2dd251b 2021-06-05)
binary: rustc
commit-hash: 6c2dd251bbff03c7a3092d43fb5b637eca0810e3
commit-date: 2021-06-05
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 6, 2021
…eGomez

Fix corrected example in E0759.md

This pull request fixes rust-lang#86061, which was probably caused by a copy-paste error, where the supposedly corrected code example was also marked with `compile_fail`. Thus, the fact that the "correct" example actually _isn't_ correct was not caught by the doc-tests. This pull request removes the incorrect `compile_fail` annotation and fixes the example.

r? `@GuillaumeGomez`
@bors bors closed this as completed in 487200b Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant