@@ -652,6 +652,51 @@ mod type_parameter_bounds {
652652 }
653653}
654654
655+ mod trait_default_self_type_parameter {
656+ // A trait with a type parameter that defaults to `Self`.
657+ // trait TraitWithSelfTp<A = Self> {
658+ trait TraitWithSelfTp < A = Option < Self > > {
659+ // TraitWithSelfTp::get_a
660+ fn get_a ( & self ) -> A ;
661+ }
662+
663+ fn get_a < A , T : TraitWithSelfTp < A > > ( thing : & T ) -> A {
664+ thing. get_a ( ) // $ target=TraitWithSelfTp::get_a
665+ }
666+
667+ // The trait bound on `T` uses the default for `A` which contains `Self`
668+ fn tp_uses_default < S : TraitWithSelfTp > ( thing : S ) -> i64 {
669+ let _ms = thing. get_a ( ) ; // $ target=TraitWithSelfTp::get_a MISSING: type=_ms:T.S
670+ 0
671+ }
672+
673+ // The supertrait uses the default for `A` which contains `Self`
674+ trait SubTraitOfTraitWithSelfTp : TraitWithSelfTp + Sized { }
675+
676+ fn get_a_through_tp < S : SubTraitOfTraitWithSelfTp > ( thing : & S ) {
677+ // `thing` is a `TraitWithSelfTp` through the trait hierarchy
678+ let _ms = get_a ( thing) ; // $ target=get_a MISSING: type=_ms:T.S
679+ }
680+
681+ struct MyStruct {
682+ value : i32 ,
683+ }
684+
685+ // The implementing trait uses the default for `A` which contains `Self`
686+ impl TraitWithSelfTp for MyStruct {
687+ fn get_a ( & self ) -> Option < Self > {
688+ Some ( MyStruct { value : self . value } ) // $ fieldof=MyStruct
689+ }
690+ }
691+
692+ impl SubTraitOfTraitWithSelfTp for MyStruct { }
693+
694+ pub fn test ( ) {
695+ let s = MyStruct { value : 0 } ;
696+ let _ms = get_a ( & s) ; // $ target=get_a MISSING: type=_ms:T.MyStruct
697+ }
698+ }
699+
655700mod function_trait_bounds {
656701 #[ derive( Debug , Clone , Copy ) ]
657702 struct MyThing < T > {
@@ -2753,6 +2798,7 @@ fn main() {
27532798 method_impl:: g ( method_impl:: Foo { } , method_impl:: Foo { } ) ; // $ target=g
27542799 method_non_parametric_impl:: f ( ) ; // $ target=f
27552800 method_non_parametric_trait_impl:: f ( ) ; // $ target=f
2801+ trait_default_self_type_parameter:: test ( ) ; // $ target=test
27562802 function_trait_bounds:: f ( ) ; // $ target=f
27572803 associated_type_in_trait:: f ( ) ; // $ target=f
27582804 generic_enum:: f ( ) ; // $ target=f
0 commit comments