Closed
Description
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
Labels
No labels