Summary

Check all types for well-formedness with respect to the bounds

制限する、結び付けられて
of type variables.
変数、ストレージ

Allow

許可する、可能にする
bounds
制限する、結び付けられて
on formal type variable
変数、ストレージ
in structs
構造、構造体
and enums. Check these bounds
制限する、結び付けられて
are satisfied
満たす、満足させる
wherever the struct
構造、構造体
or enum is used with actual
実際の
type parameters.
仮引数

Motivation

Makes type checking saner. Catches errors earlier in the development

開発
process. Matches behaviour with built-in
組み込みの
bounds
制限する、結び付けられて
(I think).

Currently formal type variables

変数、ストレージ
in traits and functions may have bounds
制限する、結び付けられて
and these bounds
制限する、結び付けられて
are checked whenever the item is used against the actual
実際の
type variables.
変数、ストレージ
Where these type variables
変数、ストレージ
are used in types, these types should be checked for well-formedness with respect to the type definitions.
定義
E.g.,

trait U {} trait T<X: U> {} trait S<Y> { fn m(x: ~T<Y>) {} // Should be flagged as an error }

Formal type variables

変数、ストレージ
in structs
構造、構造体
and enums may not have bounds.
制限する、結び付けられて
It is possible to use these type variables
変数、ストレージ
in the types of fields, and these types cannot be checked for well-formedness until the struct
構造、構造体
is instantiated, where each field must be checked.

struct St<X> { f: ~T<X>, // Cannot be checked }

Likewise, impls of structs

構造、構造体
are not checked. E.g.,

impl<X> St<X> { // Cannot be checked ... }

Here, no struct

構造、構造体
can exist where X is replaced by something implementing U, so in the impl, X can be assumed to have the bound
制限する、結び付けられて
U. But the impl does not indicate
指し示す
this. Note, this is sound, but does not indicate
指し示す
programmer intent very well.

Detailed design
設計(する)

Whenever a type is used it must be checked for well-formedness. For polymorphic types we currently check only that the type exists. I would like to also check that any actual

実際の
type parameters
仮引数
are valid.
有効な、正しい
That is, given
与えられた
a type T<U> where T is declared
宣言
as T<X: B>, we currently only check that T does in fact exist somewhere (I think we also check that the correct number of type parameters
仮引数
are supplied, in this case one). I would also like to check that U satisfies
満たす、満足させる
the bound
制限する、結び付けられて
B.

Work on built-in

組み込みの
bounds
制限する、結び付けられて
is (I think) in the process of adding
たす
this behaviour for built-in
組み込みの
bounds.
制限する、結び付けられて
I would like to apply
適用する
this to user-specified bounds
制限する、結び付けられて
too.

I think no fewer programs can be expressed. That is, any errors we catch with this new check would have been caught later in the existing scheme, where exactly

正確に
would depend on where the type was used. The only exception
例外
would be if the formal type variable
変数、ストレージ
was not used.

We would allow

許可する、可能にする
bounds
制限する、結び付けられて
on type variable
変数、ストレージ
in structs
構造、構造体
and enums. Wherever a concrete
具体的な/具象的な
struct
構造、構造体
or enum type appears,
現れる
check the actual
実際の
type variables
変数、ストレージ
against the bounds
制限する、結び付けられて
on the formals (the type well-formedness check).

From the above examples:

trait U {} trait T<X: U> {} trait S1<Y> { fn m(x: ~T<Y>) {} //~ ERROR } trait S2<Y: U> { fn m(x: ~T<Y>) {} } struct St<X: U> { f: ~T<X>, } impl<X: U> St<X> { ... }

Alternatives
代わりのもの、選択肢

Keep the status quo.

We could add bounds

制限する、結び付けられて
on structs,
構造、構造体
etc. But not check them in impls. This is safe since the implementation
実装
is more general
一般
than the struct.
構造、構造体
It would mean we allow
許可する、可能にする
impls to be un-necessarily general.
一般

Unresolved questions

Do we allow

許可する、可能にする
and check bounds
制限する、結び付けられて
in type aliases? We currently do not. We should probably continue not to since these type variables
変数、ストレージ
(and indeed the type aliases) are substituted away early in the type checking process. So if we think of type aliases
別名
as almost macro-like, then not checking makes sense. OTOH, it is still a little bit inconsistent.