Skip to content

Commit 8e3d059

Browse files
committed
Rust: Move impl_overlap test into its own file
1 parent a35e7b2 commit 8e3d059

File tree

4 files changed

+7351
-7350
lines changed

4 files changed

+7351
-7350
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:2871:13:2871:17 | x.f() |
2+
| main.rs:2720:13:2720:17 | x.f() |

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

Lines changed: 1 addition & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -453,158 +453,7 @@ mod method_non_parametric_trait_impl {
453453
}
454454
}
455455

456-
mod impl_overlap {
457-
#[derive(Debug, Clone, Copy)]
458-
struct S1;
459-
460-
trait OverlappingTrait {
461-
fn common_method(self) -> S1;
462-
463-
fn common_method_2(self, s1: S1) -> S1;
464-
}
465-
466-
impl OverlappingTrait for S1 {
467-
// <S1_as_OverlappingTrait>::common_method
468-
fn common_method(self) -> S1 {
469-
S1
470-
}
471-
472-
// <S1_as_OverlappingTrait>::common_method_2
473-
fn common_method_2(self, s1: S1) -> S1 {
474-
S1
475-
}
476-
}
477-
478-
impl S1 {
479-
// S1::common_method
480-
fn common_method(self) -> S1 {
481-
self
482-
}
483-
484-
// S1::common_method_2
485-
fn common_method_2(self) -> S1 {
486-
self
487-
}
488-
}
489-
490-
struct S2<T2>(T2);
491-
492-
impl S2<i32> {
493-
// S2<i32>::common_method
494-
fn common_method(self) -> S1 {
495-
S1
496-
}
497-
498-
// S2<i32>::common_method
499-
fn common_method_2(self) -> S1 {
500-
S1
501-
}
502-
}
503-
504-
impl OverlappingTrait for S2<i32> {
505-
// <S2<i32>_as_OverlappingTrait>::common_method
506-
fn common_method(self) -> S1 {
507-
S1
508-
}
509-
510-
// <S2<i32>_as_OverlappingTrait>::common_method_2
511-
fn common_method_2(self, s1: S1) -> S1 {
512-
S1
513-
}
514-
}
515-
516-
impl OverlappingTrait for S2<S1> {
517-
// <S2<S1>_as_OverlappingTrait>::common_method
518-
fn common_method(self) -> S1 {
519-
S1
520-
}
521-
522-
// <S2<S1>_as_OverlappingTrait>::common_method_2
523-
fn common_method_2(self, s1: S1) -> S1 {
524-
S1
525-
}
526-
}
527-
528-
#[derive(Debug)]
529-
struct S3<T3>(T3);
530-
531-
trait OverlappingTrait2<T> {
532-
fn m(&self, x: &T) -> &Self;
533-
}
534-
535-
impl<T> OverlappingTrait2<T> for S3<T> {
536-
// <S3<T>_as_OverlappingTrait2<T>>::m
537-
fn m(&self, x: &T) -> &Self {
538-
self
539-
}
540-
}
541-
542-
impl<T> S3<T> {
543-
// S3<T>::m
544-
fn m(&self, x: T) -> &Self {
545-
self
546-
}
547-
}
548-
549-
trait MyTrait1 {
550-
// MyTrait1::m
551-
fn m(&self) {}
552-
}
553-
554-
trait MyTrait2: MyTrait1 {}
555-
556-
#[derive(Debug)]
557-
struct S4;
558-
559-
impl MyTrait1 for S4 {
560-
// <S4_as_MyTrait1>::m
561-
fn m(&self) {}
562-
}
563-
564-
impl MyTrait2 for S4 {}
565-
566-
#[derive(Debug)]
567-
struct S5<T5>(T5);
568-
569-
impl MyTrait1 for S5<i32> {
570-
// <S5<i32>_as_MyTrait1>::m
571-
fn m(&self) {}
572-
}
573-
574-
impl MyTrait2 for S5<i32> {}
575-
576-
impl MyTrait1 for S5<bool> {}
577-
578-
impl MyTrait2 for S5<bool> {}
579-
580-
pub fn f() {
581-
let x = S1;
582-
println!("{:?}", x.common_method()); // $ target=S1::common_method
583-
println!("{:?}", S1::common_method(x)); // $ target=S1::common_method
584-
println!("{:?}", x.common_method_2()); // $ target=S1::common_method_2
585-
println!("{:?}", S1::common_method_2(x)); // $ target=S1::common_method_2
586-
587-
let y = S2(S1);
588-
println!("{:?}", y.common_method()); // $ target=<S2<S1>_as_OverlappingTrait>::common_method
589-
println!("{:?}", S2::<S1>::common_method(S2(S1))); // $ target=<S2<S1>_as_OverlappingTrait>::common_method
590-
591-
let z = S2(0);
592-
println!("{:?}", z.common_method()); // $ target=S2<i32>::common_method
593-
println!("{:?}", S2::common_method(S2(0))); // $ target=S2<i32>::common_method
594-
println!("{:?}", S2::<i32>::common_method(S2(0))); // $ target=S2<i32>::common_method
595-
596-
let w = S3(S1);
597-
println!("{:?}", w.m(x)); // $ target=S3<T>::m
598-
println!("{:?}", S3::m(&w, x)); // $ target=S3<T>::m
599-
600-
S4.m(); // $ target=<S4_as_MyTrait1>::m
601-
S4::m(&S4); // $ target=<S4_as_MyTrait1>::m
602-
S5(0i32).m(); // $ target=<S5<i32>_as_MyTrait1>::m
603-
S5::m(&S5(0i32)); // $ target=<S5<i32>_as_MyTrait1>::m
604-
S5(true).m(); // $ target=MyTrait1::m
605-
S5::m(&S5(true)); // $ target=MyTrait1::m
606-
}
607-
}
456+
mod overloading;
608457

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

0 commit comments

Comments
 (0)