TYPE_ALIAS_BOUNDS in rustc_lint::builtin - Rust
Description: The `type_alias_bounds` lint detects bounds in type aliases.

Skip to main content

## TYPE_ALIAS_BOUNDS

# Static TYPE_ALIAS_BOUNDS

Source

    static TYPE_ALIAS_BOUNDS: &Lint

Expand description

The `type_alias_bounds` lint detects bounds in type aliases.

#### §Example

    type SendVec<T: Send> = Vec<T>;

{{produces}}

#### §Explanation

Trait and lifetime bounds on generic parameters and in where clauses of type aliases are not checked at usage sites of the type alias. Moreover, they are not thoroughly checked for correctness at their definition site either similar to the aliased type.

This is a known limitation of the type checker that may be lifted in a future edition. Permitting such bounds in light of this was unintentional.

While these bounds may have secondary effects such as enabling the use of “shorthand” associated type paths1 and affecting the default trait object lifetime2 of trait object types passed to the type alias, this should not have been allowed until the aforementioned restrictions of the type checker have been lifted.

Using such bounds is highly discouraged as they are actively misleading.

1. I.e., paths of the form `T::Assoc` where `T` is a type parameter bounded by trait `Trait` which defines an associated type called `Assoc` as opposed to a fully qualified path of the form `<T as Trait>::Assoc`. ↩

2. https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes ↩