Workarounds for #134890

โš“ Rust    ๐Ÿ“… 2026-01-06    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 4      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Workarounds for #134890

I 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

Read full topic

๐Ÿท๏ธ Rust_feed