Bound on generic parameter in type alias

I encountered this warning for the first time, and would like both to understand its motivation and potentially discuss improving the warning messages. I reduced the situation down to:

pub trait State {
    type Action;
}
pub type Transition1<S: State> = (S, S::Action);

Rustc says:

warning: bounds on generic parameters are not enforced in type aliases
 --> src/lib.rs:5:25
  |
5 | pub type Transition1<S: State> = (S, S::Action);
  |                         ^^^^^
  |
  = note: `#[warn(type_alias_bounds)]` on by default
help: use fully disambiguated paths (i.e., `<T as Trait>::Assoc`) to refer to associated types in type aliases
 --> src/lib.rs:5:38
  |
5 | pub type Transition1<S: State> = (S, S::Action);
  |                                      ^^^^^^^^^
help: the bound will not be checked when the type alias is used, and should be removed
  |
5 | pub type Transition1<S> = (S, S::Action);

As usual, there is an obvious effort to give helpful messages :+1: Still, it seems to me the second help message might be better left out: in this current form, the bound cannot be removed, because it is required to give meaning to S::Action. So potentially printing only the first help would be more helpful.

More fundamentally though, I'm not sure I understand the reason for this warning. Following the recommendations lead me to:

pub type Transition2<S> = (S, <S as State>::Action);

Is Transition2 equivalent to Transition1?

Why is writing S as State allowed when S in unconstrained? Does it generate an implicit constraint on S? To me the explicit constraint in Transition1 seems clearer.

Regarding the first warning, "bounds on generic parameters are not enforced in type aliases", is this a fundamental design choice/constraint, or something that is not (yet) implemented?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.