Update the description of lint type_alias_bounds

This commit is contained in:
León Orell Valerian Liehr 2024-06-16 15:53:01 +02:00
parent d67b61637e
commit 5859dff742
No known key found for this signature in database
GPG Key ID: D17A07215F68E713

View File

@ -1390,20 +1390,32 @@ declare_lint! {
///
/// ### Explanation
///
/// The trait bounds in a type alias are currently ignored, and should not
/// be included to avoid confusion. This was previously allowed
/// unintentionally; this may become a hard error in the future.
/// 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 paths[^1] and affecting the default trait
/// object lifetime[^2] 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>
TYPE_ALIAS_BOUNDS,
Warn,
"bounds in type aliases are not enforced"
}
declare_lint_pass!(
/// Lint for trait and lifetime bounds in type aliases being mostly ignored.
/// They are relevant when using associated types, but otherwise neither checked
/// at definition site nor enforced at use site.
TypeAliasBounds => [TYPE_ALIAS_BOUNDS]
);
declare_lint_pass!(TypeAliasBounds => [TYPE_ALIAS_BOUNDS]);
impl TypeAliasBounds {
pub(crate) fn affects_object_lifetime_defaults(pred: &hir::WherePredicate<'_>) -> bool {