Open danielhenrymantilla opened 1 month ago
NB By the way, lazy_type_alias
implements the desired semantics. See its tracking issue: #112792.
CC #21903.
Good to know there is progress on the "make type
aliases work as expected" front 🙂.
But to avoid confusion, I do want to clarify that this is not what this issue is about, this one is a diagnostics issue, w.r.t. how type
aliases currently work. That is, when using <T as Trait>::Assoc
in the rhs of a type
alias, this already, currently, enforces that T : ?Sized + Trait
be true (and when Trait : Sized
, we end up with T : Trait
).
Given that, we should be allowed to add such bounds without having Rust warn us about our bounds being ignored, because given the rhs, they cannot be.
Right, that makes sense (I just had to do some advertising :P).
Yeah, the lint isn't super smart atm. This isn't the only case where bounds on type parameters of (eager) type aliases actually have a user-visible effect. Outlives-bounds for example may affect trait object lifetime defaults (we have an A-lint
issue for that somewhere).
Thanks for improving my poor issue title 😄 @fmease 🙏
Code
Current output
Desired output
Rationale and extra context
Whilst it is true that left-hand-side bounds on generic parameters are not enforced in type aliases, { performing a
Trait
associated type "lookup" on / resolving theTrait
associated type of } a given typeT
does effectively constrainT
to be: ?Sized + Trait
.This means that for that specific snippet, the pattern is fine, both presently, and in the future, should these bounds end up enforced.
Whilst it may look like an oddly over-specific example, it is actually a common pattern to define a
type
alias as a shortcut for a trait associated type lookup.Granted, the bounds could be skipped, like so:
but this significantly hinders the quality of the generated documentation (now people need to look at the implementation/"value" of the
type
alias to try and figure out what the bounds on it are).Other cases
Bonus points if when
: Sized
is a supertrait ofT
, the?Sized +
ends up not being required to prevent the lint from firing.