Closed
Description
The following compiles just fine:
#![feature(impl_trait_in_bindings)]
fn main() {
let func: impl Fn(&str) -> usize = |s| s.parse().unwrap();
}
However this does not:
#![feature(impl_trait_in_bindings)]
fn main() {
const func: impl Fn(&str) -> usize = |s| s.parse().unwrap();
}
It gives the following error message:
error: non-defining existential type use in defining scope
--> src/main.rs:4:42
|
4 | const func: impl Fn(&str) -> usize = |s| s.parse().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^ lifetime `` is part of concrete type but not used in parameter list of existential type
error: aborting due to previous error
error: Could not compile `playground`.
Why is this an error? The closure does not capture anything, so it's lifetime is 'static
, and const requires 'static
.