Skip to content

Commit

Permalink
Update the description of lint type_alias_bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Jul 22, 2024
1 parent d67b616 commit 5859dff
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5859dff

Please sign in to comment.