Idea: "Maybe Trait" Object and Bounds (an alternative form of specialization)

Ah, I see. It hadn't occured to me that whether a trait is implemented for a type or not could depend on a lifetime. Perhaps because I don't think I have ever written such a trait impl myself. Presumably:

impl<'a> Bar for &'a u32 {}
fn func<T: ~Bar>(t: T) -> bool {
    t.implements::<Bar>()
}

would also work, as the trait is implemented for all possible lifetimes.

If so, then I agree with your assessment that this would be good enough for the vast majority of use cases. It would probably require a bit of effort to be put into the error messages to explain the situation, but that's nothing new for rustc :slight_smile:

I think it would need to be impl Bar for for<'a> T<'a> {} (which isn't possible spelled this way at least; the closest I could get to work is impl<T: for<'a> Lt<'a>> Bar for T {} where Lt<'a> is another trait) because Bar could have a method that works on 'a and that feels like an easy "not sound" determination to me at least.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.