@@ -2,6 +2,132 @@ use expect_test::expect;
2
2
3
3
use crate :: tests:: { check_infer, check_no_mismatches} ;
4
4
5
+ #[ test]
6
+ fn regression_20365 ( ) {
7
+ check_infer (
8
+ r#"
9
+ //- minicore: iterator
10
+ struct Vec<T>(T);
11
+ struct IntoIter<T>(T);
12
+ impl<T> IntoIterator for Vec<T> {
13
+ type IntoIter = IntoIter<T>;
14
+ type Item = T;
15
+ }
16
+ impl<T> Iterator for IntoIter<T> {
17
+ type Item = T;
18
+ }
19
+
20
+ fn f<T: Space>(a: Vec<u8>) {
21
+ let iter = a.into_iter();
22
+ }
23
+
24
+ pub trait Space: IntoIterator {
25
+ type Ty: Space;
26
+ }
27
+ impl Space for [u8; 1] {
28
+ type Ty = Self;
29
+ }
30
+ "# ,
31
+ expect ! [ [ r#"
32
+ 201..202 'a': Vec<u8>
33
+ 213..246 '{ ...r(); }': ()
34
+ 223..227 'iter': IntoIter<u8>
35
+ 230..231 'a': Vec<u8>
36
+ 230..243 'a.into_iter()': IntoIter<u8>
37
+ "# ] ] ,
38
+ ) ;
39
+ }
40
+
41
+ #[ test]
42
+ fn regression_19971 ( ) {
43
+ check_infer (
44
+ r#"
45
+ //- minicore: pointee
46
+ fn make<T>(_thin: *const (), _meta: core::ptr::DynMetadata<T>) -> *const T
47
+ where
48
+ T: core::ptr::Pointee<Metadata = core::ptr::DynMetadata<T>> + ?Sized,
49
+ {
50
+ loop {}
51
+ }
52
+ trait Foo {
53
+ fn foo(&self) -> i32 {
54
+ loop {}
55
+ }
56
+ }
57
+
58
+ fn test() -> i32 {
59
+ struct F {}
60
+ impl Foo for F {}
61
+ let meta = core::ptr::metadata(0 as *const F as *const dyn Foo);
62
+
63
+ let f = F {};
64
+ let fat_ptr = make(&f as *const F as *const (), meta); // <-- infers type as `*const {unknown}`
65
+
66
+ let fat_ref = unsafe { &*fat_ptr }; // <-- infers type as `&{unknown}`
67
+ fat_ref.foo() // cannot 'go to definition' on `foo`
68
+ }
69
+
70
+ "# ,
71
+ expect ! [ [ r#"
72
+ 11..16 '_thin': *const ()
73
+ 29..34 '_meta': DynMetadata<T>
74
+ 155..170 '{ loop {} }': *const T
75
+ 161..168 'loop {}': !
76
+ 166..168 '{}': ()
77
+ 195..199 'self': &'? Self
78
+ 208..231 '{ ... }': i32
79
+ 218..225 'loop {}': !
80
+ 223..225 '{}': ()
81
+ 252..613 '{ ...foo` }': i32
82
+ 300..304 'meta': DynMetadata<dyn Foo + '?>
83
+ 307..326 'core::...tadata': fn metadata<dyn Foo + '?>(*const (dyn Foo + '?)) -> <dyn Foo + '? as Pointee>::Metadata
84
+ 307..359 'core::...n Foo)': DynMetadata<dyn Foo + '?>
85
+ 327..328 '0': usize
86
+ 327..340 '0 as *const F': *const F
87
+ 327..358 '0 as *...yn Foo': *const (dyn Foo + '?)
88
+ 370..371 'f': F
89
+ 374..378 'F {}': F
90
+ 388..395 'fat_ptr': *const (dyn Foo + '?)
91
+ 398..402 'make': fn make<dyn Foo + '?>(*const (), DynMetadata<dyn Foo + '?>) -> *const (dyn Foo + '?)
92
+ 398..437 'make(&... meta)': *const (dyn Foo + '?)
93
+ 403..405 '&f': &'? F
94
+ 403..417 '&f as *const F': *const F
95
+ 403..430 '&f as ...nst ()': *const ()
96
+ 404..405 'f': F
97
+ 432..436 'meta': DynMetadata<dyn Foo + '?>
98
+ 489..496 'fat_ref': &'? (dyn Foo + '?)
99
+ 499..519 'unsafe..._ptr }': &'? (dyn Foo + '?)
100
+ 508..517 '&*fat_ptr': &'? (dyn Foo + '?)
101
+ 509..517 '*fat_ptr': dyn Foo + '?
102
+ 510..517 'fat_ptr': *const (dyn Foo + '?)
103
+ 560..567 'fat_ref': &'? (dyn Foo + '?)
104
+ 560..573 'fat_ref.foo()': i32
105
+ "# ] ] ,
106
+ ) ;
107
+ }
108
+
109
+ #[ test]
110
+ fn regression_19752 ( ) {
111
+ check_no_mismatches (
112
+ r#"
113
+ //- minicore: sized, copy
114
+ trait T1<T: T2>: Sized + Copy {
115
+ fn a(self, other: Self) -> Self {
116
+ other
117
+ }
118
+
119
+ fn b(&mut self, other: Self) {
120
+ *self = self.a(other);
121
+ }
122
+ }
123
+
124
+ trait T2: Sized {
125
+ type T1: T1<Self>;
126
+ }
127
+ "# ,
128
+ ) ;
129
+ }
130
+
5
131
#[ test]
6
132
fn opaque_generics ( ) {
7
133
check_infer (
0 commit comments