File tree Expand file tree Collapse file tree 3 files changed +435
-0
lines changed
rust/ql/test/library-tests/type-inference Expand file tree Collapse file tree 3 files changed +435
-0
lines changed Original file line number Diff line number Diff line change @@ -400,3 +400,52 @@ mod from_default {
400400 x
401401 }
402402}
403+
404+ mod inherent_before_trait {
405+ struct S < T > ( T ) ;
406+
407+ trait Trait {
408+ fn foo ( & self ) ;
409+ fn bar ( & self ) ;
410+ }
411+
412+ impl S < i32 > {
413+ // S<i32>::foo
414+ fn foo ( x : & Self ) { }
415+
416+ // S<i32>::bar
417+ fn bar ( & self ) { }
418+ }
419+
420+ impl Trait for S < i32 > {
421+ // <S<i32>_as_Trait>::foo
422+ fn foo ( & self ) {
423+ S :: foo ( self ) ; // $ MISSING: target=S<i32>::foo
424+ S :: < i32 > :: foo ( self ) ; // $ MISSING: target=S<i32>::foo
425+ self . foo ( ) // $ target=<S<i32>_as_Trait>::foo
426+ }
427+
428+ // <S<i32>_as_Trait>::bar
429+ fn bar ( & self ) {
430+ S :: bar ( self ) ; // $ target=S<i32>::bar
431+ S :: < i32 > :: bar ( self ) ; // $ target=S<i32>::bar
432+ self . bar ( ) // $ target=S<i32>::bar
433+ }
434+ }
435+
436+ impl Trait for S < i64 > {
437+ // <S<i64>_as_Trait>::foo
438+ fn foo ( & self ) {
439+ // `S::foo(self);` is not valid
440+ S :: < i64 > :: foo ( self ) ; // $ MISSING: target=<S<i64>_as_Trait>::foo
441+ self . foo ( ) // $ target=<S<i64>_as_Trait>::foo
442+ }
443+
444+ // <S<i64>_as_Trait>::bar
445+ fn bar ( & self ) {
446+ // `S::bar(self);` is not valid
447+ S :: < i64 > :: bar ( self ) ; // $ target=<S<i64>_as_Trait>::bar
448+ self . bar ( ) // $ target=<S<i64>_as_Trait>::bar
449+ }
450+ }
451+ }
Original file line number Diff line number Diff line change @@ -74,3 +74,35 @@ mod regression2 {
7474 let x = s1 - & s2; // $ target=S1SubRefS2 type=x:S2
7575 }
7676}
77+
78+ mod regression3 {
79+ trait SomeTrait { }
80+
81+ trait MyFrom < T > {
82+ fn my_from ( value : T ) -> Self ;
83+ }
84+
85+ impl < T > MyFrom < T > for T {
86+ fn my_from ( s : T ) -> Self {
87+ s
88+ }
89+ }
90+
91+ impl < T > MyFrom < T > for Option < T > {
92+ fn my_from ( val : T ) -> Option < T > {
93+ Some ( val)
94+ }
95+ }
96+
97+ pub struct S < Ts > ( Ts ) ;
98+
99+ pub fn f < T1 , T2 > ( x : T2 ) -> T2
100+ where
101+ T2 : SomeTrait + MyFrom < Option < T1 > > ,
102+ Option < T1 > : MyFrom < T2 > ,
103+ {
104+ let y = MyFrom :: my_from ( x) ; // $ target=my_from
105+ let z = MyFrom :: my_from ( y) ; // $ target=my_from
106+ z
107+ }
108+ }
You can’t perform that action at this time.
0 commit comments