Skip to content

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

@nroi

Description

@nroi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions