pub static OPAQUE_HIDDEN_INFERRED_BOUND: &Lint
Expand description

The opaque_hidden_inferred_bound lint detects cases in which nested impl Trait in associated type bounds are not written generally enough to satisfy the bounds of the associated type.

Explanation

This functionality was removed in #97346, but then rolled back in #99860 because it caused regressions.

We plan on reintroducing this as a hard error, but in the mean time, this lint serves to warn and suggest fixes for any use-cases which rely on this behavior.

Example

trait Duh {}

impl Duh for i32 {}

trait Trait {
    type Assoc: Duh;
}

struct Struct;

impl<F: Duh> Trait for F {
    type Assoc = F;
}

fn test() -> impl Trait<Assoc = impl Sized> {
    42
}

{{produces}}

In this example, test declares that the associated type Assoc for impl Trait is impl Sized, which does not satisfy the Send bound on the associated type.

Although the hidden type, i32 does satisfy this bound, we do not consider the return type to be well-formed with this lint. It can be fixed by changing impl Sized into impl Sized + Send.