Workarounds for #134890
โ Rust ๐ 2026-01-06 ๐ค surdeus ๐๏ธ 4I just ran into Impl has "stricter" requirement that is implied by existing requirement ยท Issue #134890 ยท rust-lang/rust ยท GitHub.
It's pretty silly. Rust Playground
trait Foo {
type Bar;
fn func<'a>() where Self::Bar: 'a;
}
impl<'d, T: ?Sized> Foo for &'d T {
type Bar = &'d ();
fn func<'a>() where Self::Bar: 'a {}
}
// Applying suggested fix for `&'d mut T` still does nothing:
impl<'d, T: ?Sized> Foo for &'d mut T {
type Bar = &'d ();
fn func<'a>() where <Self as Foo>::Bar: 'a {}
}
// Rephrasing trait bound doesn't help:
trait Baz {
type Bar;
fn func<'a>() where &'a Self::Bar:, <Self as Baz>::Bar: 'a;
}
impl<'d, T: ?Sized> Baz for &'d T {
type Bar = &'d ();
fn func<'a>() where &'a Self::Bar:, <Self as Baz>::Bar: 'a {}
}
Seems like you'd need to add a dummy parameter to the trait, which would be annoying for consumers of the trait:
trait Foo<P: ?Sized> {
type Bar;
fn func<'a>() where P: 'a;
}
impl<'d, T: ?Sized> Foo<&'d ()> for &'d T {
type Bar = &'d ();
fn func<'a>() where &'d (): 'a {}
}
If there happen to be any better workarounds, I'd be glad to hear them; otherwise, I just want to call a little attention to that bug.
3 posts - 2 participants
๐ท๏ธ Rust_feed