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
{{ message }}
Repository navigation
impl FnOnce hidden type captures more than the closure itself #124413
I expected both methods to compile, but only the dyn version does.
The error says:
error[E0700]: hidden type for `impl FnOnce() -> i32 + '_` captures lifetime that does not appear in bounds
--> src/lib.rs:13:9
|
8 | impl<'a> Foo<'a> {
| -- hidden type `{closure@src/lib.rs:13:9: 13:11}` captures the lifetime `'a` as defined here
...
12 | fn doent(&self) -> impl FnOnce() -> i32 + '_ {
| ------------------------- opaque type defined here
13 | || self.value
| ^^^^^^^^^^^^^
The error says that the closure captures lifetime 'a, although the closure in the dyn version is the same and compiles successfully without capturing 'a
It compiles on nightly if you add #![feature(lifetime_capture_rules_2024)], so this is probably the expected (if surprising) behavior of lifetime capture rules in return-position impl Traits. At least until the 2024 edition.
Activity
ryanavella commentedon Apr 27, 2024
It compiles on nightly if you add
#![feature(lifetime_capture_rules_2024)], so this is probably the expected (if surprising) behavior of lifetime capture rules in return-positionimpl Traits. At least until the 2024 edition.Related: #117587, rust-lang/rfcs#3498
compiler-errors commentedon Jan 3, 2025
Nightly suggests adding
+ use<'_, 'a>, so I think this is fixed.