Skip to content

Commit 330505c

Browse files
committed
Rust: Add tests for associated types
1 parent 01cc19c commit 330505c

File tree

6 files changed

+1032
-689
lines changed

6 files changed

+1032
-689
lines changed

rust/ql/test/library-tests/path-resolution/main.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,71 @@ mod associated_types {
877877
}
878878
}
879879

880+
mod associated_types_subtrait {
881+
trait Super {
882+
type Out; // SuperAssoc
883+
} // Super
884+
885+
trait Sub: Super // $ item=Super
886+
{
887+
fn f() -> Self::Out // $ item=SuperAssoc
888+
; // Sub_f
889+
} // Sub
890+
891+
struct S<ST>(
892+
ST, // $ item=ST
893+
);
894+
895+
#[rustfmt::skip]
896+
impl Super for S<i32> { // $ item=Super item=S item=i32
897+
type Out = char // $ item=char
898+
; // S<i32>::Out
899+
}
900+
901+
#[rustfmt::skip]
902+
impl Super for S<bool> { // $ item=Super item=S item=bool
903+
type Out = i64 // $ item=i64
904+
; // S<bool>::Out
905+
}
906+
907+
#[rustfmt::skip]
908+
impl Sub for S<i32> { // $ item=Sub item=S item=i32
909+
fn f() -> Self::Out { // $ MISSING: item=SuperAssoc SPURIOUS: item=S<i32>::Out item=S<bool>::Out item=S<A>::Out
910+
'a'
911+
}
912+
}
913+
914+
#[rustfmt::skip]
915+
impl Sub for S<bool> { // $ item=Sub item=S item=bool
916+
fn f() -> Self::Out { // $ MISSING: item=SuperAssoc SPURIOUS: item=S<i32>::Out item=S<bool>::Out item=S<A>::Out
917+
1
918+
}
919+
}
920+
921+
trait SuperAlt {
922+
type Out; // SuperAltAssoc
923+
} // SuperAlt
924+
925+
trait SubAlt: SuperAlt // $ item=SuperAlt
926+
{
927+
fn f(self) -> Self::Out // $ item=SuperAltAssoc
928+
; // SubAlt_f
929+
} // SubAlt
930+
931+
#[rustfmt::skip]
932+
impl<A> SuperAlt for S<A> { // $ item=SuperAlt item=S item=A
933+
type Out = A // $ item=A
934+
; // S<A>::Out
935+
}
936+
937+
#[rustfmt::skip]
938+
impl<A> SubAlt for S<A> { // $ item=SubAlt item=S item=A
939+
fn f(self) -> Self::Out { // $ MISSING: item=SuperAltAssoc SPURIOUS: item=S<i32>::Out item=S<bool>::Out item=S<A>::Out
940+
self.0
941+
}
942+
}
943+
}
944+
880945
use std::{self as ztd}; // $ item=std
881946

882947
fn use_ztd(x: ztd::string::String) {} // $ item=String

0 commit comments

Comments
 (0)