Skip to content

Commit d7cf14d

Browse files
committed
Rust: Add tests for associated types
1 parent bedb803 commit d7cf14d

File tree

4 files changed

+859
-657
lines changed

4 files changed

+859
-657
lines changed

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

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ mod m23 {
716716

717717
#[rustfmt::skip]
718718
impl Trait1<
719-
Self // $ item=I4
719+
Self // $ SPURIOUS: item=I4 MISSING: item=implTrait1forS
720720
> // $ item=I2
721721
for S { // $ item=I4
722722
fn f(&self) {
@@ -870,6 +870,71 @@ mod associated_types {
870870
}
871871
}
872872

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

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

0 commit comments

Comments
 (0)