-
Notifications
You must be signed in to change notification settings - Fork 13.4k
impl Trait cannot work well with lifetime bounds #66551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You could workaround using the pub trait Captures<U: ?Sized> {}
impl<U: ?Sized, T: ?Sized> Captures<U> for T {}
impl<'t> S<'t> {
pub fn foo(&mut self) -> impl FnMut() + Captures<&'t str> + '_ {
move || self.0 += 1
}
} |
Could the |
The pub fn foo<'s>(&'s mut self) -> impl FnMut() + use<'s, 't> {
move || self.0 += 1
} And I think even that much gets erased in the 2024 edition, where it's implicit. (I'm coming back to this old bug because my use of the Captures trait linked back to this issue, and I am joyfully replacing that usage. :]) |
Current output:
|
I've been using the |
Playground
The
self: &'s mut S<'t>
implies't: 's
, so the signature should be correct. But compiler still complain that't
is captured but does not appear inimpl
bounds.I checked the error description of
E0700
and triedimpl FnMut() + 's where 't: 's
andimpl FnMut() + 's + 't
, while it still fails.Note that when using
dyn Trait
aspub fn foo<'s>(&'s mut self) -> Box<dyn FnMut() + 's>
, it compiles.The text was updated successfully, but these errors were encountered: