3 // rust-lang/rust#61631: Uses of `Self` in the defaults of generic
4 // types for ADT's are not allowed. We justify this because the `Self`
5 // type could be considered the "final" type parameter, that is only
6 // well-defined after all of the other type parameters on the ADT have
9 // These were previously were ICE'ing at the usage point anyway (see
10 // `demo_usages` below), so there should not be any backwards
11 // compatibility concern.
13 struct Snobound<'a, P = Self> { x: Option<&'a P> }
14 //~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
16 enum Enobound<'a, P = Self> { A, B(Option<&'a P>) }
17 //~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
19 union Unobound<'a, P = Self> { x: i32, y: Option<&'a P> }
20 //~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
22 // Disallowing `Self` in defaults sidesteps need to check the bounds
23 // on the defaults in cases like these.
25 struct Ssized<'a, P: Sized = [Self]> { x: Option<&'a P> }
26 //~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
28 enum Esized<'a, P: Sized = [Self]> { A, B(Option<&'a P>) }
29 //~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
31 union Usized<'a, P: Sized = [Self]> { x: i32, y: Option<&'a P> }
32 //~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
35 // An ICE means you only get the error from the first line of the
36 // demo; comment each out to observe the other ICEs when trying
37 // this out on older versions of Rust.