File tree Expand file tree Collapse file tree 2 files changed +3872
-3786
lines changed
rust/ql/test/library-tests/type-inference Expand file tree Collapse file tree 2 files changed +3872
-3786
lines changed Original file line number Diff line number Diff line change @@ -652,6 +652,47 @@ 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+ fn tp_uses_default < T : TraitWithSelfTp > ( thing : T ) -> i64 {
668+ let also_t = thing. get_a ( ) ; // $ target=TraitWithSelfTp::get_a
669+ 0
670+ }
671+
672+ trait SubTraitOfTraitWithSelfTp : TraitWithSelfTp + Sized { }
673+
674+ fn get_a_through_tp < T : SubTraitOfTraitWithSelfTp > ( thing : & T ) {
675+ let _also_t = get_a ( thing) ; // $ target=get_a MISSING: type=_also_t:T.T
676+ }
677+
678+ struct MyStruct {
679+ value : i32 ,
680+ }
681+
682+ impl TraitWithSelfTp for MyStruct {
683+ fn get_a ( & self ) -> Option < Self > {
684+ Some ( MyStruct { value : self . value } ) // $ fieldof=MyStruct
685+ }
686+ }
687+
688+ impl SubTraitOfTraitWithSelfTp for MyStruct { }
689+
690+ pub fn f ( ) {
691+ let s = MyStruct { value : 0 } ;
692+ let _a = get_a ( & s) ; // $ target=get_a MISSING: type=_a:T.MyStruct
693+ }
694+ }
695+
655696mod function_trait_bounds {
656697 #[ derive( Debug , Clone , Copy ) ]
657698 struct MyThing < T > {
You can’t perform that action at this time.
0 commit comments