]> git.lizzy.rs Git - rust.git/blob - tests/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.rs
Rollup merge of #106935 - TaKO8Ki:fix-104440, r=cjgillot
[rust.git] / tests / ui / generics / issue-61631-default-type-param-can-reference-self-in-trait.rs
1 #![crate_type="lib"]
2
3 // rust-lang/rust#61631: The use of `Self` in the defaults of generic
4 // types in a *trait* definition are allowed.
5 //
6 // It *must* be accepted; we have used this pattern extensively since
7 // Rust 1.0 (see e.g. `trait Add<Rhs=Self>`).
8 trait Tnobound<P = Self> {}
9
10 impl Tnobound for () { }
11
12 // This variant is accepted at the definition site; but it will be
13 // rejected at every possible usage site (such as the one immediately
14 // below). Maybe one day we will attempt to catch it at the definition
15 // site, but today this is accepted due to compiler implementation
16 // limitations.
17 trait Tsized<P: Sized = [Self]> {}
18
19 impl Tsized for () {}
20 //~^ ERROR the size for values of type `[()]` cannot be known at compilation time [E0277]