Skip to content

Commit d193e75

Browse files
committed
Update the description of lint type_alias_bounds
1 parent f6d96c2 commit d193e75

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

Diff for: compiler/rustc_lint/src/builtin.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -1459,20 +1459,32 @@ declare_lint! {
14591459
///
14601460
/// ### Explanation
14611461
///
1462-
/// The trait bounds in a type alias are currently ignored, and should not
1463-
/// be included to avoid confusion. This was previously allowed
1464-
/// unintentionally; this may become a hard error in the future.
1462+
/// Trait and lifetime bounds on generic parameters and in where clauses of
1463+
/// type aliases are not checked at usage sites of the type alias. Moreover,
1464+
/// they are not thoroughly checked for correctness at their definition site
1465+
/// either similar to the aliased type.
1466+
///
1467+
/// This is a known limitation of the type checker that may be lifted in a
1468+
/// future edition. Permitting such bounds in light of this was unintentional.
1469+
///
1470+
/// While these bounds may have secondary effects such as enabling the use of
1471+
/// "shorthand" associated type paths[^1] and affecting the default trait
1472+
/// object lifetime[^2] of trait object types passed to the type alias, this
1473+
/// should not have been allowed until the aforementioned restrictions of the
1474+
/// type checker have been lifted.
1475+
///
1476+
/// Using such bounds is highly discouraged as they are actively misleading.
1477+
///
1478+
/// [^1]: I.e., paths of the form `T::Assoc` where `T` is a type parameter
1479+
/// bounded by trait `Trait` which defines an associated type called `Assoc`
1480+
/// as opposed to a fully qualified path of the form `<T as Trait>::Assoc`.
1481+
/// [^2]: <https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes>
14651482
TYPE_ALIAS_BOUNDS,
14661483
Warn,
14671484
"bounds in type aliases are not enforced"
14681485
}
14691486

1470-
declare_lint_pass!(
1471-
/// Lint for trait and lifetime bounds in type aliases being mostly ignored.
1472-
/// They are relevant when using associated types, but otherwise neither checked
1473-
/// at definition site nor enforced at use site.
1474-
TypeAliasBounds => [TYPE_ALIAS_BOUNDS]
1475-
);
1487+
declare_lint_pass!(TypeAliasBounds => [TYPE_ALIAS_BOUNDS]);
14761488

14771489
impl TypeAliasBounds {
14781490
pub(crate) fn affects_object_lifetime_defaults(pred: &hir::WherePredicate<'_>) -> bool {

0 commit comments

Comments
 (0)