You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
so it has something to do with the &str type parameter. But the trick that often fixes problems like this in other places in rust does not help here:
#![feature(impl_trait_in_bindings)]fnmain(){// explicitly annotate the closure arg as &_.// same error as OPconst func:implFn(&str) -> usize = |s:&_| s.parse().unwrap();// not even this helpsconst func:implfor<'a>Fn(&'astr) -> usize = |s:&_| s.parse().unwrap();}
Activity
ExpHP commentedon Oct 22, 2018
Note also that the following works:
so it has something to do with the
&strtype parameter. But the trick that often fixes problems like this in other places in rust does not help here:ilyvion commentedon Oct 1, 2022
Seems this feature doesn't even exist anymore.
traviscross commentedon Apr 28, 2025
We can close this as the feature was pulled out in #86729 and what was added back in #134185 only supports local bindings.