Skip to content

Commit 025f733

Browse files
committed
Rust: Move some overloading tests into a separate file
1 parent 1203da1 commit 025f733

File tree

4 files changed

+8217
-8216
lines changed

4 files changed

+8217
-8216
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
multipleResolvedTargets
2-
| main.rs:2902:13:2902:17 | x.f() |
2+
| main.rs:2723:13:2723:17 | x.f() |

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 1 addition & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -184,34 +184,6 @@ mod trait_visibility {
184184
}
185185
}
186186

187-
mod method_call_trait_path_disambig {
188-
trait FirstTrait {
189-
// FirstTrait::method
190-
fn method(&self) -> bool {
191-
true
192-
}
193-
}
194-
trait SecondTrait {
195-
// SecondTrait::method
196-
fn method(&self) -> i64 {
197-
1
198-
}
199-
}
200-
struct S;
201-
impl FirstTrait for S {}
202-
impl SecondTrait for S {}
203-
204-
fn _test() {
205-
let s = S;
206-
207-
let _b1 = FirstTrait::method(&s); // $ type=_b1:bool target=FirstTrait::method
208-
let _b2 = <S as FirstTrait>::method(&s); // $ type=_b2:bool target=FirstTrait::method
209-
210-
let _n1 = SecondTrait::method(&s); // $ type=_n1:i64 target=SecondTrait::method
211-
let _n2 = <S as SecondTrait>::method(&s); // $ type=_n2:i64 target=SecondTrait::method
212-
}
213-
}
214-
215187
mod method_non_parametric_impl {
216188
#[derive(Debug)]
217189
struct MyThing<A> {
@@ -484,158 +456,7 @@ mod method_non_parametric_trait_impl {
484456
}
485457
}
486458

487-
mod impl_overlap {
488-
#[derive(Debug, Clone, Copy)]
489-
struct S1;
490-
491-
trait OverlappingTrait {
492-
fn common_method(self) -> S1;
493-
494-
fn common_method_2(self, s1: S1) -> S1;
495-
}
496-
497-
impl OverlappingTrait for S1 {
498-
// <S1_as_OverlappingTrait>::common_method
499-
fn common_method(self) -> S1 {
500-
S1
501-
}
502-
503-
// <S1_as_OverlappingTrait>::common_method_2
504-
fn common_method_2(self, s1: S1) -> S1 {
505-
S1
506-
}
507-
}
508-
509-
impl S1 {
510-
// S1::common_method
511-
fn common_method(self) -> S1 {
512-
self
513-
}
514-
515-
// S1::common_method_2
516-
fn common_method_2(self) -> S1 {
517-
self
518-
}
519-
}
520-
521-
struct S2<T2>(T2);
522-
523-
impl S2<i32> {
524-
// S2<i32>::common_method
525-
fn common_method(self) -> S1 {
526-
S1
527-
}
528-
529-
// S2<i32>::common_method
530-
fn common_method_2(self) -> S1 {
531-
S1
532-
}
533-
}
534-
535-
impl OverlappingTrait for S2<i32> {
536-
// <S2<i32>_as_OverlappingTrait>::common_method
537-
fn common_method(self) -> S1 {
538-
S1
539-
}
540-
541-
// <S2<i32>_as_OverlappingTrait>::common_method_2
542-
fn common_method_2(self, s1: S1) -> S1 {
543-
S1
544-
}
545-
}
546-
547-
impl OverlappingTrait for S2<S1> {
548-
// <S2<S1>_as_OverlappingTrait>::common_method
549-
fn common_method(self) -> S1 {
550-
S1
551-
}
552-
553-
// <S2<S1>_as_OverlappingTrait>::common_method_2
554-
fn common_method_2(self, s1: S1) -> S1 {
555-
S1
556-
}
557-
}
558-
559-
#[derive(Debug)]
560-
struct S3<T3>(T3);
561-
562-
trait OverlappingTrait2<T> {
563-
fn m(&self, x: &T) -> &Self;
564-
}
565-
566-
impl<T> OverlappingTrait2<T> for S3<T> {
567-
// <S3<T>_as_OverlappingTrait2<T>>::m
568-
fn m(&self, x: &T) -> &Self {
569-
self
570-
}
571-
}
572-
573-
impl<T> S3<T> {
574-
// S3<T>::m
575-
fn m(&self, x: T) -> &Self {
576-
self
577-
}
578-
}
579-
580-
trait MyTrait1 {
581-
// MyTrait1::m
582-
fn m(&self) {}
583-
}
584-
585-
trait MyTrait2: MyTrait1 {}
586-
587-
#[derive(Debug)]
588-
struct S4;
589-
590-
impl MyTrait1 for S4 {
591-
// <S4_as_MyTrait1>::m
592-
fn m(&self) {}
593-
}
594-
595-
impl MyTrait2 for S4 {}
596-
597-
#[derive(Debug)]
598-
struct S5<T5>(T5);
599-
600-
impl MyTrait1 for S5<i32> {
601-
// <S5<i32>_as_MyTrait1>::m
602-
fn m(&self) {}
603-
}
604-
605-
impl MyTrait2 for S5<i32> {}
606-
607-
impl MyTrait1 for S5<bool> {}
608-
609-
impl MyTrait2 for S5<bool> {}
610-
611-
pub fn f() {
612-
let x = S1;
613-
println!("{:?}", x.common_method()); // $ target=S1::common_method
614-
println!("{:?}", S1::common_method(x)); // $ target=S1::common_method
615-
println!("{:?}", x.common_method_2()); // $ target=S1::common_method_2
616-
println!("{:?}", S1::common_method_2(x)); // $ target=S1::common_method_2
617-
618-
let y = S2(S1);
619-
println!("{:?}", y.common_method()); // $ target=<S2<S1>_as_OverlappingTrait>::common_method
620-
println!("{:?}", S2::<S1>::common_method(S2(S1))); // $ target=<S2<S1>_as_OverlappingTrait>::common_method
621-
622-
let z = S2(0);
623-
println!("{:?}", z.common_method()); // $ target=S2<i32>::common_method
624-
println!("{:?}", S2::common_method(S2(0))); // $ target=S2<i32>::common_method
625-
println!("{:?}", S2::<i32>::common_method(S2(0))); // $ target=S2<i32>::common_method
626-
627-
let w = S3(S1);
628-
println!("{:?}", w.m(x)); // $ target=S3<T>::m
629-
println!("{:?}", S3::m(&w, x)); // $ target=S3<T>::m
630-
631-
S4.m(); // $ target=<S4_as_MyTrait1>::m
632-
S4::m(&S4); // $ target=<S4_as_MyTrait1>::m
633-
S5(0i32).m(); // $ target=<S5<i32>_as_MyTrait1>::m
634-
S5::m(&S5(0i32)); // $ target=<S5<i32>_as_MyTrait1>::m
635-
S5(true).m(); // $ target=MyTrait1::m
636-
S5::m(&S5(true)); // $ target=MyTrait1::m
637-
}
638-
}
459+
mod overloading;
639460

640461
mod type_parameter_bounds {
641462
use std::fmt::Debug;
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
mod method_call_trait_path_disambig {
2+
trait FirstTrait {
3+
// FirstTrait::method
4+
fn method(&self) -> bool {
5+
true
6+
}
7+
}
8+
trait SecondTrait {
9+
// SecondTrait::method
10+
fn method(&self) -> i64 {
11+
1
12+
}
13+
}
14+
struct S;
15+
impl FirstTrait for S {}
16+
impl SecondTrait for S {}
17+
18+
fn _test() {
19+
let s = S;
20+
21+
let _b1 = FirstTrait::method(&s); // $ type=_b1:bool target=FirstTrait::method
22+
let _b2 = <S as FirstTrait>::method(&s); // $ type=_b2:bool target=FirstTrait::method
23+
24+
let _n1 = SecondTrait::method(&s); // $ type=_n1:i64 target=SecondTrait::method
25+
let _n2 = <S as SecondTrait>::method(&s); // $ type=_n2:i64 target=SecondTrait::method
26+
}
27+
}
28+
29+
pub mod impl_overlap {
30+
#[derive(Debug, Clone, Copy)]
31+
struct S1;
32+
33+
trait OverlappingTrait {
34+
fn common_method(self) -> S1;
35+
36+
fn common_method_2(self, s1: S1) -> S1;
37+
}
38+
39+
impl OverlappingTrait for S1 {
40+
// <S1_as_OverlappingTrait>::common_method
41+
fn common_method(self) -> S1 {
42+
S1
43+
}
44+
45+
// <S1_as_OverlappingTrait>::common_method_2
46+
fn common_method_2(self, s1: S1) -> S1 {
47+
S1
48+
}
49+
}
50+
51+
impl S1 {
52+
// S1::common_method
53+
fn common_method(self) -> S1 {
54+
self
55+
}
56+
57+
// S1::common_method_2
58+
fn common_method_2(self) -> S1 {
59+
self
60+
}
61+
}
62+
63+
struct S2<T2>(T2);
64+
65+
impl S2<i32> {
66+
// S2<i32>::common_method
67+
fn common_method(self) -> S1 {
68+
S1
69+
}
70+
71+
// S2<i32>::common_method
72+
fn common_method_2(self) -> S1 {
73+
S1
74+
}
75+
}
76+
77+
impl OverlappingTrait for S2<i32> {
78+
// <S2<i32>_as_OverlappingTrait>::common_method
79+
fn common_method(self) -> S1 {
80+
S1
81+
}
82+
83+
// <S2<i32>_as_OverlappingTrait>::common_method_2
84+
fn common_method_2(self, s1: S1) -> S1 {
85+
S1
86+
}
87+
}
88+
89+
impl OverlappingTrait for S2<S1> {
90+
// <S2<S1>_as_OverlappingTrait>::common_method
91+
fn common_method(self) -> S1 {
92+
S1
93+
}
94+
95+
// <S2<S1>_as_OverlappingTrait>::common_method_2
96+
fn common_method_2(self, s1: S1) -> S1 {
97+
S1
98+
}
99+
}
100+
101+
#[derive(Debug)]
102+
struct S3<T3>(T3);
103+
104+
trait OverlappingTrait2<T> {
105+
fn m(&self, x: &T) -> &Self;
106+
}
107+
108+
impl<T> OverlappingTrait2<T> for S3<T> {
109+
// <S3<T>_as_OverlappingTrait2<T>>::m
110+
fn m(&self, x: &T) -> &Self {
111+
self
112+
}
113+
}
114+
115+
impl<T> S3<T> {
116+
// S3<T>::m
117+
fn m(&self, x: T) -> &Self {
118+
self
119+
}
120+
}
121+
122+
trait MyTrait1 {
123+
// MyTrait1::m
124+
fn m(&self) {}
125+
}
126+
127+
trait MyTrait2: MyTrait1 {}
128+
129+
#[derive(Debug)]
130+
struct S4;
131+
132+
impl MyTrait1 for S4 {
133+
// <S4_as_MyTrait1>::m
134+
fn m(&self) {}
135+
}
136+
137+
impl MyTrait2 for S4 {}
138+
139+
#[derive(Debug)]
140+
struct S5<T5>(T5);
141+
142+
impl MyTrait1 for S5<i32> {
143+
// <S5<i32>_as_MyTrait1>::m
144+
fn m(&self) {}
145+
}
146+
147+
impl MyTrait2 for S5<i32> {}
148+
149+
impl MyTrait1 for S5<bool> {}
150+
151+
impl MyTrait2 for S5<bool> {}
152+
153+
pub fn f() {
154+
let x = S1;
155+
println!("{:?}", x.common_method()); // $ target=S1::common_method
156+
println!("{:?}", S1::common_method(x)); // $ target=S1::common_method
157+
println!("{:?}", x.common_method_2()); // $ target=S1::common_method_2
158+
println!("{:?}", S1::common_method_2(x)); // $ target=S1::common_method_2
159+
160+
let y = S2(S1);
161+
println!("{:?}", y.common_method()); // $ target=<S2<S1>_as_OverlappingTrait>::common_method
162+
println!("{:?}", S2::<S1>::common_method(S2(S1))); // $ target=<S2<S1>_as_OverlappingTrait>::common_method
163+
164+
let z = S2(0);
165+
println!("{:?}", z.common_method()); // $ target=S2<i32>::common_method
166+
println!("{:?}", S2::common_method(S2(0))); // $ target=S2<i32>::common_method
167+
println!("{:?}", S2::<i32>::common_method(S2(0))); // $ target=S2<i32>::common_method
168+
169+
let w = S3(S1);
170+
println!("{:?}", w.m(x)); // $ target=S3<T>::m
171+
println!("{:?}", S3::m(&w, x)); // $ target=S3<T>::m
172+
173+
S4.m(); // $ target=<S4_as_MyTrait1>::m
174+
S4::m(&S4); // $ target=<S4_as_MyTrait1>::m
175+
S5(0i32).m(); // $ target=<S5<i32>_as_MyTrait1>::m
176+
S5::m(&S5(0i32)); // $ target=<S5<i32>_as_MyTrait1>::m
177+
S5(true).m(); // $ target=MyTrait1::m
178+
S5::m(&S5(true)); // $ target=MyTrait1::m
179+
}
180+
}

0 commit comments

Comments
 (0)