diff options
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r-- | crates/hir_ty/src/tests/coercion.rs | 1017 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/display_source_code.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/macros.rs | 29 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/method_resolution.rs | 363 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/patterns.rs | 80 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/regression.rs | 280 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/simple.rs | 793 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 1086 |
8 files changed, 1343 insertions, 2315 deletions
diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index 71047703d..87089f09d 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs | |||
@@ -1,380 +1,157 @@ | |||
1 | use expect_test::expect; | 1 | use super::{check, check_no_mismatches, check_types}; |
2 | |||
3 | use super::{check_infer, check_infer_with_mismatches, check_no_mismatches, check_types}; | ||
4 | 2 | ||
5 | #[test] | 3 | #[test] |
6 | fn infer_block_expr_type_mismatch() { | 4 | fn block_expr_type_mismatch() { |
7 | check_infer( | 5 | // FIXME fix double type mismatch |
6 | check( | ||
8 | r" | 7 | r" |
9 | fn test() { | 8 | fn test() { |
10 | let a: i32 = { 1i64 }; | 9 | let a: i32 = { 1i64 }; |
11 | } | 10 | // ^^^^^^^^ expected i32, got i64 |
11 | // ^^^^ expected i32, got i64 | ||
12 | } | ||
12 | ", | 13 | ", |
13 | expect![[r" | ||
14 | 10..40 '{ ...4 }; }': () | ||
15 | 20..21 'a': i32 | ||
16 | 29..37 '{ 1i64 }': i64 | ||
17 | 31..35 '1i64': i64 | ||
18 | "]], | ||
19 | ); | 14 | ); |
20 | } | 15 | } |
21 | 16 | ||
22 | #[test] | 17 | #[test] |
23 | fn coerce_places() { | 18 | fn coerce_places() { |
24 | check_infer( | 19 | check_no_mismatches( |
25 | r#" | 20 | r#" |
26 | struct S<T> { a: T } | 21 | //- minicore: coerce_unsized |
22 | struct S<T> { a: T } | ||
27 | 23 | ||
28 | fn f<T>(_: &[T]) -> T { loop {} } | 24 | fn f<T>(_: &[T]) -> T { loop {} } |
29 | fn g<T>(_: S<&[T]>) -> T { loop {} } | 25 | fn g<T>(_: S<&[T]>) -> T { loop {} } |
30 | 26 | ||
31 | fn gen<T>() -> *mut [T; 2] { loop {} } | 27 | fn gen<T>() -> *mut [T; 2] { loop {} } |
32 | fn test1<U>() -> *mut [U] { | 28 | fn test1<U>() -> *mut [U] { |
33 | gen() | 29 | gen() |
34 | } | 30 | } |
35 | |||
36 | fn test2() { | ||
37 | let arr: &[u8; 1] = &[1]; | ||
38 | |||
39 | let a: &[_] = arr; | ||
40 | let b = f(arr); | ||
41 | let c: &[_] = { arr }; | ||
42 | let d = g(S { a: arr }); | ||
43 | let e: [&[_]; 1] = [arr]; | ||
44 | let f: [&[_]; 2] = [arr; 2]; | ||
45 | let g: (&[_], &[_]) = (arr, arr); | ||
46 | } | ||
47 | 31 | ||
48 | #[lang = "sized"] | 32 | fn test2() { |
49 | pub trait Sized {} | 33 | let arr: &[u8; 1] = &[1]; |
50 | #[lang = "unsize"] | ||
51 | pub trait Unsize<T: ?Sized> {} | ||
52 | #[lang = "coerce_unsized"] | ||
53 | pub trait CoerceUnsized<T> {} | ||
54 | 34 | ||
55 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | 35 | let a: &[_] = arr; |
56 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | 36 | let b = f(arr); |
57 | "#, | 37 | let c: &[_] = { arr }; |
58 | expect![[r#" | 38 | let d = g(S { a: arr }); |
59 | 30..31 '_': &[T] | 39 | let e: [&[_]; 1] = [arr]; |
60 | 44..55 '{ loop {} }': T | 40 | let f: [&[_]; 2] = [arr; 2]; |
61 | 46..53 'loop {}': ! | 41 | let g: (&[_], &[_]) = (arr, arr); |
62 | 51..53 '{}': () | 42 | } |
63 | 64..65 '_': S<&[T]> | 43 | "#, |
64 | 81..92 '{ loop {} }': T | ||
65 | 83..90 'loop {}': ! | ||
66 | 88..90 '{}': () | ||
67 | 121..132 '{ loop {} }': *mut [T; 2] | ||
68 | 123..130 'loop {}': ! | ||
69 | 128..130 '{}': () | ||
70 | 159..172 '{ gen() }': *mut [U] | ||
71 | 165..168 'gen': fn gen<U>() -> *mut [U; 2] | ||
72 | 165..170 'gen()': *mut [U; 2] | ||
73 | 185..419 '{ ...rr); }': () | ||
74 | 195..198 'arr': &[u8; 1] | ||
75 | 211..215 '&[1]': &[u8; 1] | ||
76 | 212..215 '[1]': [u8; 1] | ||
77 | 213..214 '1': u8 | ||
78 | 226..227 'a': &[u8] | ||
79 | 236..239 'arr': &[u8; 1] | ||
80 | 249..250 'b': u8 | ||
81 | 253..254 'f': fn f<u8>(&[u8]) -> u8 | ||
82 | 253..259 'f(arr)': u8 | ||
83 | 255..258 'arr': &[u8; 1] | ||
84 | 269..270 'c': &[u8] | ||
85 | 279..286 '{ arr }': &[u8] | ||
86 | 281..284 'arr': &[u8; 1] | ||
87 | 296..297 'd': u8 | ||
88 | 300..301 'g': fn g<u8>(S<&[u8]>) -> u8 | ||
89 | 300..315 'g(S { a: arr })': u8 | ||
90 | 302..314 'S { a: arr }': S<&[u8]> | ||
91 | 309..312 'arr': &[u8; 1] | ||
92 | 325..326 'e': [&[u8]; 1] | ||
93 | 340..345 '[arr]': [&[u8]; 1] | ||
94 | 341..344 'arr': &[u8; 1] | ||
95 | 355..356 'f': [&[u8]; 2] | ||
96 | 370..378 '[arr; 2]': [&[u8]; 2] | ||
97 | 371..374 'arr': &[u8; 1] | ||
98 | 376..377 '2': usize | ||
99 | 388..389 'g': (&[u8], &[u8]) | ||
100 | 406..416 '(arr, arr)': (&[u8], &[u8]) | ||
101 | 407..410 'arr': &[u8; 1] | ||
102 | 412..415 'arr': &[u8; 1] | ||
103 | "#]], | ||
104 | ); | 44 | ); |
105 | } | 45 | } |
106 | 46 | ||
107 | #[test] | 47 | #[test] |
108 | fn infer_let_stmt_coerce() { | 48 | fn let_stmt_coerce() { |
109 | check_infer( | 49 | check_no_mismatches( |
110 | r" | 50 | r" |
111 | fn test() { | 51 | //- minicore: coerce_unsized |
112 | let x: &[isize] = &[1]; | 52 | fn test() { |
113 | let x: *const [isize] = &[1]; | 53 | let x: &[isize] = &[1]; |
114 | } | 54 | let x: *const [isize] = &[1]; |
115 | ", | 55 | } |
116 | expect![[r#" | 56 | ", |
117 | 10..75 '{ ...[1]; }': () | ||
118 | 20..21 'x': &[isize] | ||
119 | 34..38 '&[1]': &[isize; 1] | ||
120 | 35..38 '[1]': [isize; 1] | ||
121 | 36..37 '1': isize | ||
122 | 48..49 'x': *const [isize] | ||
123 | 68..72 '&[1]': &[isize; 1] | ||
124 | 69..72 '[1]': [isize; 1] | ||
125 | 70..71 '1': isize | ||
126 | "#]], | ||
127 | ); | 57 | ); |
128 | } | 58 | } |
129 | 59 | ||
130 | #[test] | 60 | #[test] |
131 | fn infer_custom_coerce_unsized() { | 61 | fn custom_coerce_unsized() { |
132 | check_infer( | 62 | check( |
133 | r#" | 63 | r#" |
134 | struct A<T: ?Sized>(*const T); | 64 | //- minicore: coerce_unsized |
135 | struct B<T: ?Sized>(*const T); | 65 | use core::{marker::Unsize, ops::CoerceUnsized}; |
136 | struct C<T: ?Sized> { inner: *const T } | ||
137 | 66 | ||
138 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<B<U>> for B<T> {} | 67 | struct A<T: ?Sized>(*const T); |
139 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<C<U>> for C<T> {} | 68 | struct B<T: ?Sized>(*const T); |
69 | struct C<T: ?Sized> { inner: *const T } | ||
140 | 70 | ||
141 | fn foo1<T>(x: A<[T]>) -> A<[T]> { x } | 71 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<B<U>> for B<T> {} |
142 | fn foo2<T>(x: B<[T]>) -> B<[T]> { x } | 72 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<C<U>> for C<T> {} |
143 | fn foo3<T>(x: C<[T]>) -> C<[T]> { x } | ||
144 | 73 | ||
145 | fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) { | 74 | fn foo1<T>(x: A<[T]>) -> A<[T]> { x } |
146 | let d = foo1(a); | 75 | fn foo2<T>(x: B<[T]>) -> B<[T]> { x } |
147 | let e = foo2(b); | 76 | fn foo3<T>(x: C<[T]>) -> C<[T]> { x } |
148 | let f = foo3(c); | ||
149 | } | ||
150 | 77 | ||
151 | 78 | fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) { | |
152 | #[lang = "sized"] | 79 | let d = foo1(a); |
153 | pub trait Sized {} | 80 | // ^ expected A<[{unknown}]>, got A<[u8; 2]> |
154 | #[lang = "unsize"] | 81 | let e = foo2(b); |
155 | pub trait Unsize<T: ?Sized> {} | 82 | // ^ type: B<[u8]> |
156 | #[lang = "coerce_unsized"] | 83 | let f = foo3(c); |
157 | pub trait CoerceUnsized<T> {} | 84 | // ^ type: C<[u8]> |
158 | 85 | } | |
159 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | 86 | "#, |
160 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | ||
161 | "#, | ||
162 | expect![[r#" | ||
163 | 257..258 'x': A<[T]> | ||
164 | 278..283 '{ x }': A<[T]> | ||
165 | 280..281 'x': A<[T]> | ||
166 | 295..296 'x': B<[T]> | ||
167 | 316..321 '{ x }': B<[T]> | ||
168 | 318..319 'x': B<[T]> | ||
169 | 333..334 'x': C<[T]> | ||
170 | 354..359 '{ x }': C<[T]> | ||
171 | 356..357 'x': C<[T]> | ||
172 | 369..370 'a': A<[u8; 2]> | ||
173 | 384..385 'b': B<[u8; 2]> | ||
174 | 399..400 'c': C<[u8; 2]> | ||
175 | 414..480 '{ ...(c); }': () | ||
176 | 424..425 'd': A<[{unknown}]> | ||
177 | 428..432 'foo1': fn foo1<{unknown}>(A<[{unknown}]>) -> A<[{unknown}]> | ||
178 | 428..435 'foo1(a)': A<[{unknown}]> | ||
179 | 433..434 'a': A<[u8; 2]> | ||
180 | 445..446 'e': B<[u8]> | ||
181 | 449..453 'foo2': fn foo2<u8>(B<[u8]>) -> B<[u8]> | ||
182 | 449..456 'foo2(b)': B<[u8]> | ||
183 | 454..455 'b': B<[u8; 2]> | ||
184 | 466..467 'f': C<[u8]> | ||
185 | 470..474 'foo3': fn foo3<u8>(C<[u8]>) -> C<[u8]> | ||
186 | 470..477 'foo3(c)': C<[u8]> | ||
187 | 475..476 'c': C<[u8; 2]> | ||
188 | "#]], | ||
189 | ); | 87 | ); |
190 | } | 88 | } |
191 | 89 | ||
192 | #[test] | 90 | #[test] |
193 | fn infer_if_coerce() { | 91 | fn if_coerce() { |
194 | check_infer( | 92 | check_no_mismatches( |
195 | r#" | 93 | r#" |
196 | fn foo<T>(x: &[T]) -> &[T] { loop {} } | 94 | //- minicore: coerce_unsized |
197 | fn test() { | 95 | fn foo<T>(x: &[T]) -> &[T] { x } |
198 | let x = if true { | 96 | fn test() { |
199 | foo(&[1]) | 97 | let x = if true { |
200 | } else { | 98 | foo(&[1]) |
201 | &[1] | 99 | } else { |
202 | }; | 100 | &[1] |
203 | } | 101 | }; |
204 | 102 | } | |
205 | 103 | "#, | |
206 | #[lang = "sized"] | ||
207 | pub trait Sized {} | ||
208 | #[lang = "unsize"] | ||
209 | pub trait Unsize<T: ?Sized> {} | ||
210 | "#, | ||
211 | expect![[r#" | ||
212 | 10..11 'x': &[T] | ||
213 | 27..38 '{ loop {} }': &[T] | ||
214 | 29..36 'loop {}': ! | ||
215 | 34..36 '{}': () | ||
216 | 49..125 '{ ... }; }': () | ||
217 | 59..60 'x': &[i32] | ||
218 | 63..122 'if tru... }': &[i32] | ||
219 | 66..70 'true': bool | ||
220 | 71..96 '{ ... }': &[i32] | ||
221 | 81..84 'foo': fn foo<i32>(&[i32]) -> &[i32] | ||
222 | 81..90 'foo(&[1])': &[i32] | ||
223 | 85..89 '&[1]': &[i32; 1] | ||
224 | 86..89 '[1]': [i32; 1] | ||
225 | 87..88 '1': i32 | ||
226 | 102..122 '{ ... }': &[i32; 1] | ||
227 | 112..116 '&[1]': &[i32; 1] | ||
228 | 113..116 '[1]': [i32; 1] | ||
229 | 114..115 '1': i32 | ||
230 | "#]], | ||
231 | ); | 104 | ); |
232 | } | 105 | } |
233 | 106 | ||
234 | #[test] | 107 | #[test] |
235 | fn infer_if_else_coerce() { | 108 | fn if_else_coerce() { |
236 | check_infer( | 109 | check_no_mismatches( |
237 | r#" | 110 | r#" |
238 | fn foo<T>(x: &[T]) -> &[T] { loop {} } | 111 | //- minicore: coerce_unsized |
239 | fn test() { | 112 | fn foo<T>(x: &[T]) -> &[T] { x } |
240 | let x = if true { | 113 | fn test() { |
241 | &[1] | 114 | let x = if true { |
242 | } else { | 115 | &[1] |
243 | foo(&[1]) | 116 | } else { |
244 | }; | 117 | foo(&[1]) |
245 | } | 118 | }; |
246 | 119 | } | |
247 | #[lang = "sized"] | 120 | "#, |
248 | pub trait Sized {} | ||
249 | #[lang = "unsize"] | ||
250 | pub trait Unsize<T: ?Sized> {} | ||
251 | #[lang = "coerce_unsized"] | ||
252 | pub trait CoerceUnsized<T> {} | ||
253 | |||
254 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | ||
255 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | ||
256 | "#, | ||
257 | expect![[r#" | ||
258 | 10..11 'x': &[T] | ||
259 | 27..38 '{ loop {} }': &[T] | ||
260 | 29..36 'loop {}': ! | ||
261 | 34..36 '{}': () | ||
262 | 49..125 '{ ... }; }': () | ||
263 | 59..60 'x': &[i32] | ||
264 | 63..122 'if tru... }': &[i32] | ||
265 | 66..70 'true': bool | ||
266 | 71..91 '{ ... }': &[i32; 1] | ||
267 | 81..85 '&[1]': &[i32; 1] | ||
268 | 82..85 '[1]': [i32; 1] | ||
269 | 83..84 '1': i32 | ||
270 | 97..122 '{ ... }': &[i32] | ||
271 | 107..110 'foo': fn foo<i32>(&[i32]) -> &[i32] | ||
272 | 107..116 'foo(&[1])': &[i32] | ||
273 | 111..115 '&[1]': &[i32; 1] | ||
274 | 112..115 '[1]': [i32; 1] | ||
275 | 113..114 '1': i32 | ||
276 | "#]], | ||
277 | ) | 121 | ) |
278 | } | 122 | } |
279 | 123 | ||
280 | #[test] | 124 | #[test] |
281 | fn infer_match_first_coerce() { | 125 | fn match_first_coerce() { |
282 | check_infer( | 126 | check_no_mismatches( |
283 | r#" | 127 | r#" |
284 | fn foo<T>(x: &[T]) -> &[T] { loop {} } | 128 | //- minicore: coerce_unsized |
285 | fn test(i: i32) { | 129 | fn foo<T>(x: &[T]) -> &[T] { x } |
286 | let x = match i { | 130 | fn test(i: i32) { |
287 | 2 => foo(&[2]), | 131 | let x = match i { |
288 | 1 => &[1], | 132 | 2 => foo(&[2]), |
289 | _ => &[3], | 133 | 1 => &[1], |
290 | }; | 134 | _ => &[3], |
291 | } | 135 | }; |
292 | 136 | } | |
293 | #[lang = "sized"] | 137 | "#, |
294 | pub trait Sized {} | ||
295 | #[lang = "unsize"] | ||
296 | pub trait Unsize<T: ?Sized> {} | ||
297 | "#, | ||
298 | expect![[r#" | ||
299 | 10..11 'x': &[T] | ||
300 | 27..38 '{ loop {} }': &[T] | ||
301 | 29..36 'loop {}': ! | ||
302 | 34..36 '{}': () | ||
303 | 47..48 'i': i32 | ||
304 | 55..149 '{ ... }; }': () | ||
305 | 65..66 'x': &[i32] | ||
306 | 69..146 'match ... }': &[i32] | ||
307 | 75..76 'i': i32 | ||
308 | 87..88 '2': i32 | ||
309 | 87..88 '2': i32 | ||
310 | 92..95 'foo': fn foo<i32>(&[i32]) -> &[i32] | ||
311 | 92..101 'foo(&[2])': &[i32] | ||
312 | 96..100 '&[2]': &[i32; 1] | ||
313 | 97..100 '[2]': [i32; 1] | ||
314 | 98..99 '2': i32 | ||
315 | 111..112 '1': i32 | ||
316 | 111..112 '1': i32 | ||
317 | 116..120 '&[1]': &[i32; 1] | ||
318 | 117..120 '[1]': [i32; 1] | ||
319 | 118..119 '1': i32 | ||
320 | 130..131 '_': i32 | ||
321 | 135..139 '&[3]': &[i32; 1] | ||
322 | 136..139 '[3]': [i32; 1] | ||
323 | 137..138 '3': i32 | ||
324 | "#]], | ||
325 | ); | 138 | ); |
326 | } | 139 | } |
327 | 140 | ||
328 | #[test] | 141 | #[test] |
329 | fn infer_match_second_coerce() { | 142 | fn match_second_coerce() { |
330 | check_infer( | 143 | check_no_mismatches( |
331 | r#" | 144 | r#" |
332 | fn foo<T>(x: &[T]) -> &[T] { loop {} } | 145 | //- minicore: coerce_unsized |
333 | fn test(i: i32) { | 146 | fn foo<T>(x: &[T]) -> &[T] { loop {} } |
334 | let x = match i { | 147 | fn test(i: i32) { |
335 | 1 => &[1], | 148 | let x = match i { |
336 | 2 => foo(&[2]), | 149 | 1 => &[1], |
337 | _ => &[3], | 150 | 2 => foo(&[2]), |
338 | }; | 151 | _ => &[3], |
339 | } | 152 | }; |
340 | 153 | } | |
341 | #[lang = "sized"] | 154 | "#, |
342 | pub trait Sized {} | ||
343 | #[lang = "unsize"] | ||
344 | pub trait Unsize<T: ?Sized> {} | ||
345 | #[lang = "coerce_unsized"] | ||
346 | pub trait CoerceUnsized<T> {} | ||
347 | |||
348 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | ||
349 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | ||
350 | "#, | ||
351 | expect![[r#" | ||
352 | 10..11 'x': &[T] | ||
353 | 27..38 '{ loop {} }': &[T] | ||
354 | 29..36 'loop {}': ! | ||
355 | 34..36 '{}': () | ||
356 | 47..48 'i': i32 | ||
357 | 55..149 '{ ... }; }': () | ||
358 | 65..66 'x': &[i32] | ||
359 | 69..146 'match ... }': &[i32] | ||
360 | 75..76 'i': i32 | ||
361 | 87..88 '1': i32 | ||
362 | 87..88 '1': i32 | ||
363 | 92..96 '&[1]': &[i32; 1] | ||
364 | 93..96 '[1]': [i32; 1] | ||
365 | 94..95 '1': i32 | ||
366 | 106..107 '2': i32 | ||
367 | 106..107 '2': i32 | ||
368 | 111..114 'foo': fn foo<i32>(&[i32]) -> &[i32] | ||
369 | 111..120 'foo(&[2])': &[i32] | ||
370 | 115..119 '&[2]': &[i32; 1] | ||
371 | 116..119 '[2]': [i32; 1] | ||
372 | 117..118 '2': i32 | ||
373 | 130..131 '_': i32 | ||
374 | 135..139 '&[3]': &[i32; 1] | ||
375 | 136..139 '[3]': [i32; 1] | ||
376 | 137..138 '3': i32 | ||
377 | "#]], | ||
378 | ); | 155 | ); |
379 | } | 156 | } |
380 | 157 | ||
@@ -382,207 +159,103 @@ fn infer_match_second_coerce() { | |||
382 | fn coerce_merge_one_by_one1() { | 159 | fn coerce_merge_one_by_one1() { |
383 | cov_mark::check!(coerce_merge_fail_fallback); | 160 | cov_mark::check!(coerce_merge_fail_fallback); |
384 | 161 | ||
385 | check_infer( | 162 | check( |
386 | r" | 163 | r" |
387 | fn test() { | 164 | fn test() { |
388 | let t = &mut 1; | 165 | let t = &mut 1; |
389 | let x = match 1 { | 166 | let x = match 1 { |
390 | 1 => t as *mut i32, | 167 | 1 => t as *mut i32, |
391 | 2 => t as &i32, | 168 | 2 => t as &i32, |
392 | _ => t as *const i32, | 169 | //^^^^^^^^^ expected *mut i32, got &i32 |
393 | }; | 170 | _ => t as *const i32, |
394 | } | 171 | }; |
172 | x; | ||
173 | //^ type: *const i32 | ||
174 | } | ||
395 | ", | 175 | ", |
396 | expect![[r" | ||
397 | 10..144 '{ ... }; }': () | ||
398 | 20..21 't': &mut i32 | ||
399 | 24..30 '&mut 1': &mut i32 | ||
400 | 29..30 '1': i32 | ||
401 | 40..41 'x': *const i32 | ||
402 | 44..141 'match ... }': *const i32 | ||
403 | 50..51 '1': i32 | ||
404 | 62..63 '1': i32 | ||
405 | 62..63 '1': i32 | ||
406 | 67..68 't': &mut i32 | ||
407 | 67..80 't as *mut i32': *mut i32 | ||
408 | 90..91 '2': i32 | ||
409 | 90..91 '2': i32 | ||
410 | 95..96 't': &mut i32 | ||
411 | 95..104 't as &i32': &i32 | ||
412 | 114..115 '_': i32 | ||
413 | 119..120 't': &mut i32 | ||
414 | 119..134 't as *const i32': *const i32 | ||
415 | "]], | ||
416 | ); | 176 | ); |
417 | } | 177 | } |
418 | 178 | ||
419 | #[test] | 179 | #[test] |
420 | fn return_coerce_unknown() { | 180 | fn return_coerce_unknown() { |
421 | check_infer_with_mismatches( | 181 | check_types( |
422 | r" | 182 | r" |
423 | fn foo() -> u32 { | 183 | fn foo() -> u32 { |
424 | return unknown; | 184 | return unknown; |
425 | } | 185 | //^^^^^^^ u32 |
186 | } | ||
426 | ", | 187 | ", |
427 | expect![[r" | ||
428 | 16..39 '{ ...own; }': u32 | ||
429 | 22..36 'return unknown': ! | ||
430 | 29..36 'unknown': u32 | ||
431 | "]], | ||
432 | ); | 188 | ); |
433 | } | 189 | } |
434 | 190 | ||
435 | #[test] | 191 | #[test] |
436 | fn coerce_autoderef() { | 192 | fn coerce_autoderef() { |
437 | check_infer_with_mismatches( | 193 | check_no_mismatches( |
438 | r" | 194 | r" |
439 | struct Foo; | 195 | struct Foo; |
440 | fn takes_ref_foo(x: &Foo) {} | 196 | fn takes_ref_foo(x: &Foo) {} |
441 | fn test() { | 197 | fn test() { |
442 | takes_ref_foo(&Foo); | 198 | takes_ref_foo(&Foo); |
443 | takes_ref_foo(&&Foo); | 199 | takes_ref_foo(&&Foo); |
444 | takes_ref_foo(&&&Foo); | 200 | takes_ref_foo(&&&Foo); |
445 | } | 201 | }", |
446 | ", | ||
447 | expect![[r" | ||
448 | 29..30 'x': &Foo | ||
449 | 38..40 '{}': () | ||
450 | 51..132 '{ ...oo); }': () | ||
451 | 57..70 'takes_ref_foo': fn takes_ref_foo(&Foo) | ||
452 | 57..76 'takes_...(&Foo)': () | ||
453 | 71..75 '&Foo': &Foo | ||
454 | 72..75 'Foo': Foo | ||
455 | 82..95 'takes_ref_foo': fn takes_ref_foo(&Foo) | ||
456 | 82..102 'takes_...&&Foo)': () | ||
457 | 96..101 '&&Foo': &&Foo | ||
458 | 97..101 '&Foo': &Foo | ||
459 | 98..101 'Foo': Foo | ||
460 | 108..121 'takes_ref_foo': fn takes_ref_foo(&Foo) | ||
461 | 108..129 'takes_...&&Foo)': () | ||
462 | 122..128 '&&&Foo': &&&Foo | ||
463 | 123..128 '&&Foo': &&Foo | ||
464 | 124..128 '&Foo': &Foo | ||
465 | 125..128 'Foo': Foo | ||
466 | "]], | ||
467 | ); | 202 | ); |
468 | } | 203 | } |
469 | 204 | ||
470 | #[test] | 205 | #[test] |
471 | fn coerce_autoderef_generic() { | 206 | fn coerce_autoderef_generic() { |
472 | check_infer_with_mismatches( | 207 | check_no_mismatches( |
473 | r" | 208 | r#" |
474 | struct Foo; | 209 | struct Foo; |
475 | fn takes_ref<T>(x: &T) -> T { *x } | 210 | fn takes_ref<T>(x: &T) -> T { *x } |
476 | fn test() { | 211 | fn test() { |
477 | takes_ref(&Foo); | 212 | takes_ref(&Foo); |
478 | takes_ref(&&Foo); | 213 | takes_ref(&&Foo); |
479 | takes_ref(&&&Foo); | 214 | takes_ref(&&&Foo); |
480 | } | 215 | } |
481 | ", | 216 | "#, |
482 | expect![[r" | ||
483 | 28..29 'x': &T | ||
484 | 40..46 '{ *x }': T | ||
485 | 42..44 '*x': T | ||
486 | 43..44 'x': &T | ||
487 | 57..126 '{ ...oo); }': () | ||
488 | 63..72 'takes_ref': fn takes_ref<Foo>(&Foo) -> Foo | ||
489 | 63..78 'takes_ref(&Foo)': Foo | ||
490 | 73..77 '&Foo': &Foo | ||
491 | 74..77 'Foo': Foo | ||
492 | 84..93 'takes_ref': fn takes_ref<&Foo>(&&Foo) -> &Foo | ||
493 | 84..100 'takes_...&&Foo)': &Foo | ||
494 | 94..99 '&&Foo': &&Foo | ||
495 | 95..99 '&Foo': &Foo | ||
496 | 96..99 'Foo': Foo | ||
497 | 106..115 'takes_ref': fn takes_ref<&&Foo>(&&&Foo) -> &&Foo | ||
498 | 106..123 'takes_...&&Foo)': &&Foo | ||
499 | 116..122 '&&&Foo': &&&Foo | ||
500 | 117..122 '&&Foo': &&Foo | ||
501 | 118..122 '&Foo': &Foo | ||
502 | 119..122 'Foo': Foo | ||
503 | "]], | ||
504 | ); | 217 | ); |
505 | } | 218 | } |
506 | 219 | ||
507 | #[test] | 220 | #[test] |
508 | fn coerce_autoderef_block() { | 221 | fn coerce_autoderef_block() { |
509 | check_infer_with_mismatches( | 222 | check_no_mismatches( |
510 | r#" | 223 | r#" |
511 | struct String {} | 224 | //- minicore: deref |
512 | #[lang = "deref"] | 225 | struct String {} |
513 | trait Deref { type Target; } | 226 | impl core::ops::Deref for String { type Target = str; } |
514 | impl Deref for String { type Target = str; } | 227 | fn takes_ref_str(x: &str) {} |
515 | fn takes_ref_str(x: &str) {} | 228 | fn returns_string() -> String { loop {} } |
516 | fn returns_string() -> String { loop {} } | 229 | fn test() { |
517 | fn test() { | 230 | takes_ref_str(&{ returns_string() }); |
518 | takes_ref_str(&{ returns_string() }); | 231 | } |
519 | } | 232 | "#, |
520 | "#, | ||
521 | expect![[r" | ||
522 | 126..127 'x': &str | ||
523 | 135..137 '{}': () | ||
524 | 168..179 '{ loop {} }': String | ||
525 | 170..177 'loop {}': ! | ||
526 | 175..177 '{}': () | ||
527 | 190..235 '{ ... }); }': () | ||
528 | 196..209 'takes_ref_str': fn takes_ref_str(&str) | ||
529 | 196..232 'takes_...g() })': () | ||
530 | 210..231 '&{ ret...ng() }': &String | ||
531 | 211..231 '{ retu...ng() }': String | ||
532 | 213..227 'returns_string': fn returns_string() -> String | ||
533 | 213..229 'return...ring()': String | ||
534 | "]], | ||
535 | ); | 233 | ); |
536 | } | 234 | } |
537 | 235 | ||
538 | #[test] | 236 | #[test] |
539 | fn closure_return_coerce() { | 237 | fn closure_return_coerce() { |
540 | check_infer_with_mismatches( | 238 | check_no_mismatches( |
541 | r" | 239 | r" |
542 | fn foo() { | 240 | fn foo() { |
543 | let x = || { | 241 | let x = || { |
544 | if true { | 242 | if true { |
545 | return &1u32; | 243 | return &1u32; |
546 | } | ||
547 | &&1u32 | ||
548 | }; | ||
549 | } | 244 | } |
550 | ", | 245 | &&1u32 |
551 | expect![[r" | 246 | }; |
552 | 9..105 '{ ... }; }': () | 247 | }", |
553 | 19..20 'x': || -> &u32 | ||
554 | 23..102 '|| { ... }': || -> &u32 | ||
555 | 26..102 '{ ... }': &u32 | ||
556 | 36..81 'if tru... }': () | ||
557 | 39..43 'true': bool | ||
558 | 44..81 '{ ... }': () | ||
559 | 58..70 'return &1u32': ! | ||
560 | 65..70 '&1u32': &u32 | ||
561 | 66..70 '1u32': u32 | ||
562 | 90..96 '&&1u32': &&u32 | ||
563 | 91..96 '&1u32': &u32 | ||
564 | 92..96 '1u32': u32 | ||
565 | "]], | ||
566 | ); | 248 | ); |
567 | } | 249 | } |
568 | 250 | ||
569 | #[test] | 251 | #[test] |
570 | fn coerce_fn_item_to_fn_ptr() { | 252 | fn coerce_fn_item_to_fn_ptr() { |
571 | check_infer_with_mismatches( | 253 | check_no_mismatches( |
572 | r" | 254 | r" |
573 | fn foo(x: u32) -> isize { 1 } | 255 | fn foo(x: u32) -> isize { 1 } |
574 | fn test() { | 256 | fn test() { |
575 | let f: fn(u32) -> isize = foo; | 257 | let f: fn(u32) -> isize = foo; |
576 | } | 258 | }", |
577 | ", | ||
578 | expect![[r" | ||
579 | 7..8 'x': u32 | ||
580 | 24..29 '{ 1 }': isize | ||
581 | 26..27 '1': isize | ||
582 | 40..78 '{ ...foo; }': () | ||
583 | 50..51 'f': fn(u32) -> isize | ||
584 | 72..75 'foo': fn foo(u32) -> isize | ||
585 | "]], | ||
586 | ); | 259 | ); |
587 | } | 260 | } |
588 | 261 | ||
@@ -590,340 +263,160 @@ fn coerce_fn_item_to_fn_ptr() { | |||
590 | fn coerce_fn_items_in_match_arms() { | 263 | fn coerce_fn_items_in_match_arms() { |
591 | cov_mark::check!(coerce_fn_reification); | 264 | cov_mark::check!(coerce_fn_reification); |
592 | 265 | ||
593 | check_infer_with_mismatches( | 266 | check_types( |
594 | r" | 267 | r" |
595 | fn foo1(x: u32) -> isize { 1 } | 268 | fn foo1(x: u32) -> isize { 1 } |
596 | fn foo2(x: u32) -> isize { 2 } | 269 | fn foo2(x: u32) -> isize { 2 } |
597 | fn foo3(x: u32) -> isize { 3 } | 270 | fn foo3(x: u32) -> isize { 3 } |
598 | fn test() { | 271 | fn test() { |
599 | let x = match 1 { | 272 | let x = match 1 { |
600 | 1 => foo1, | 273 | 1 => foo1, |
601 | 2 => foo2, | 274 | 2 => foo2, |
602 | _ => foo3, | 275 | _ => foo3, |
603 | }; | 276 | }; |
604 | } | 277 | x; |
605 | ", | 278 | //^ fn(u32) -> isize |
606 | expect![[r" | 279 | }", |
607 | 8..9 'x': u32 | ||
608 | 25..30 '{ 1 }': isize | ||
609 | 27..28 '1': isize | ||
610 | 39..40 'x': u32 | ||
611 | 56..61 '{ 2 }': isize | ||
612 | 58..59 '2': isize | ||
613 | 70..71 'x': u32 | ||
614 | 87..92 '{ 3 }': isize | ||
615 | 89..90 '3': isize | ||
616 | 103..192 '{ ... }; }': () | ||
617 | 113..114 'x': fn(u32) -> isize | ||
618 | 117..189 'match ... }': fn(u32) -> isize | ||
619 | 123..124 '1': i32 | ||
620 | 135..136 '1': i32 | ||
621 | 135..136 '1': i32 | ||
622 | 140..144 'foo1': fn foo1(u32) -> isize | ||
623 | 154..155 '2': i32 | ||
624 | 154..155 '2': i32 | ||
625 | 159..163 'foo2': fn foo2(u32) -> isize | ||
626 | 173..174 '_': i32 | ||
627 | 178..182 'foo3': fn foo3(u32) -> isize | ||
628 | "]], | ||
629 | ); | 280 | ); |
630 | } | 281 | } |
631 | 282 | ||
632 | #[test] | 283 | #[test] |
633 | fn coerce_closure_to_fn_ptr() { | 284 | fn coerce_closure_to_fn_ptr() { |
634 | check_infer_with_mismatches( | 285 | check_no_mismatches( |
635 | r" | 286 | r" |
636 | fn test() { | 287 | fn test() { |
637 | let f: fn(u32) -> isize = |x| { 1 }; | 288 | let f: fn(u32) -> isize = |x| { 1 }; |
638 | } | 289 | }", |
639 | ", | ||
640 | expect![[r" | ||
641 | 10..54 '{ ...1 }; }': () | ||
642 | 20..21 'f': fn(u32) -> isize | ||
643 | 42..51 '|x| { 1 }': |u32| -> isize | ||
644 | 43..44 'x': u32 | ||
645 | 46..51 '{ 1 }': isize | ||
646 | 48..49 '1': isize | ||
647 | "]], | ||
648 | ); | 290 | ); |
649 | } | 291 | } |
650 | 292 | ||
651 | #[test] | 293 | #[test] |
652 | fn coerce_placeholder_ref() { | 294 | fn coerce_placeholder_ref() { |
653 | // placeholders should unify, even behind references | 295 | // placeholders should unify, even behind references |
654 | check_infer_with_mismatches( | 296 | check_no_mismatches( |
655 | r" | 297 | r" |
656 | struct S<T> { t: T } | 298 | struct S<T> { t: T } |
657 | impl<TT> S<TT> { | 299 | impl<TT> S<TT> { |
658 | fn get(&self) -> &TT { | 300 | fn get(&self) -> &TT { |
659 | &self.t | 301 | &self.t |
660 | } | 302 | } |
661 | } | 303 | }", |
662 | ", | ||
663 | expect![[r" | ||
664 | 50..54 'self': &S<TT> | ||
665 | 63..86 '{ ... }': &TT | ||
666 | 73..80 '&self.t': &TT | ||
667 | 74..78 'self': &S<TT> | ||
668 | 74..80 'self.t': TT | ||
669 | "]], | ||
670 | ); | 304 | ); |
671 | } | 305 | } |
672 | 306 | ||
673 | #[test] | 307 | #[test] |
674 | fn coerce_unsize_array() { | 308 | fn coerce_unsize_array() { |
675 | check_infer_with_mismatches( | 309 | check_types( |
676 | r#" | 310 | r#" |
677 | #[lang = "unsize"] | 311 | //- minicore: coerce_unsized |
678 | pub trait Unsize<T> {} | 312 | fn test() { |
679 | #[lang = "coerce_unsized"] | 313 | let f: &[usize] = &[1, 2, 3]; |
680 | pub trait CoerceUnsized<T> {} | 314 | //^ usize |
681 | 315 | }"#, | |
682 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
683 | |||
684 | fn test() { | ||
685 | let f: &[usize] = &[1, 2, 3]; | ||
686 | } | ||
687 | "#, | ||
688 | expect![[r#" | ||
689 | 161..198 '{ ... 3]; }': () | ||
690 | 171..172 'f': &[usize] | ||
691 | 185..195 '&[1, 2, 3]': &[usize; 3] | ||
692 | 186..195 '[1, 2, 3]': [usize; 3] | ||
693 | 187..188 '1': usize | ||
694 | 190..191 '2': usize | ||
695 | 193..194 '3': usize | ||
696 | "#]], | ||
697 | ); | 316 | ); |
698 | } | 317 | } |
699 | 318 | ||
700 | #[test] | 319 | #[test] |
701 | fn coerce_unsize_trait_object_simple() { | 320 | fn coerce_unsize_trait_object_simple() { |
702 | check_infer_with_mismatches( | 321 | check_types( |
703 | r#" | ||
704 | #[lang = "sized"] | ||
705 | pub trait Sized {} | ||
706 | #[lang = "unsize"] | ||
707 | pub trait Unsize<T> {} | ||
708 | #[lang = "coerce_unsized"] | ||
709 | pub trait CoerceUnsized<T> {} | ||
710 | |||
711 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
712 | |||
713 | trait Foo<T, U> {} | ||
714 | trait Bar<U, T, X>: Foo<T, U> {} | ||
715 | trait Baz<T, X>: Bar<usize, T, X> {} | ||
716 | |||
717 | struct S<T, X>; | ||
718 | impl<T, X> Foo<T, usize> for S<T, X> {} | ||
719 | impl<T, X> Bar<usize, T, X> for S<T, X> {} | ||
720 | impl<T, X> Baz<T, X> for S<T, X> {} | ||
721 | |||
722 | fn test() { | ||
723 | let obj: &dyn Baz<i8, i16> = &S; | ||
724 | let obj: &dyn Bar<_, i8, i16> = &S; | ||
725 | let obj: &dyn Foo<i8, _> = &S; | ||
726 | } | ||
727 | "#, | ||
728 | expect![[r" | ||
729 | 424..539 '{ ... &S; }': () | ||
730 | 434..437 'obj': &dyn Baz<i8, i16> | ||
731 | 459..461 '&S': &S<i8, i16> | ||
732 | 460..461 'S': S<i8, i16> | ||
733 | 471..474 'obj': &dyn Bar<usize, i8, i16> | ||
734 | 499..501 '&S': &S<i8, i16> | ||
735 | 500..501 'S': S<i8, i16> | ||
736 | 511..514 'obj': &dyn Foo<i8, usize> | ||
737 | 534..536 '&S': &S<i8, {unknown}> | ||
738 | 535..536 'S': S<i8, {unknown}> | ||
739 | "]], | ||
740 | ); | ||
741 | } | ||
742 | |||
743 | #[test] | ||
744 | // The rust reference says this should be possible, but rustc doesn't implement | ||
745 | // it. We used to support it, but Chalk doesn't. | ||
746 | #[ignore] | ||
747 | fn coerce_unsize_trait_object_to_trait_object() { | ||
748 | check_infer_with_mismatches( | ||
749 | r#" | 322 | r#" |
750 | #[lang = "sized"] | 323 | //- minicore: coerce_unsized |
751 | pub trait Sized {} | 324 | trait Foo<T, U> {} |
752 | #[lang = "unsize"] | 325 | trait Bar<U, T, X>: Foo<T, U> {} |
753 | pub trait Unsize<T> {} | 326 | trait Baz<T, X>: Bar<usize, T, X> {} |
754 | #[lang = "coerce_unsized"] | 327 | |
755 | pub trait CoerceUnsized<T> {} | 328 | struct S<T, X>; |
756 | 329 | impl<T, X> Foo<T, usize> for S<T, X> {} | |
757 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | 330 | impl<T, X> Bar<usize, T, X> for S<T, X> {} |
758 | 331 | impl<T, X> Baz<T, X> for S<T, X> {} | |
759 | trait Foo<T, U> {} | 332 | |
760 | trait Bar<U, T, X>: Foo<T, U> {} | 333 | fn test() { |
761 | trait Baz<T, X>: Bar<usize, T, X> {} | 334 | let obj: &dyn Baz<i8, i16> = &S; |
762 | 335 | //^ S<i8, i16> | |
763 | struct S<T, X>; | 336 | let obj: &dyn Bar<_, i8, i16> = &S; |
764 | impl<T, X> Foo<T, usize> for S<T, X> {} | 337 | //^ S<i8, i16> |
765 | impl<T, X> Bar<usize, T, X> for S<T, X> {} | 338 | let obj: &dyn Foo<i8, _> = &S; |
766 | impl<T, X> Baz<T, X> for S<T, X> {} | 339 | //^ S<i8, {unknown}> |
767 | 340 | }"#, | |
768 | fn test() { | ||
769 | let obj: &dyn Baz<i8, i16> = &S; | ||
770 | let obj: &dyn Bar<_, _, _> = obj; | ||
771 | let obj: &dyn Foo<_, _> = obj; | ||
772 | let obj2: &dyn Baz<i8, i16> = &S; | ||
773 | let _: &dyn Foo<_, _> = obj2; | ||
774 | } | ||
775 | "#, | ||
776 | expect![[r" | ||
777 | 424..609 '{ ...bj2; }': () | ||
778 | 434..437 'obj': &dyn Baz<i8, i16> | ||
779 | 459..461 '&S': &S<i8, i16> | ||
780 | 460..461 'S': S<i8, i16> | ||
781 | 471..474 'obj': &dyn Bar<usize, i8, i16> | ||
782 | 496..499 'obj': &dyn Baz<i8, i16> | ||
783 | 509..512 'obj': &dyn Foo<i8, usize> | ||
784 | 531..534 'obj': &dyn Bar<usize, i8, i16> | ||
785 | 544..548 'obj2': &dyn Baz<i8, i16> | ||
786 | 570..572 '&S': &S<i8, i16> | ||
787 | 571..572 'S': S<i8, i16> | ||
788 | 582..583 '_': &dyn Foo<i8, usize> | ||
789 | 602..606 'obj2': &dyn Baz<i8, i16> | ||
790 | "]], | ||
791 | ); | 341 | ); |
792 | } | 342 | } |
793 | 343 | ||
794 | #[test] | 344 | #[test] |
795 | fn coerce_unsize_super_trait_cycle() { | 345 | fn coerce_unsize_super_trait_cycle() { |
796 | check_infer_with_mismatches( | 346 | check_no_mismatches( |
797 | r#" | 347 | r#" |
798 | #[lang = "sized"] | 348 | //- minicore: coerce_unsized |
799 | pub trait Sized {} | 349 | trait A {} |
800 | #[lang = "unsize"] | 350 | trait B: C + A {} |
801 | pub trait Unsize<T> {} | 351 | trait C: B {} |
802 | #[lang = "coerce_unsized"] | 352 | trait D: C |
803 | pub trait CoerceUnsized<T> {} | 353 | |
804 | 354 | struct S; | |
805 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | 355 | impl A for S {} |
806 | 356 | impl B for S {} | |
807 | trait A {} | 357 | impl C for S {} |
808 | trait B: C + A {} | 358 | impl D for S {} |
809 | trait C: B {} | 359 | |
810 | trait D: C | 360 | fn test() { |
811 | 361 | let obj: &dyn D = &S; | |
812 | struct S; | 362 | let obj: &dyn A = &S; |
813 | impl A for S {} | 363 | } |
814 | impl B for S {} | 364 | "#, |
815 | impl C for S {} | ||
816 | impl D for S {} | ||
817 | |||
818 | fn test() { | ||
819 | let obj: &dyn D = &S; | ||
820 | let obj: &dyn A = &S; | ||
821 | } | ||
822 | "#, | ||
823 | expect![[r" | ||
824 | 328..383 '{ ... &S; }': () | ||
825 | 338..341 'obj': &dyn D | ||
826 | 352..354 '&S': &S | ||
827 | 353..354 'S': S | ||
828 | 364..367 'obj': &dyn A | ||
829 | 378..380 '&S': &S | ||
830 | 379..380 'S': S | ||
831 | "]], | ||
832 | ); | 365 | ); |
833 | } | 366 | } |
834 | 367 | ||
835 | #[test] | 368 | #[test] |
836 | fn coerce_unsize_generic() { | 369 | fn coerce_unsize_generic() { |
837 | // FIXME: fix the type mismatches here | 370 | // FIXME: fix the type mismatches here |
838 | check_infer_with_mismatches( | 371 | check( |
839 | r#" | 372 | r#" |
840 | #[lang = "unsize"] | 373 | //- minicore: coerce_unsized |
841 | pub trait Unsize<T> {} | 374 | struct Foo<T> { t: T }; |
842 | #[lang = "coerce_unsized"] | 375 | struct Bar<T>(Foo<T>); |
843 | pub trait CoerceUnsized<T> {} | ||
844 | |||
845 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
846 | |||
847 | struct Foo<T> { t: T }; | ||
848 | struct Bar<T>(Foo<T>); | ||
849 | 376 | ||
850 | fn test() { | 377 | fn test() { |
851 | let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; | 378 | let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; |
852 | let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); | 379 | //^^^^^^^^^ expected [usize], got [usize; 3] |
853 | } | 380 | let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); |
854 | "#, | 381 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &Bar<[usize]>, got &Bar<[i32; 3]> |
855 | expect![[r#" | 382 | } |
856 | 209..317 '{ ... }); }': () | 383 | "#, |
857 | 219..220 '_': &Foo<[usize]> | ||
858 | 238..259 '&Foo {..., 3] }': &Foo<[usize]> | ||
859 | 239..259 'Foo { ..., 3] }': Foo<[usize]> | ||
860 | 248..257 '[1, 2, 3]': [usize; 3] | ||
861 | 249..250 '1': usize | ||
862 | 252..253 '2': usize | ||
863 | 255..256 '3': usize | ||
864 | 269..270 '_': &Bar<[usize]> | ||
865 | 288..314 '&Bar(F... 3] })': &Bar<[i32; 3]> | ||
866 | 289..292 'Bar': Bar<[i32; 3]>(Foo<[i32; 3]>) -> Bar<[i32; 3]> | ||
867 | 289..314 'Bar(Fo... 3] })': Bar<[i32; 3]> | ||
868 | 293..313 'Foo { ..., 3] }': Foo<[i32; 3]> | ||
869 | 302..311 '[1, 2, 3]': [i32; 3] | ||
870 | 303..304 '1': i32 | ||
871 | 306..307 '2': i32 | ||
872 | 309..310 '3': i32 | ||
873 | 248..257: expected [usize], got [usize; 3] | ||
874 | 288..314: expected &Bar<[usize]>, got &Bar<[i32; 3]> | ||
875 | "#]], | ||
876 | ); | 384 | ); |
877 | } | 385 | } |
878 | 386 | ||
879 | #[test] | 387 | #[test] |
880 | fn coerce_unsize_apit() { | 388 | fn coerce_unsize_apit() { |
881 | // FIXME: #8984 | 389 | // FIXME: #8984 |
882 | check_infer_with_mismatches( | 390 | check( |
883 | r#" | 391 | r#" |
884 | #[lang = "sized"] | 392 | //- minicore: coerce_unsized |
885 | pub trait Sized {} | ||
886 | #[lang = "unsize"] | ||
887 | pub trait Unsize<T> {} | ||
888 | #[lang = "coerce_unsized"] | ||
889 | pub trait CoerceUnsized<T> {} | ||
890 | |||
891 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
892 | |||
893 | trait Foo {} | 393 | trait Foo {} |
894 | 394 | ||
895 | fn test(f: impl Foo) { | 395 | fn test(f: impl Foo) { |
896 | let _: &dyn Foo = &f; | 396 | let _: &dyn Foo = &f; |
397 | //^^ expected &dyn Foo, got &impl Foo | ||
897 | } | 398 | } |
898 | "#, | 399 | "#, |
899 | expect![[r#" | ||
900 | 210..211 'f': impl Foo | ||
901 | 223..252 '{ ... &f; }': () | ||
902 | 233..234 '_': &dyn Foo | ||
903 | 247..249 '&f': &impl Foo | ||
904 | 248..249 'f': impl Foo | ||
905 | 247..249: expected &dyn Foo, got &impl Foo | ||
906 | "#]], | ||
907 | ); | 400 | ); |
908 | } | 401 | } |
909 | 402 | ||
910 | #[test] | 403 | #[test] |
911 | fn infer_two_closures_lub() { | 404 | fn two_closures_lub() { |
912 | check_types( | 405 | check_types( |
913 | r#" | 406 | r#" |
914 | fn foo(c: i32) { | 407 | fn foo(c: i32) { |
915 | let add = |a: i32, b: i32| a + b; | 408 | let add = |a: i32, b: i32| a + b; |
916 | let sub = |a, b| a - b; | 409 | let sub = |a, b| a - b; |
917 | //^ |i32, i32| -> i32 | 410 | //^^^^^^^^^^^^ |i32, i32| -> i32 |
918 | if c > 42 { add } else { sub }; | 411 | if c > 42 { add } else { sub }; |
919 | //^ fn(i32, i32) -> i32 | 412 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ fn(i32, i32) -> i32 |
920 | } | 413 | } |
921 | "#, | 414 | "#, |
922 | ) | 415 | ) |
923 | } | 416 | } |
924 | 417 | ||
925 | #[test] | 418 | #[test] |
926 | fn infer_match_diverging_branch_1() { | 419 | fn match_diverging_branch_1() { |
927 | check_types( | 420 | check_types( |
928 | r#" | 421 | r#" |
929 | enum Result<T> { Ok(T), Err } | 422 | enum Result<T> { Ok(T), Err } |
@@ -942,7 +435,7 @@ fn test() -> i32 { | |||
942 | } | 435 | } |
943 | 436 | ||
944 | #[test] | 437 | #[test] |
945 | fn infer_match_diverging_branch_2() { | 438 | fn match_diverging_branch_2() { |
946 | // same as 1 except for order of branches | 439 | // same as 1 except for order of branches |
947 | check_types( | 440 | check_types( |
948 | r#" | 441 | r#" |
@@ -998,15 +491,7 @@ fn main() { | |||
998 | fn coerce_unsize_expected_type() { | 491 | fn coerce_unsize_expected_type() { |
999 | check_no_mismatches( | 492 | check_no_mismatches( |
1000 | r#" | 493 | r#" |
1001 | #[lang = "sized"] | 494 | //- minicore: coerce_unsized |
1002 | pub trait Sized {} | ||
1003 | #[lang = "unsize"] | ||
1004 | pub trait Unsize<T> {} | ||
1005 | #[lang = "coerce_unsized"] | ||
1006 | pub trait CoerceUnsized<T> {} | ||
1007 | |||
1008 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
1009 | |||
1010 | fn main() { | 495 | fn main() { |
1011 | let foo: &[u32] = &[1, 2]; | 496 | let foo: &[u32] = &[1, 2]; |
1012 | let foo: &[u32] = match true { | 497 | let foo: &[u32] = match true { |
diff --git a/crates/hir_ty/src/tests/display_source_code.rs b/crates/hir_ty/src/tests/display_source_code.rs index 3d29021aa..058cd02d7 100644 --- a/crates/hir_ty/src/tests/display_source_code.rs +++ b/crates/hir_ty/src/tests/display_source_code.rs | |||
@@ -10,8 +10,8 @@ mod foo { | |||
10 | 10 | ||
11 | fn bar() { | 11 | fn bar() { |
12 | let foo: foo::Foo = foo::Foo; | 12 | let foo: foo::Foo = foo::Foo; |
13 | foo | 13 | foo; |
14 | } //^ foo::Foo | 14 | } //^^^ foo::Foo |
15 | 15 | ||
16 | "#, | 16 | "#, |
17 | ); | 17 | ); |
@@ -25,7 +25,7 @@ struct Foo<T = u8> { t: T } | |||
25 | fn main() { | 25 | fn main() { |
26 | let foo = Foo { t: 5u8 }; | 26 | let foo = Foo { t: 5u8 }; |
27 | foo; | 27 | foo; |
28 | } //^ Foo | 28 | } //^^^ Foo |
29 | "#, | 29 | "#, |
30 | ); | 30 | ); |
31 | 31 | ||
@@ -35,7 +35,7 @@ struct Foo<K, T = u8> { k: K, t: T } | |||
35 | fn main() { | 35 | fn main() { |
36 | let foo = Foo { k: 400, t: 5u8 }; | 36 | let foo = Foo { k: 400, t: 5u8 }; |
37 | foo; | 37 | foo; |
38 | } //^ Foo<i32> | 38 | } //^^^ Foo<i32> |
39 | "#, | 39 | "#, |
40 | ); | 40 | ); |
41 | } | 41 | } |
@@ -50,7 +50,7 @@ fn foo() -> *const (impl Unpin + Sized) { loop {} } | |||
50 | fn main() { | 50 | fn main() { |
51 | let foo = foo(); | 51 | let foo = foo(); |
52 | foo; | 52 | foo; |
53 | } //^ *const (impl Unpin + Sized) | 53 | } //^^^ *const (impl Unpin + Sized) |
54 | "#, | 54 | "#, |
55 | ); | 55 | ); |
56 | } | 56 | } |
diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index d14103aab..2cf41e49e 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs | |||
@@ -435,11 +435,11 @@ fn processes_impls_generated_by_macros() { | |||
435 | macro_rules! m { | 435 | macro_rules! m { |
436 | ($ident:ident) => (impl Trait for $ident {}) | 436 | ($ident:ident) => (impl Trait for $ident {}) |
437 | } | 437 | } |
438 | trait Trait { fn foo(self) -> u128 {} } | 438 | trait Trait { fn foo(self) -> u128 { 0 } } |
439 | struct S; | 439 | struct S; |
440 | m!(S); | 440 | m!(S); |
441 | fn test() { S.foo(); } | 441 | fn test() { S.foo(); } |
442 | //^ u128 | 442 | //^^^^^^^ u128 |
443 | "#, | 443 | "#, |
444 | ); | 444 | ); |
445 | } | 445 | } |
@@ -457,7 +457,7 @@ impl S { | |||
457 | } | 457 | } |
458 | 458 | ||
459 | fn test() { S.foo(); } | 459 | fn test() { S.foo(); } |
460 | //^ u128 | 460 | //^^^^^^^ u128 |
461 | "#, | 461 | "#, |
462 | ); | 462 | ); |
463 | } | 463 | } |
@@ -479,7 +479,7 @@ impl S { | |||
479 | } | 479 | } |
480 | 480 | ||
481 | fn test() { S.foo(); } | 481 | fn test() { S.foo(); } |
482 | //^ u128 | 482 | //^^^^^^^ u128 |
483 | "#, | 483 | "#, |
484 | ); | 484 | ); |
485 | } | 485 | } |
@@ -743,7 +743,7 @@ include!("foo.rs"); | |||
743 | 743 | ||
744 | fn main() { | 744 | fn main() { |
745 | bar(); | 745 | bar(); |
746 | } //^ u32 | 746 | } //^^^^^ u32 |
747 | 747 | ||
748 | //- /foo.rs | 748 | //- /foo.rs |
749 | fn bar() -> u32 {0} | 749 | fn bar() -> u32 {0} |
@@ -781,7 +781,7 @@ include!("f/foo.rs"); | |||
781 | 781 | ||
782 | fn main() { | 782 | fn main() { |
783 | bar::bar(); | 783 | bar::bar(); |
784 | } //^ u32 | 784 | } //^^^^^^^^^^ u32 |
785 | 785 | ||
786 | //- /f/foo.rs | 786 | //- /f/foo.rs |
787 | pub mod bar; | 787 | pub mod bar; |
@@ -853,7 +853,7 @@ include!("foo.rs"); | |||
853 | 853 | ||
854 | fn main() { | 854 | fn main() { |
855 | RegisterBlock { }; | 855 | RegisterBlock { }; |
856 | //^ RegisterBlock | 856 | //^^^^^^^^^^^^^^^^^ RegisterBlock |
857 | } | 857 | } |
858 | "#; | 858 | "#; |
859 | let fixture = format!("{}\n//- /foo.rs\n{}", fixture, data); | 859 | let fixture = format!("{}\n//- /foo.rs\n{}", fixture, data); |
@@ -879,7 +879,7 @@ include!(concat!("f", "oo.rs")); | |||
879 | 879 | ||
880 | fn main() { | 880 | fn main() { |
881 | bar(); | 881 | bar(); |
882 | } //^ u32 | 882 | } //^^^^^ u32 |
883 | 883 | ||
884 | //- /foo.rs | 884 | //- /foo.rs |
885 | fn bar() -> u32 {0} | 885 | fn bar() -> u32 {0} |
@@ -905,7 +905,7 @@ include!(concat!(env!("OUT_DIR"), "/foo.rs")); | |||
905 | 905 | ||
906 | fn main() { | 906 | fn main() { |
907 | bar(); | 907 | bar(); |
908 | } //^ {unknown} | 908 | } //^^^^^ {unknown} |
909 | 909 | ||
910 | //- /foo.rs | 910 | //- /foo.rs |
911 | fn bar() -> u32 {0} | 911 | fn bar() -> u32 {0} |
@@ -923,7 +923,7 @@ macro_rules! include {() => {}} | |||
923 | include!("main.rs"); | 923 | include!("main.rs"); |
924 | 924 | ||
925 | fn main() { | 925 | fn main() { |
926 | 0 | 926 | 0; |
927 | } //^ i32 | 927 | } //^ i32 |
928 | "#, | 928 | "#, |
929 | ); | 929 | ); |
@@ -979,7 +979,7 @@ fn infer_derive_clone_simple() { | |||
979 | struct S; | 979 | struct S; |
980 | fn test() { | 980 | fn test() { |
981 | S.clone(); | 981 | S.clone(); |
982 | } //^ S | 982 | } //^^^^^^^^^ S |
983 | 983 | ||
984 | //- /lib.rs crate:core | 984 | //- /lib.rs crate:core |
985 | pub mod prelude { | 985 | pub mod prelude { |
@@ -1028,7 +1028,7 @@ pub struct S; | |||
1028 | use core::S; | 1028 | use core::S; |
1029 | fn test() { | 1029 | fn test() { |
1030 | S.clone(); | 1030 | S.clone(); |
1031 | } //^ S | 1031 | } //^^^^^^^^^ S |
1032 | "#, | 1032 | "#, |
1033 | ); | 1033 | ); |
1034 | } | 1034 | } |
@@ -1044,7 +1044,8 @@ struct S; | |||
1044 | struct Wrapper<T>(T); | 1044 | struct Wrapper<T>(T); |
1045 | struct NonClone; | 1045 | struct NonClone; |
1046 | fn test() { | 1046 | fn test() { |
1047 | (Wrapper(S).clone(), Wrapper(NonClone).clone()); | 1047 | let x = (Wrapper(S).clone(), Wrapper(NonClone).clone()); |
1048 | x; | ||
1048 | //^ (Wrapper<S>, {unknown}) | 1049 | //^ (Wrapper<S>, {unknown}) |
1049 | } | 1050 | } |
1050 | 1051 | ||
@@ -1079,7 +1080,7 @@ struct S{} | |||
1079 | 1080 | ||
1080 | fn test() { | 1081 | fn test() { |
1081 | S{}; | 1082 | S{}; |
1082 | } //^ S | 1083 | } //^^^ S |
1083 | "#, | 1084 | "#, |
1084 | ); | 1085 | ); |
1085 | } | 1086 | } |
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index f26b2c8a7..3f7a37295 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs | |||
@@ -257,7 +257,7 @@ fn test() { | |||
257 | mod foo { | 257 | mod foo { |
258 | struct S; | 258 | struct S; |
259 | impl S { | 259 | impl S { |
260 | fn thing() -> i128 {} | 260 | fn thing() -> i128 { 0 } |
261 | } | 261 | } |
262 | } | 262 | } |
263 | "#, | 263 | "#, |
@@ -267,164 +267,128 @@ mod foo { | |||
267 | #[test] | 267 | #[test] |
268 | fn infer_trait_method_simple() { | 268 | fn infer_trait_method_simple() { |
269 | // the trait implementation is intentionally incomplete -- it shouldn't matter | 269 | // the trait implementation is intentionally incomplete -- it shouldn't matter |
270 | check_infer( | 270 | check_types( |
271 | r#" | 271 | r#" |
272 | trait Trait1 { | 272 | trait Trait1 { |
273 | fn method(&self) -> u32; | 273 | fn method(&self) -> u32; |
274 | } | 274 | } |
275 | struct S1; | 275 | struct S1; |
276 | impl Trait1 for S1 {} | 276 | impl Trait1 for S1 {} |
277 | trait Trait2 { | 277 | trait Trait2 { |
278 | fn method(&self) -> i128; | 278 | fn method(&self) -> i128; |
279 | } | 279 | } |
280 | struct S2; | 280 | struct S2; |
281 | impl Trait2 for S2 {} | 281 | impl Trait2 for S2 {} |
282 | fn test() { | 282 | fn test() { |
283 | S1.method(); // -> u32 | 283 | S1.method(); |
284 | S2.method(); // -> i128 | 284 | //^^^^^^^^^^^ u32 |
285 | } | 285 | S2.method(); // -> i128 |
286 | //^^^^^^^^^^^ i128 | ||
287 | } | ||
286 | "#, | 288 | "#, |
287 | expect![[r#" | ||
288 | 30..34 'self': &Self | ||
289 | 109..113 'self': &Self | ||
290 | 169..227 '{ ...i128 }': () | ||
291 | 175..177 'S1': S1 | ||
292 | 175..186 'S1.method()': u32 | ||
293 | 202..204 'S2': S2 | ||
294 | 202..213 'S2.method()': i128 | ||
295 | "#]], | ||
296 | ); | 289 | ); |
297 | } | 290 | } |
298 | 291 | ||
299 | #[test] | 292 | #[test] |
300 | fn infer_trait_method_scoped() { | 293 | fn infer_trait_method_scoped() { |
301 | // the trait implementation is intentionally incomplete -- it shouldn't matter | 294 | // the trait implementation is intentionally incomplete -- it shouldn't matter |
302 | check_infer( | 295 | check_types( |
303 | r#" | 296 | r#" |
304 | struct S; | 297 | struct S; |
305 | mod foo { | 298 | mod foo { |
306 | pub trait Trait1 { | 299 | pub trait Trait1 { |
307 | fn method(&self) -> u32; | 300 | fn method(&self) -> u32; |
308 | } | 301 | } |
309 | impl Trait1 for super::S {} | 302 | impl Trait1 for super::S {} |
310 | } | 303 | } |
311 | mod bar { | 304 | mod bar { |
312 | pub trait Trait2 { | 305 | pub trait Trait2 { |
313 | fn method(&self) -> i128; | 306 | fn method(&self) -> i128; |
314 | } | 307 | } |
315 | impl Trait2 for super::S {} | 308 | impl Trait2 for super::S {} |
316 | } | 309 | } |
317 | 310 | ||
318 | mod foo_test { | 311 | mod foo_test { |
319 | use super::S; | 312 | use super::S; |
320 | use super::foo::Trait1; | 313 | use super::foo::Trait1; |
321 | fn test() { | 314 | fn test() { |
322 | S.method(); // -> u32 | 315 | S.method(); |
323 | } | 316 | //^^^^^^^^^^ u32 |
324 | } | 317 | } |
318 | } | ||
325 | 319 | ||
326 | mod bar_test { | 320 | mod bar_test { |
327 | use super::S; | 321 | use super::S; |
328 | use super::bar::Trait2; | 322 | use super::bar::Trait2; |
329 | fn test() { | 323 | fn test() { |
330 | S.method(); // -> i128 | 324 | S.method(); |
331 | } | 325 | //^^^^^^^^^^ i128 |
332 | } | 326 | } |
327 | } | ||
333 | "#, | 328 | "#, |
334 | expect![[r#" | ||
335 | 62..66 'self': &Self | ||
336 | 168..172 'self': &Self | ||
337 | 299..336 '{ ... }': () | ||
338 | 309..310 'S': S | ||
339 | 309..319 'S.method()': u32 | ||
340 | 415..453 '{ ... }': () | ||
341 | 425..426 'S': S | ||
342 | 425..435 'S.method()': i128 | ||
343 | "#]], | ||
344 | ); | 329 | ); |
345 | } | 330 | } |
346 | 331 | ||
347 | #[test] | 332 | #[test] |
348 | fn infer_trait_method_generic_1() { | 333 | fn infer_trait_method_generic_1() { |
349 | // the trait implementation is intentionally incomplete -- it shouldn't matter | 334 | // the trait implementation is intentionally incomplete -- it shouldn't matter |
350 | check_infer( | 335 | check_types( |
351 | r#" | 336 | r#" |
352 | trait Trait<T> { | 337 | trait Trait<T> { |
353 | fn method(&self) -> T; | 338 | fn method(&self) -> T; |
354 | } | 339 | } |
355 | struct S; | 340 | struct S; |
356 | impl Trait<u32> for S {} | 341 | impl Trait<u32> for S {} |
357 | fn test() { | 342 | fn test() { |
358 | S.method(); | 343 | S.method(); |
359 | } | 344 | //^^^^^^^^^^ u32 |
345 | } | ||
360 | "#, | 346 | "#, |
361 | expect![[r#" | ||
362 | 32..36 'self': &Self | ||
363 | 91..110 '{ ...d(); }': () | ||
364 | 97..98 'S': S | ||
365 | 97..107 'S.method()': u32 | ||
366 | "#]], | ||
367 | ); | 347 | ); |
368 | } | 348 | } |
369 | 349 | ||
370 | #[test] | 350 | #[test] |
371 | fn infer_trait_method_generic_more_params() { | 351 | fn infer_trait_method_generic_more_params() { |
372 | // the trait implementation is intentionally incomplete -- it shouldn't matter | 352 | // the trait implementation is intentionally incomplete -- it shouldn't matter |
373 | check_infer( | 353 | check_types( |
374 | r#" | 354 | r#" |
375 | trait Trait<T1, T2, T3> { | 355 | trait Trait<T1, T2, T3> { |
376 | fn method1(&self) -> (T1, T2, T3); | 356 | fn method1(&self) -> (T1, T2, T3); |
377 | fn method2(&self) -> (T3, T2, T1); | 357 | fn method2(&self) -> (T3, T2, T1); |
378 | } | 358 | } |
379 | struct S1; | 359 | struct S1; |
380 | impl Trait<u8, u16, u32> for S1 {} | 360 | impl Trait<u8, u16, u32> for S1 {} |
381 | struct S2; | 361 | struct S2; |
382 | impl<T> Trait<i8, i16, T> for S2 {} | 362 | impl<T> Trait<i8, i16, T> for S2 {} |
383 | fn test() { | 363 | fn test() { |
384 | S1.method1(); // u8, u16, u32 | 364 | S1.method1(); |
385 | S1.method2(); // u32, u16, u8 | 365 | //^^^^^^^^^^^^ (u8, u16, u32) |
386 | S2.method1(); // i8, i16, {unknown} | 366 | S1.method2(); |
387 | S2.method2(); // {unknown}, i16, i8 | 367 | //^^^^^^^^^^^^ (u32, u16, u8) |
388 | } | 368 | S2.method1(); |
369 | //^^^^^^^^^^^^ (i8, i16, {unknown}) | ||
370 | S2.method2(); | ||
371 | //^^^^^^^^^^^^ ({unknown}, i16, i8) | ||
372 | } | ||
389 | "#, | 373 | "#, |
390 | expect![[r#" | ||
391 | 42..46 'self': &Self | ||
392 | 81..85 'self': &Self | ||
393 | 209..360 '{ ..., i8 }': () | ||
394 | 215..217 'S1': S1 | ||
395 | 215..227 'S1.method1()': (u8, u16, u32) | ||
396 | 249..251 'S1': S1 | ||
397 | 249..261 'S1.method2()': (u32, u16, u8) | ||
398 | 283..285 'S2': S2 | ||
399 | 283..295 'S2.method1()': (i8, i16, {unknown}) | ||
400 | 323..325 'S2': S2 | ||
401 | 323..335 'S2.method2()': ({unknown}, i16, i8) | ||
402 | "#]], | ||
403 | ); | 374 | ); |
404 | } | 375 | } |
405 | 376 | ||
406 | #[test] | 377 | #[test] |
407 | fn infer_trait_method_generic_2() { | 378 | fn infer_trait_method_generic_2() { |
408 | // the trait implementation is intentionally incomplete -- it shouldn't matter | 379 | // the trait implementation is intentionally incomplete -- it shouldn't matter |
409 | check_infer( | 380 | check_types( |
410 | r#" | 381 | r#" |
411 | trait Trait<T> { | 382 | trait Trait<T> { |
412 | fn method(&self) -> T; | 383 | fn method(&self) -> T; |
413 | } | 384 | } |
414 | struct S<T>(T); | 385 | struct S<T>(T); |
415 | impl<U> Trait<U> for S<U> {} | 386 | impl<U> Trait<U> for S<U> {} |
416 | fn test() { | 387 | fn test() { |
417 | S(1u32).method(); | 388 | S(1u32).method(); |
418 | } | 389 | //^^^^^^^^^^^^^^^^ u32 |
390 | } | ||
419 | "#, | 391 | "#, |
420 | expect![[r#" | ||
421 | 32..36 'self': &Self | ||
422 | 101..126 '{ ...d(); }': () | ||
423 | 107..108 'S': S<u32>(u32) -> S<u32> | ||
424 | 107..114 'S(1u32)': S<u32> | ||
425 | 107..123 'S(1u32...thod()': u32 | ||
426 | 109..113 '1u32': u32 | ||
427 | "#]], | ||
428 | ); | 392 | ); |
429 | } | 393 | } |
430 | 394 | ||
@@ -685,10 +649,10 @@ fn method_resolution_unify_impl_self_type() { | |||
685 | check_types( | 649 | check_types( |
686 | r#" | 650 | r#" |
687 | struct S<T>; | 651 | struct S<T>; |
688 | impl S<u32> { fn foo(&self) -> u8 {} } | 652 | impl S<u32> { fn foo(&self) -> u8 { 0 } } |
689 | impl S<i32> { fn foo(&self) -> i8 {} } | 653 | impl S<i32> { fn foo(&self) -> i8 { 0 } } |
690 | fn test() { (S::<u32>.foo(), S::<i32>.foo()); } | 654 | fn test() { (S::<u32>.foo(), S::<i32>.foo()); } |
691 | //^ (u8, i8) | 655 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (u8, i8) |
692 | "#, | 656 | "#, |
693 | ); | 657 | ); |
694 | } | 658 | } |
@@ -702,7 +666,7 @@ struct S; | |||
702 | impl S { fn foo(&self) -> i8 { 0 } } | 666 | impl S { fn foo(&self) -> i8 { 0 } } |
703 | impl Trait for S { fn foo(self) -> u128 { 0 } } | 667 | impl Trait for S { fn foo(self) -> u128 { 0 } } |
704 | fn test() { S.foo(); } | 668 | fn test() { S.foo(); } |
705 | //^ u128 | 669 | //^^^^^^^ u128 |
706 | "#, | 670 | "#, |
707 | ); | 671 | ); |
708 | } | 672 | } |
@@ -716,7 +680,7 @@ struct S; | |||
716 | impl Clone for S {} | 680 | impl Clone for S {} |
717 | impl Clone for &S {} | 681 | impl Clone for &S {} |
718 | fn test() { (S.clone(), (&S).clone(), (&&S).clone()); } | 682 | fn test() { (S.clone(), (&S).clone(), (&&S).clone()); } |
719 | //^ (S, S, &S) | 683 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (S, S, &S) |
720 | "#, | 684 | "#, |
721 | ); | 685 | ); |
722 | } | 686 | } |
@@ -730,7 +694,7 @@ struct S; | |||
730 | impl S { fn foo(self) -> i8 { 0 } } | 694 | impl S { fn foo(self) -> i8 { 0 } } |
731 | impl Trait for &S { fn foo(self) -> u128 { 0 } } | 695 | impl Trait for &S { fn foo(self) -> u128 { 0 } } |
732 | fn test() { (&S).foo(); } | 696 | fn test() { (&S).foo(); } |
733 | //^ u128 | 697 | //^^^^^^^^^^ u128 |
734 | "#, | 698 | "#, |
735 | ); | 699 | ); |
736 | } | 700 | } |
@@ -744,7 +708,7 @@ struct S; | |||
744 | impl S { fn foo(self) -> i8 { 0 } } | 708 | impl S { fn foo(self) -> i8 { 0 } } |
745 | impl Trait for S { fn foo(self) -> u128 { 0 } } | 709 | impl Trait for S { fn foo(self) -> u128 { 0 } } |
746 | fn test() { S.foo(); } | 710 | fn test() { S.foo(); } |
747 | //^ i8 | 711 | //^^^^^^^ i8 |
748 | "#, | 712 | "#, |
749 | ); | 713 | ); |
750 | } | 714 | } |
@@ -758,7 +722,7 @@ struct S; | |||
758 | impl S { fn foo(&self) -> i8 { 0 } } | 722 | impl S { fn foo(&self) -> i8 { 0 } } |
759 | impl Trait for &S { fn foo(self) -> u128 { 0 } } | 723 | impl Trait for &S { fn foo(self) -> u128 { 0 } } |
760 | fn test() { S.foo(); } | 724 | fn test() { S.foo(); } |
761 | //^ i8 | 725 | //^^^^^^^ i8 |
762 | "#, | 726 | "#, |
763 | ); | 727 | ); |
764 | } | 728 | } |
@@ -771,7 +735,7 @@ trait Trait { fn foo(self) -> u128; } | |||
771 | struct S; | 735 | struct S; |
772 | impl Trait for S { fn foo(self) -> u128 { 0 } } | 736 | impl Trait for S { fn foo(self) -> u128 { 0 } } |
773 | fn test() { (&S).foo(); } | 737 | fn test() { (&S).foo(); } |
774 | //^ u128 | 738 | //^^^^^^^^^^ u128 |
775 | "#, | 739 | "#, |
776 | ); | 740 | ); |
777 | } | 741 | } |
@@ -780,14 +744,11 @@ fn test() { (&S).foo(); } | |||
780 | fn method_resolution_unsize_array() { | 744 | fn method_resolution_unsize_array() { |
781 | check_types( | 745 | check_types( |
782 | r#" | 746 | r#" |
783 | #[lang = "slice"] | 747 | //- minicore: slice |
784 | impl<T> [T] { | ||
785 | fn len(&self) -> usize { loop {} } | ||
786 | } | ||
787 | fn test() { | 748 | fn test() { |
788 | let a = [1, 2, 3]; | 749 | let a = [1, 2, 3]; |
789 | a.len(); | 750 | a.len(); |
790 | } //^ usize | 751 | } //^^^^^^^ usize |
791 | "#, | 752 | "#, |
792 | ); | 753 | ); |
793 | } | 754 | } |
@@ -802,7 +763,7 @@ impl Clone for S {} | |||
802 | 763 | ||
803 | fn test() { | 764 | fn test() { |
804 | S.clone(); | 765 | S.clone(); |
805 | //^ S | 766 | //^^^^^^^^^ S |
806 | } | 767 | } |
807 | 768 | ||
808 | //- /lib.rs crate:core | 769 | //- /lib.rs crate:core |
@@ -826,7 +787,7 @@ trait Trait { fn foo(self) -> u128; } | |||
826 | struct S; | 787 | struct S; |
827 | impl<T> Trait for T where T: UnknownTrait {} | 788 | impl<T> Trait for T where T: UnknownTrait {} |
828 | fn test() { (&S).foo(); } | 789 | fn test() { (&S).foo(); } |
829 | //^ u128 | 790 | //^^^^^^^^^^ u128 |
830 | "#, | 791 | "#, |
831 | ); | 792 | ); |
832 | } | 793 | } |
@@ -844,7 +805,7 @@ trait Trait { fn foo(self) -> u128; } | |||
844 | struct S; | 805 | struct S; |
845 | impl<T> Trait for T where T: Clone {} | 806 | impl<T> Trait for T where T: Clone {} |
846 | fn test() { (&S).foo(); } | 807 | fn test() { (&S).foo(); } |
847 | //^ {unknown} | 808 | //^^^^^^^^^^ {unknown} |
848 | "#, | 809 | "#, |
849 | ); | 810 | ); |
850 | } | 811 | } |
@@ -859,7 +820,7 @@ trait Trait { fn foo(self) -> u128; } | |||
859 | struct S; | 820 | struct S; |
860 | impl<T: Clone> Trait for T {} | 821 | impl<T: Clone> Trait for T {} |
861 | fn test() { (&S).foo(); } | 822 | fn test() { (&S).foo(); } |
862 | //^ {unknown} | 823 | //^^^^^^^^^^ {unknown} |
863 | "#, | 824 | "#, |
864 | ); | 825 | ); |
865 | } | 826 | } |
@@ -874,7 +835,7 @@ struct S; | |||
874 | impl Clone for S {} | 835 | impl Clone for S {} |
875 | impl<T> Trait for T where T: Clone {} | 836 | impl<T> Trait for T where T: Clone {} |
876 | fn test() { S.foo(); } | 837 | fn test() { S.foo(); } |
877 | //^ u128 | 838 | //^^^^^^^ u128 |
878 | "#, | 839 | "#, |
879 | ); | 840 | ); |
880 | } | 841 | } |
@@ -890,7 +851,7 @@ struct S2; | |||
890 | impl From<S2> for S1 {} | 851 | impl From<S2> for S1 {} |
891 | impl<T, U> Into<U> for T where U: From<T> {} | 852 | impl<T, U> Into<U> for T where U: From<T> {} |
892 | fn test() { S2.into(); } | 853 | fn test() { S2.into(); } |
893 | //^ {unknown} | 854 | //^^^^^^^^^ {unknown} |
894 | "#, | 855 | "#, |
895 | ); | 856 | ); |
896 | } | 857 | } |
@@ -906,7 +867,7 @@ struct S2; | |||
906 | impl From<S2> for S1 {} | 867 | impl From<S2> for S1 {} |
907 | impl<T, U: From<T>> Into<U> for T {} | 868 | impl<T, U: From<T>> Into<U> for T {} |
908 | fn test() { S2.into(); } | 869 | fn test() { S2.into(); } |
909 | //^ {unknown} | 870 | //^^^^^^^^^ {unknown} |
910 | "#, | 871 | "#, |
911 | ); | 872 | ); |
912 | } | 873 | } |
@@ -936,7 +897,7 @@ fn main() { | |||
936 | let a = Wrapper::<Foo<f32>>::new(1.0); | 897 | let a = Wrapper::<Foo<f32>>::new(1.0); |
937 | let b = Wrapper::<Bar<f32>>::new(1.0); | 898 | let b = Wrapper::<Bar<f32>>::new(1.0); |
938 | (a, b); | 899 | (a, b); |
939 | //^ (Wrapper<Foo<f32>>, Wrapper<Bar<f32>>) | 900 | //^^^^^^ (Wrapper<Foo<f32>>, Wrapper<Bar<f32>>) |
940 | } | 901 | } |
941 | "#, | 902 | "#, |
942 | ); | 903 | ); |
@@ -950,7 +911,7 @@ fn method_resolution_encountering_fn_type() { | |||
950 | fn foo() {} | 911 | fn foo() {} |
951 | trait FnOnce { fn call(self); } | 912 | trait FnOnce { fn call(self); } |
952 | fn test() { foo.call(); } | 913 | fn test() { foo.call(); } |
953 | //^ {unknown} | 914 | //^^^^^^^^^^ {unknown} |
954 | "#, | 915 | "#, |
955 | ); | 916 | ); |
956 | } | 917 | } |
@@ -1016,7 +977,7 @@ where | |||
1016 | Wrapper<T>: a::Foo, | 977 | Wrapper<T>: a::Foo, |
1017 | { | 978 | { |
1018 | t.foo(); | 979 | t.foo(); |
1019 | } //^ {unknown} | 980 | } //^^^^^^^ {unknown} |
1020 | "#, | 981 | "#, |
1021 | ); | 982 | ); |
1022 | } | 983 | } |
@@ -1033,7 +994,7 @@ impl A<i32> { | |||
1033 | 994 | ||
1034 | fn main() { | 995 | fn main() { |
1035 | A::from(3); | 996 | A::from(3); |
1036 | } //^ A<i32> | 997 | } //^^^^^^^^^^ A<i32> |
1037 | "#, | 998 | "#, |
1038 | ); | 999 | ); |
1039 | } | 1000 | } |
@@ -1061,7 +1022,7 @@ trait FnX {} | |||
1061 | impl<B, C> Trait for S<B, C> where C: FnX, B: SendX {} | 1022 | impl<B, C> Trait for S<B, C> where C: FnX, B: SendX {} |
1062 | 1023 | ||
1063 | fn test() { (S {}).method(); } | 1024 | fn test() { (S {}).method(); } |
1064 | //^ () | 1025 | //^^^^^^^^^^^^^^^ () |
1065 | "#, | 1026 | "#, |
1066 | ); | 1027 | ); |
1067 | } | 1028 | } |
@@ -1146,8 +1107,8 @@ impl<T> Slice<T> { | |||
1146 | 1107 | ||
1147 | fn main() { | 1108 | fn main() { |
1148 | let foo: Slice<u32>; | 1109 | let foo: Slice<u32>; |
1149 | (foo.into_vec()); // we don't actually support arbitrary self types, but we shouldn't crash at least | 1110 | foo.into_vec(); // we shouldn't crash on this at least |
1150 | } //^ {unknown} | 1111 | } //^^^^^^^^^^^^^^ {unknown} |
1151 | "#, | 1112 | "#, |
1152 | ); | 1113 | ); |
1153 | } | 1114 | } |
@@ -1168,7 +1129,7 @@ impl dyn Foo + '_ { | |||
1168 | fn main() { | 1129 | fn main() { |
1169 | let f = &42u32 as &dyn Foo; | 1130 | let f = &42u32 as &dyn Foo; |
1170 | f.dyn_foo(); | 1131 | f.dyn_foo(); |
1171 | // ^u32 | 1132 | // ^^^^^^^^^^^ u32 |
1172 | } | 1133 | } |
1173 | "#, | 1134 | "#, |
1174 | ); | 1135 | ); |
@@ -1178,11 +1139,7 @@ fn main() { | |||
1178 | fn autoderef_visibility_field() { | 1139 | fn autoderef_visibility_field() { |
1179 | check_infer( | 1140 | check_infer( |
1180 | r#" | 1141 | r#" |
1181 | #[lang = "deref"] | 1142 | //- minicore: deref |
1182 | pub trait Deref { | ||
1183 | type Target; | ||
1184 | fn deref(&self) -> &Self::Target; | ||
1185 | } | ||
1186 | mod a { | 1143 | mod a { |
1187 | pub struct Foo(pub char); | 1144 | pub struct Foo(pub char); |
1188 | pub struct Bar(i32); | 1145 | pub struct Bar(i32); |
@@ -1191,7 +1148,7 @@ mod a { | |||
1191 | Self(0) | 1148 | Self(0) |
1192 | } | 1149 | } |
1193 | } | 1150 | } |
1194 | impl super::Deref for Bar { | 1151 | impl core::ops::Deref for Bar { |
1195 | type Target = Foo; | 1152 | type Target = Foo; |
1196 | fn deref(&self) -> &Foo { | 1153 | fn deref(&self) -> &Foo { |
1197 | &Foo('z') | 1154 | &Foo('z') |
@@ -1205,22 +1162,21 @@ mod b { | |||
1205 | } | 1162 | } |
1206 | "#, | 1163 | "#, |
1207 | expect![[r#" | 1164 | expect![[r#" |
1208 | 67..71 'self': &Self | 1165 | 107..138 '{ ... }': Bar |
1209 | 200..231 '{ ... }': Bar | 1166 | 121..125 'Self': Bar(i32) -> Bar |
1210 | 214..218 'Self': Bar(i32) -> Bar | 1167 | 121..128 'Self(0)': Bar |
1211 | 214..221 'Self(0)': Bar | 1168 | 126..127 '0': i32 |
1212 | 219..220 '0': i32 | 1169 | 226..230 'self': &Bar |
1213 | 315..319 'self': &Bar | 1170 | 240..273 '{ ... }': &Foo |
1214 | 329..362 '{ ... }': &Foo | 1171 | 254..263 '&Foo('z')': &Foo |
1215 | 343..352 '&Foo('z')': &Foo | 1172 | 255..258 'Foo': Foo(char) -> Foo |
1216 | 344..347 'Foo': Foo(char) -> Foo | 1173 | 255..263 'Foo('z')': Foo |
1217 | 344..352 'Foo('z')': Foo | 1174 | 259..262 ''z'': char |
1218 | 348..351 ''z'': char | 1175 | 303..350 '{ ... }': () |
1219 | 392..439 '{ ... }': () | 1176 | 317..318 'x': char |
1220 | 406..407 'x': char | 1177 | 321..339 'super:...r::new': fn new() -> Bar |
1221 | 410..428 'super:...r::new': fn new() -> Bar | 1178 | 321..341 'super:...:new()': Bar |
1222 | 410..430 'super:...:new()': Bar | 1179 | 321..343 'super:...ew().0': char |
1223 | 410..432 'super:...ew().0': char | ||
1224 | "#]], | 1180 | "#]], |
1225 | ) | 1181 | ) |
1226 | } | 1182 | } |
@@ -1230,11 +1186,7 @@ fn autoderef_visibility_method() { | |||
1230 | cov_mark::check!(autoderef_candidate_not_visible); | 1186 | cov_mark::check!(autoderef_candidate_not_visible); |
1231 | check_infer( | 1187 | check_infer( |
1232 | r#" | 1188 | r#" |
1233 | #[lang = "deref"] | 1189 | //- minicore: deref |
1234 | pub trait Deref { | ||
1235 | type Target; | ||
1236 | fn deref(&self) -> &Self::Target; | ||
1237 | } | ||
1238 | mod a { | 1190 | mod a { |
1239 | pub struct Foo(pub char); | 1191 | pub struct Foo(pub char); |
1240 | impl Foo { | 1192 | impl Foo { |
@@ -1251,7 +1203,7 @@ mod a { | |||
1251 | self.0 | 1203 | self.0 |
1252 | } | 1204 | } |
1253 | } | 1205 | } |
1254 | impl super::Deref for Bar { | 1206 | impl core::ops::Deref for Bar { |
1255 | type Target = Foo; | 1207 | type Target = Foo; |
1256 | fn deref(&self) -> &Foo { | 1208 | fn deref(&self) -> &Foo { |
1257 | &Foo('z') | 1209 | &Foo('z') |
@@ -1265,30 +1217,29 @@ mod b { | |||
1265 | } | 1217 | } |
1266 | "#, | 1218 | "#, |
1267 | expect![[r#" | 1219 | expect![[r#" |
1268 | 67..71 'self': &Self | 1220 | 75..79 'self': &Foo |
1269 | 168..172 'self': &Foo | 1221 | 89..119 '{ ... }': char |
1270 | 182..212 '{ ... }': char | 1222 | 103..107 'self': &Foo |
1271 | 196..200 'self': &Foo | 1223 | 103..109 'self.0': char |
1272 | 196..202 'self.0': char | 1224 | 195..226 '{ ... }': Bar |
1273 | 288..319 '{ ... }': Bar | 1225 | 209..213 'Self': Bar(i32) -> Bar |
1274 | 302..306 'Self': Bar(i32) -> Bar | 1226 | 209..216 'Self(0)': Bar |
1275 | 302..309 'Self(0)': Bar | 1227 | 214..215 '0': i32 |
1276 | 307..308 '0': i32 | 1228 | 245..249 'self': &Bar |
1277 | 338..342 'self': &Bar | 1229 | 258..288 '{ ... }': i32 |
1278 | 351..381 '{ ... }': i32 | 1230 | 272..276 'self': &Bar |
1279 | 365..369 'self': &Bar | 1231 | 272..278 'self.0': i32 |
1280 | 365..371 'self.0': i32 | 1232 | 376..380 'self': &Bar |
1281 | 465..469 'self': &Bar | 1233 | 390..423 '{ ... }': &Foo |
1282 | 479..512 '{ ... }': &Foo | 1234 | 404..413 '&Foo('z')': &Foo |
1283 | 493..502 '&Foo('z')': &Foo | 1235 | 405..408 'Foo': Foo(char) -> Foo |
1284 | 494..497 'Foo': Foo(char) -> Foo | 1236 | 405..413 'Foo('z')': Foo |
1285 | 494..502 'Foo('z')': Foo | 1237 | 409..412 ''z'': char |
1286 | 498..501 ''z'': char | 1238 | 453..506 '{ ... }': () |
1287 | 542..595 '{ ... }': () | 1239 | 467..468 'x': char |
1288 | 556..557 'x': char | 1240 | 471..489 'super:...r::new': fn new() -> Bar |
1289 | 560..578 'super:...r::new': fn new() -> Bar | 1241 | 471..491 'super:...:new()': Bar |
1290 | 560..580 'super:...:new()': Bar | 1242 | 471..499 'super:...ango()': char |
1291 | 560..588 'super:...ango()': char | ||
1292 | "#]], | 1243 | "#]], |
1293 | ) | 1244 | ) |
1294 | } | 1245 | } |
@@ -1389,11 +1340,11 @@ pub trait IntoIterator { | |||
1389 | 1340 | ||
1390 | impl<T> IntoIterator for [T; 1] { | 1341 | impl<T> IntoIterator for [T; 1] { |
1391 | type Out = T; | 1342 | type Out = T; |
1392 | fn into_iter(self) -> Self::Out {} | 1343 | fn into_iter(self) -> Self::Out { loop {} } |
1393 | } | 1344 | } |
1394 | impl<'a, T> IntoIterator for &'a [T] { | 1345 | impl<'a, T> IntoIterator for &'a [T] { |
1395 | type Out = &'a T; | 1346 | type Out = &'a T; |
1396 | fn into_iter(self) -> Self::Out {} | 1347 | fn into_iter(self) -> Self::Out { loop {} } |
1397 | } | 1348 | } |
1398 | "#, | 1349 | "#, |
1399 | ); | 1350 | ); |
diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs index aa513c56d..47aa30d2e 100644 --- a/crates/hir_ty/src/tests/patterns.rs +++ b/crates/hir_ty/src/tests/patterns.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use expect_test::expect; | 1 | use expect_test::expect; |
2 | 2 | ||
3 | use super::{check_infer, check_infer_with_mismatches, check_mismatches, check_types}; | 3 | use super::{check, check_infer, check_infer_with_mismatches, check_types}; |
4 | 4 | ||
5 | #[test] | 5 | #[test] |
6 | fn infer_pattern() { | 6 | fn infer_pattern() { |
@@ -518,7 +518,7 @@ fn infer_generics_in_patterns() { | |||
518 | 518 | ||
519 | #[test] | 519 | #[test] |
520 | fn infer_const_pattern() { | 520 | fn infer_const_pattern() { |
521 | check_mismatches( | 521 | check( |
522 | r#" | 522 | r#" |
523 | enum Option<T> { None } | 523 | enum Option<T> { None } |
524 | use Option::None; | 524 | use Option::None; |
@@ -571,48 +571,44 @@ fn main() { | |||
571 | fn match_ergonomics_in_closure_params() { | 571 | fn match_ergonomics_in_closure_params() { |
572 | check_infer( | 572 | check_infer( |
573 | r#" | 573 | r#" |
574 | #[lang = "fn_once"] | 574 | //- minicore: fn |
575 | trait FnOnce<Args> { | 575 | fn foo<T, U, F: FnOnce(T) -> U>(t: T, f: F) -> U { loop {} } |
576 | type Output; | ||
577 | } | ||
578 | |||
579 | fn foo<T, U, F: FnOnce(T) -> U>(t: T, f: F) -> U { loop {} } | ||
580 | 576 | ||
581 | fn test() { | 577 | fn test() { |
582 | foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics | 578 | foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics |
583 | foo(&(1, "a"), |(x, y)| x); | 579 | foo(&(1, "a"), |(x, y)| x); |
584 | } | 580 | } |
585 | "#, | 581 | "#, |
586 | expect![[r#" | 582 | expect![[r#" |
587 | 93..94 't': T | 583 | 32..33 't': T |
588 | 99..100 'f': F | 584 | 38..39 'f': F |
589 | 110..121 '{ loop {} }': U | 585 | 49..60 '{ loop {} }': U |
590 | 112..119 'loop {}': ! | 586 | 51..58 'loop {}': ! |
591 | 117..119 '{}': () | 587 | 56..58 '{}': () |
592 | 133..232 '{ ... x); }': () | 588 | 72..171 '{ ... x); }': () |
593 | 139..142 'foo': fn foo<&(i32, &str), i32, |&(i32, &str)| -> i32>(&(i32, &str), |&(i32, &str)| -> i32) -> i32 | 589 | 78..81 'foo': fn foo<&(i32, &str), i32, |&(i32, &str)| -> i32>(&(i32, &str), |&(i32, &str)| -> i32) -> i32 |
594 | 139..166 'foo(&(...y)| x)': i32 | 590 | 78..105 'foo(&(...y)| x)': i32 |
595 | 143..152 '&(1, "a")': &(i32, &str) | 591 | 82..91 '&(1, "a")': &(i32, &str) |
596 | 144..152 '(1, "a")': (i32, &str) | 592 | 83..91 '(1, "a")': (i32, &str) |
597 | 145..146 '1': i32 | 593 | 84..85 '1': i32 |
598 | 148..151 '"a"': &str | 594 | 87..90 '"a"': &str |
599 | 154..165 '|&(x, y)| x': |&(i32, &str)| -> i32 | 595 | 93..104 '|&(x, y)| x': |&(i32, &str)| -> i32 |
600 | 155..162 '&(x, y)': &(i32, &str) | 596 | 94..101 '&(x, y)': &(i32, &str) |
601 | 156..162 '(x, y)': (i32, &str) | 597 | 95..101 '(x, y)': (i32, &str) |
602 | 157..158 'x': i32 | 598 | 96..97 'x': i32 |
603 | 160..161 'y': &str | 599 | 99..100 'y': &str |
604 | 164..165 'x': i32 | 600 | 103..104 'x': i32 |
605 | 203..206 'foo': fn foo<&(i32, &str), &i32, |&(i32, &str)| -> &i32>(&(i32, &str), |&(i32, &str)| -> &i32) -> &i32 | 601 | 142..145 'foo': fn foo<&(i32, &str), &i32, |&(i32, &str)| -> &i32>(&(i32, &str), |&(i32, &str)| -> &i32) -> &i32 |
606 | 203..229 'foo(&(...y)| x)': &i32 | 602 | 142..168 'foo(&(...y)| x)': &i32 |
607 | 207..216 '&(1, "a")': &(i32, &str) | 603 | 146..155 '&(1, "a")': &(i32, &str) |
608 | 208..216 '(1, "a")': (i32, &str) | 604 | 147..155 '(1, "a")': (i32, &str) |
609 | 209..210 '1': i32 | 605 | 148..149 '1': i32 |
610 | 212..215 '"a"': &str | 606 | 151..154 '"a"': &str |
611 | 218..228 '|(x, y)| x': |&(i32, &str)| -> &i32 | 607 | 157..167 '|(x, y)| x': |&(i32, &str)| -> &i32 |
612 | 219..225 '(x, y)': (i32, &str) | 608 | 158..164 '(x, y)': (i32, &str) |
613 | 220..221 'x': &i32 | 609 | 159..160 'x': &i32 |
614 | 223..224 'y': &&str | 610 | 162..163 'y': &&str |
615 | 227..228 'x': &i32 | 611 | 166..167 'x': &i32 |
616 | "#]], | 612 | "#]], |
617 | ); | 613 | ); |
618 | } | 614 | } |
diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 1019e783b..8c5e8954c 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use expect_test::expect; | 1 | use expect_test::expect; |
2 | 2 | ||
3 | use super::{check_infer, check_types}; | 3 | use super::{check_infer, check_no_mismatches, check_types}; |
4 | 4 | ||
5 | #[test] | 5 | #[test] |
6 | fn bug_484() { | 6 | fn bug_484() { |
@@ -418,55 +418,24 @@ fn issue_2705() { | |||
418 | fn issue_2683_chars_impl() { | 418 | fn issue_2683_chars_impl() { |
419 | check_types( | 419 | check_types( |
420 | r#" | 420 | r#" |
421 | //- /main.rs crate:main deps:std | 421 | //- minicore: iterator |
422 | fn test() { | 422 | pub struct Chars<'a> {} |
423 | let chars: std::str::Chars<'_>; | 423 | impl<'a> Iterator for Chars<'a> { |
424 | (chars.next(), chars.nth(1)); | 424 | type Item = char; |
425 | } //^ (Option<char>, Option<char>) | 425 | fn next(&mut self) -> Option<char> { loop {} } |
426 | |||
427 | //- /std.rs crate:std | ||
428 | #[prelude_import] | ||
429 | use self::prelude::rust_2018::*; | ||
430 | pub mod prelude { | ||
431 | pub mod rust_2018 { | ||
432 | pub use crate::iter::Iterator; | ||
433 | pub use crate::option::Option; | ||
434 | } | ||
435 | } | 426 | } |
436 | 427 | ||
437 | pub mod iter { | 428 | fn test() { |
438 | pub use self::traits::Iterator; | 429 | let chars: Chars<'_>; |
439 | pub mod traits { | 430 | (chars.next(), chars.nth(1)); |
440 | pub use self::iterator::Iterator; | 431 | } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (Option<char>, Option<char>) |
441 | |||
442 | pub mod iterator { | ||
443 | pub trait Iterator { | ||
444 | type Item; | ||
445 | fn next(&mut self) -> Option<Self::Item>; | ||
446 | fn nth(&mut self, n: usize) -> Option<Self::Item> {} | ||
447 | } | ||
448 | } | ||
449 | } | ||
450 | } | ||
451 | |||
452 | pub mod option { | ||
453 | pub enum Option<T> {} | ||
454 | } | ||
455 | |||
456 | pub mod str { | ||
457 | pub struct Chars<'a> {} | ||
458 | impl<'a> Iterator for Chars<'a> { | ||
459 | type Item = char; | ||
460 | fn next(&mut self) -> Option<char> {} | ||
461 | } | ||
462 | } | ||
463 | "#, | 432 | "#, |
464 | ); | 433 | ); |
465 | } | 434 | } |
466 | 435 | ||
467 | #[test] | 436 | #[test] |
468 | fn issue_3642_bad_macro_stackover() { | 437 | fn issue_3642_bad_macro_stackover() { |
469 | check_types( | 438 | check_no_mismatches( |
470 | r#" | 439 | r#" |
471 | #[macro_export] | 440 | #[macro_export] |
472 | macro_rules! match_ast { | 441 | macro_rules! match_ast { |
@@ -483,7 +452,6 @@ macro_rules! match_ast { | |||
483 | 452 | ||
484 | fn main() { | 453 | fn main() { |
485 | let anchor = match_ast! { | 454 | let anchor = match_ast! { |
486 | //^ () | ||
487 | match parent { | 455 | match parent { |
488 | as => {}, | 456 | as => {}, |
489 | _ => return None | 457 | _ => return None |
@@ -736,12 +704,8 @@ fn issue_4931() { | |||
736 | fn issue_4885() { | 704 | fn issue_4885() { |
737 | check_infer( | 705 | check_infer( |
738 | r#" | 706 | r#" |
739 | #[lang = "coerce_unsized"] | 707 | //- minicore: coerce_unsized, future |
740 | pub trait CoerceUnsized<T> {} | 708 | use core::future::Future; |
741 | |||
742 | trait Future { | ||
743 | type Output; | ||
744 | } | ||
745 | trait Foo<R> { | 709 | trait Foo<R> { |
746 | type Bar; | 710 | type Bar; |
747 | } | 711 | } |
@@ -758,13 +722,13 @@ fn issue_4885() { | |||
758 | } | 722 | } |
759 | "#, | 723 | "#, |
760 | expect![[r#" | 724 | expect![[r#" |
761 | 136..139 'key': &K | 725 | 70..73 'key': &K |
762 | 198..214 '{ ...key) }': impl Future<Output = <K as Foo<R>>::Bar> | 726 | 132..148 '{ ...key) }': impl Future<Output = <K as Foo<R>>::Bar> |
763 | 204..207 'bar': fn bar<R, K>(&K) -> impl Future<Output = <K as Foo<R>>::Bar> | 727 | 138..141 'bar': fn bar<R, K>(&K) -> impl Future<Output = <K as Foo<R>>::Bar> |
764 | 204..212 'bar(key)': impl Future<Output = <K as Foo<R>>::Bar> | 728 | 138..146 'bar(key)': impl Future<Output = <K as Foo<R>>::Bar> |
765 | 208..211 'key': &K | 729 | 142..145 'key': &K |
766 | 228..231 'key': &K | 730 | 162..165 'key': &K |
767 | 290..293 '{ }': () | 731 | 224..227 '{ }': () |
768 | "#]], | 732 | "#]], |
769 | ); | 733 | ); |
770 | } | 734 | } |
@@ -827,6 +791,7 @@ fn issue_4800() { | |||
827 | fn issue_4966() { | 791 | fn issue_4966() { |
828 | check_infer( | 792 | check_infer( |
829 | r#" | 793 | r#" |
794 | //- minicore: deref | ||
830 | pub trait IntoIterator { | 795 | pub trait IntoIterator { |
831 | type Item; | 796 | type Item; |
832 | } | 797 | } |
@@ -837,12 +802,7 @@ fn issue_4966() { | |||
837 | 802 | ||
838 | struct Vec<T> {} | 803 | struct Vec<T> {} |
839 | 804 | ||
840 | #[lang = "deref"] | 805 | impl<T> core::ops::Deref for Vec<T> { |
841 | pub trait Deref { | ||
842 | type Target; | ||
843 | } | ||
844 | |||
845 | impl<T> Deref for Vec<T> { | ||
846 | type Target = [T]; | 806 | type Target = [T]; |
847 | } | 807 | } |
848 | 808 | ||
@@ -859,23 +819,23 @@ fn issue_4966() { | |||
859 | } | 819 | } |
860 | "#, | 820 | "#, |
861 | expect![[r#" | 821 | expect![[r#" |
862 | 270..274 'iter': T | 822 | 225..229 'iter': T |
863 | 289..291 '{}': () | 823 | 244..246 '{}': () |
864 | 303..447 '{ ...r(); }': () | 824 | 258..402 '{ ...r(); }': () |
865 | 313..318 'inner': Map<|&f64| -> f64> | 825 | 268..273 'inner': Map<|&f64| -> f64> |
866 | 321..345 'Map { ... 0.0 }': Map<|&f64| -> f64> | 826 | 276..300 'Map { ... 0.0 }': Map<|&f64| -> f64> |
867 | 330..343 '|_: &f64| 0.0': |&f64| -> f64 | 827 | 285..298 '|_: &f64| 0.0': |&f64| -> f64 |
868 | 331..332 '_': &f64 | 828 | 286..287 '_': &f64 |
869 | 340..343 '0.0': f64 | 829 | 295..298 '0.0': f64 |
870 | 356..362 'repeat': Repeat<Map<|&f64| -> f64>> | 830 | 311..317 'repeat': Repeat<Map<|&f64| -> f64>> |
871 | 365..390 'Repeat...nner }': Repeat<Map<|&f64| -> f64>> | 831 | 320..345 'Repeat...nner }': Repeat<Map<|&f64| -> f64>> |
872 | 383..388 'inner': Map<|&f64| -> f64> | 832 | 338..343 'inner': Map<|&f64| -> f64> |
873 | 401..404 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> | 833 | 356..359 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> |
874 | 407..416 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> | 834 | 362..371 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> |
875 | 407..424 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> | 835 | 362..379 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> |
876 | 417..423 'repeat': Repeat<Map<|&f64| -> f64>> | 836 | 372..378 'repeat': Repeat<Map<|&f64| -> f64>> |
877 | 431..434 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> | 837 | 386..389 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> |
878 | 431..444 'vec.foo_bar()': {unknown} | 838 | 386..399 'vec.foo_bar()': {unknown} |
879 | "#]], | 839 | "#]], |
880 | ); | 840 | ); |
881 | } | 841 | } |
@@ -884,41 +844,37 @@ fn issue_4966() { | |||
884 | fn issue_6628() { | 844 | fn issue_6628() { |
885 | check_infer( | 845 | check_infer( |
886 | r#" | 846 | r#" |
887 | #[lang = "fn_once"] | 847 | //- minicore: fn |
888 | pub trait FnOnce<Args> { | 848 | struct S<T>(); |
889 | type Output; | 849 | impl<T> S<T> { |
890 | } | 850 | fn f(&self, _t: T) {} |
891 | 851 | fn g<F: FnOnce(&T)>(&self, _f: F) {} | |
892 | struct S<T>(); | 852 | } |
893 | impl<T> S<T> { | 853 | fn main() { |
894 | fn f(&self, _t: T) {} | 854 | let s = S(); |
895 | fn g<F: FnOnce(&T)>(&self, _f: F) {} | 855 | s.g(|_x| {}); |
896 | } | 856 | s.f(10); |
897 | fn main() { | 857 | } |
898 | let s = S(); | 858 | "#, |
899 | s.g(|_x| {}); | ||
900 | s.f(10); | ||
901 | } | ||
902 | "#, | ||
903 | expect![[r#" | 859 | expect![[r#" |
904 | 105..109 'self': &S<T> | 860 | 40..44 'self': &S<T> |
905 | 111..113 '_t': T | 861 | 46..48 '_t': T |
906 | 118..120 '{}': () | 862 | 53..55 '{}': () |
907 | 146..150 'self': &S<T> | 863 | 81..85 'self': &S<T> |
908 | 152..154 '_f': F | 864 | 87..89 '_f': F |
909 | 159..161 '{}': () | 865 | 94..96 '{}': () |
910 | 174..225 '{ ...10); }': () | 866 | 109..160 '{ ...10); }': () |
911 | 184..185 's': S<i32> | 867 | 119..120 's': S<i32> |
912 | 188..189 'S': S<i32>() -> S<i32> | 868 | 123..124 'S': S<i32>() -> S<i32> |
913 | 188..191 'S()': S<i32> | 869 | 123..126 'S()': S<i32> |
914 | 197..198 's': S<i32> | 870 | 132..133 's': S<i32> |
915 | 197..209 's.g(|_x| {})': () | 871 | 132..144 's.g(|_x| {})': () |
916 | 201..208 '|_x| {}': |&i32| -> () | 872 | 136..143 '|_x| {}': |&i32| -> () |
917 | 202..204 '_x': &i32 | 873 | 137..139 '_x': &i32 |
918 | 206..208 '{}': () | 874 | 141..143 '{}': () |
919 | 215..216 's': S<i32> | 875 | 150..151 's': S<i32> |
920 | 215..222 's.f(10)': () | 876 | 150..157 's.f(10)': () |
921 | 219..221 '10': i32 | 877 | 154..156 '10': i32 |
922 | "#]], | 878 | "#]], |
923 | ); | 879 | ); |
924 | } | 880 | } |
@@ -927,35 +883,33 @@ fn issue_6628() { | |||
927 | fn issue_6852() { | 883 | fn issue_6852() { |
928 | check_infer( | 884 | check_infer( |
929 | r#" | 885 | r#" |
930 | #[lang = "deref"] | 886 | //- minicore: deref |
931 | pub trait Deref { | 887 | use core::ops::Deref; |
932 | type Target; | ||
933 | } | ||
934 | 888 | ||
935 | struct BufWriter {} | 889 | struct BufWriter {} |
936 | 890 | ||
937 | struct Mutex<T> {} | 891 | struct Mutex<T> {} |
938 | struct MutexGuard<'a, T> {} | 892 | struct MutexGuard<'a, T> {} |
939 | impl<T> Mutex<T> { | 893 | impl<T> Mutex<T> { |
940 | fn lock(&self) -> MutexGuard<'_, T> {} | 894 | fn lock(&self) -> MutexGuard<'_, T> {} |
941 | } | 895 | } |
942 | impl<'a, T: 'a> Deref for MutexGuard<'a, T> { | 896 | impl<'a, T: 'a> Deref for MutexGuard<'a, T> { |
943 | type Target = T; | 897 | type Target = T; |
944 | } | 898 | } |
945 | fn flush(&self) { | 899 | fn flush(&self) { |
946 | let w: &Mutex<BufWriter>; | 900 | let w: &Mutex<BufWriter>; |
947 | *(w.lock()); | 901 | *(w.lock()); |
948 | } | 902 | } |
949 | "#, | 903 | "#, |
950 | expect![[r#" | 904 | expect![[r#" |
951 | 156..160 'self': &Mutex<T> | 905 | 123..127 'self': &Mutex<T> |
952 | 183..185 '{}': () | 906 | 150..152 '{}': () |
953 | 267..271 'self': &{unknown} | 907 | 234..238 'self': &{unknown} |
954 | 273..323 '{ ...()); }': () | 908 | 240..290 '{ ...()); }': () |
955 | 283..284 'w': &Mutex<BufWriter> | 909 | 250..251 'w': &Mutex<BufWriter> |
956 | 309..320 '*(w.lock())': BufWriter | 910 | 276..287 '*(w.lock())': BufWriter |
957 | 311..312 'w': &Mutex<BufWriter> | 911 | 278..279 'w': &Mutex<BufWriter> |
958 | 311..319 'w.lock()': MutexGuard<BufWriter> | 912 | 278..286 'w.lock()': MutexGuard<BufWriter> |
959 | "#]], | 913 | "#]], |
960 | ); | 914 | ); |
961 | } | 915 | } |
@@ -977,37 +931,33 @@ fn param_overrides_fn() { | |||
977 | fn lifetime_from_chalk_during_deref() { | 931 | fn lifetime_from_chalk_during_deref() { |
978 | check_types( | 932 | check_types( |
979 | r#" | 933 | r#" |
980 | #[lang = "deref"] | 934 | //- minicore: deref |
981 | pub trait Deref { | 935 | struct Box<T: ?Sized> {} |
982 | type Target; | 936 | impl<T> core::ops::Deref for Box<T> { |
983 | } | 937 | type Target = T; |
984 | |||
985 | struct Box<T: ?Sized> {} | ||
986 | impl<T> Deref for Box<T> { | ||
987 | type Target = T; | ||
988 | 938 | ||
989 | fn deref(&self) -> &Self::Target { | 939 | fn deref(&self) -> &Self::Target { |
990 | loop {} | 940 | loop {} |
991 | } | 941 | } |
992 | } | 942 | } |
993 | 943 | ||
994 | trait Iterator { | 944 | trait Iterator { |
995 | type Item; | 945 | type Item; |
996 | } | 946 | } |
997 | 947 | ||
998 | pub struct Iter<'a, T: 'a> { | 948 | pub struct Iter<'a, T: 'a> { |
999 | inner: Box<dyn IterTrait<'a, T, Item = &'a T> + 'a>, | 949 | inner: Box<dyn IterTrait<'a, T, Item = &'a T> + 'a>, |
1000 | } | 950 | } |
1001 | 951 | ||
1002 | trait IterTrait<'a, T: 'a>: Iterator<Item = &'a T> { | 952 | trait IterTrait<'a, T: 'a>: Iterator<Item = &'a T> { |
1003 | fn clone_box(&self); | 953 | fn clone_box(&self); |
1004 | } | 954 | } |
1005 | 955 | ||
1006 | fn clone_iter<T>(s: Iter<T>) { | 956 | fn clone_iter<T>(s: Iter<T>) { |
1007 | s.inner.clone_box(); | 957 | s.inner.clone_box(); |
1008 | //^^^^^^^^^^^^^^^^^^^ () | 958 | //^^^^^^^^^^^^^^^^^^^ () |
1009 | } | 959 | } |
1010 | "#, | 960 | "#, |
1011 | ) | 961 | ) |
1012 | } | 962 | } |
1013 | 963 | ||
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index 3418ed21e..b4bcc6d95 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs | |||
@@ -60,7 +60,7 @@ enum Nat { Succ(Self), Demo(Nat), Zero } | |||
60 | fn test() { | 60 | fn test() { |
61 | let foo: Nat = Nat::Zero; | 61 | let foo: Nat = Nat::Zero; |
62 | if let Nat::Succ(x) = foo { | 62 | if let Nat::Succ(x) = foo { |
63 | x | 63 | x; |
64 | } //^ Nat | 64 | } //^ Nat |
65 | } | 65 | } |
66 | "#, | 66 | "#, |
@@ -113,7 +113,7 @@ fn type_alias_in_struct_lit() { | |||
113 | fn infer_ranges() { | 113 | fn infer_ranges() { |
114 | check_types( | 114 | check_types( |
115 | r#" | 115 | r#" |
116 | //- /main.rs crate:main deps:core | 116 | //- minicore: range |
117 | fn test() { | 117 | fn test() { |
118 | let a = ..; | 118 | let a = ..; |
119 | let b = 1..; | 119 | let b = 1..; |
@@ -125,32 +125,6 @@ fn test() { | |||
125 | let t = (a, b, c, d, e, f); | 125 | let t = (a, b, c, d, e, f); |
126 | t; | 126 | t; |
127 | } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>) | 127 | } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>) |
128 | |||
129 | //- /core.rs crate:core | ||
130 | #[prelude_import] use prelude::*; | ||
131 | mod prelude {} | ||
132 | |||
133 | pub mod ops { | ||
134 | pub struct Range<Idx> { | ||
135 | pub start: Idx, | ||
136 | pub end: Idx, | ||
137 | } | ||
138 | pub struct RangeFrom<Idx> { | ||
139 | pub start: Idx, | ||
140 | } | ||
141 | struct RangeFull; | ||
142 | pub struct RangeInclusive<Idx> { | ||
143 | start: Idx, | ||
144 | end: Idx, | ||
145 | is_empty: u8, | ||
146 | } | ||
147 | pub struct RangeTo<Idx> { | ||
148 | pub end: Idx, | ||
149 | } | ||
150 | pub struct RangeToInclusive<Idx> { | ||
151 | pub end: Idx, | ||
152 | } | ||
153 | } | ||
154 | "#, | 128 | "#, |
155 | ); | 129 | ); |
156 | } | 130 | } |
@@ -164,7 +138,7 @@ enum Option<T> { Some(T), None } | |||
164 | fn test() { | 138 | fn test() { |
165 | let foo: Option<f32> = None; | 139 | let foo: Option<f32> = None; |
166 | while let Option::Some(x) = foo { | 140 | while let Option::Some(x) = foo { |
167 | x | 141 | x; |
168 | } //^ f32 | 142 | } //^ f32 |
169 | } | 143 | } |
170 | "#, | 144 | "#, |
@@ -175,16 +149,17 @@ fn test() { | |||
175 | fn infer_basics() { | 149 | fn infer_basics() { |
176 | check_infer( | 150 | check_infer( |
177 | r#" | 151 | r#" |
178 | fn test(a: u32, b: isize, c: !, d: &str) { | 152 | fn test(a: u32, b: isize, c: !, d: &str) { |
179 | a; | 153 | a; |
180 | b; | 154 | b; |
181 | c; | 155 | c; |
182 | d; | 156 | d; |
183 | 1usize; | 157 | 1usize; |
184 | 1isize; | 158 | 1isize; |
185 | "test"; | 159 | "test"; |
186 | 1.0f32; | 160 | 1.0f32; |
187 | }"#, | 161 | } |
162 | "#, | ||
188 | expect![[r#" | 163 | expect![[r#" |
189 | 8..9 'a': u32 | 164 | 8..9 'a': u32 |
190 | 16..17 'b': isize | 165 | 16..17 'b': isize |
@@ -207,15 +182,15 @@ fn infer_basics() { | |||
207 | fn infer_let() { | 182 | fn infer_let() { |
208 | check_infer( | 183 | check_infer( |
209 | r#" | 184 | r#" |
210 | fn test() { | 185 | fn test() { |
211 | let a = 1isize; | 186 | let a = 1isize; |
212 | let b: usize = 1; | 187 | let b: usize = 1; |
213 | let c = b; | 188 | let c = b; |
214 | let d: u32; | 189 | let d: u32; |
215 | let e; | 190 | let e; |
216 | let f: i32 = e; | 191 | let f: i32 = e; |
217 | } | 192 | } |
218 | "#, | 193 | "#, |
219 | expect![[r#" | 194 | expect![[r#" |
220 | 10..117 '{ ...= e; }': () | 195 | 10..117 '{ ...= e; }': () |
221 | 20..21 'a': isize | 196 | 20..21 'a': isize |
@@ -236,17 +211,17 @@ fn infer_let() { | |||
236 | fn infer_paths() { | 211 | fn infer_paths() { |
237 | check_infer( | 212 | check_infer( |
238 | r#" | 213 | r#" |
239 | fn a() -> u32 { 1 } | 214 | fn a() -> u32 { 1 } |
240 | 215 | ||
241 | mod b { | 216 | mod b { |
242 | fn c() -> u32 { 1 } | 217 | fn c() -> u32 { 1 } |
243 | } | 218 | } |
244 | 219 | ||
245 | fn test() { | 220 | fn test() { |
246 | a(); | 221 | a(); |
247 | b::c(); | 222 | b::c(); |
248 | } | 223 | } |
249 | "#, | 224 | "#, |
250 | expect![[r#" | 225 | expect![[r#" |
251 | 14..19 '{ 1 }': u32 | 226 | 14..19 '{ 1 }': u32 |
252 | 16..17 '1': u32 | 227 | 16..17 '1': u32 |
@@ -265,17 +240,17 @@ fn infer_paths() { | |||
265 | fn infer_path_type() { | 240 | fn infer_path_type() { |
266 | check_infer( | 241 | check_infer( |
267 | r#" | 242 | r#" |
268 | struct S; | 243 | struct S; |
269 | 244 | ||
270 | impl S { | 245 | impl S { |
271 | fn foo() -> i32 { 1 } | 246 | fn foo() -> i32 { 1 } |
272 | } | 247 | } |
273 | 248 | ||
274 | fn test() { | 249 | fn test() { |
275 | S::foo(); | 250 | S::foo(); |
276 | <S>::foo(); | 251 | <S>::foo(); |
277 | } | 252 | } |
278 | "#, | 253 | "#, |
279 | expect![[r#" | 254 | expect![[r#" |
280 | 40..45 '{ 1 }': i32 | 255 | 40..45 '{ 1 }': i32 |
281 | 42..43 '1': i32 | 256 | 42..43 '1': i32 |
@@ -292,21 +267,21 @@ fn infer_path_type() { | |||
292 | fn infer_struct() { | 267 | fn infer_struct() { |
293 | check_infer( | 268 | check_infer( |
294 | r#" | 269 | r#" |
295 | struct A { | 270 | struct A { |
296 | b: B, | 271 | b: B, |
297 | c: C, | 272 | c: C, |
298 | } | 273 | } |
299 | struct B; | 274 | struct B; |
300 | struct C(usize); | 275 | struct C(usize); |
301 | 276 | ||
302 | fn test() { | 277 | fn test() { |
303 | let c = C(1); | 278 | let c = C(1); |
304 | B; | 279 | B; |
305 | let a: A = A { b: B, c: C(1) }; | 280 | let a: A = A { b: B, c: C(1) }; |
306 | a.b; | 281 | a.b; |
307 | a.c; | 282 | a.c; |
308 | } | 283 | } |
309 | "#, | 284 | "#, |
310 | expect![[r#" | 285 | expect![[r#" |
311 | 71..153 '{ ...a.c; }': () | 286 | 71..153 '{ ...a.c; }': () |
312 | 81..82 'c': C | 287 | 81..82 'c': C |
@@ -332,14 +307,15 @@ fn infer_struct() { | |||
332 | fn infer_enum() { | 307 | fn infer_enum() { |
333 | check_infer( | 308 | check_infer( |
334 | r#" | 309 | r#" |
335 | enum E { | 310 | enum E { |
336 | V1 { field: u32 }, | 311 | V1 { field: u32 }, |
337 | V2 | 312 | V2 |
338 | } | 313 | } |
339 | fn test() { | 314 | fn test() { |
340 | E::V1 { field: 1 }; | 315 | E::V1 { field: 1 }; |
341 | E::V2; | 316 | E::V2; |
342 | }"#, | 317 | } |
318 | "#, | ||
343 | expect![[r#" | 319 | expect![[r#" |
344 | 51..89 '{ ...:V2; }': () | 320 | 51..89 '{ ...:V2; }': () |
345 | 57..75 'E::V1 ...d: 1 }': E | 321 | 57..75 'E::V1 ...d: 1 }': E |
@@ -353,23 +329,23 @@ fn infer_enum() { | |||
353 | fn infer_union() { | 329 | fn infer_union() { |
354 | check_infer( | 330 | check_infer( |
355 | r#" | 331 | r#" |
356 | union MyUnion { | 332 | union MyUnion { |
357 | foo: u32, | 333 | foo: u32, |
358 | bar: f32, | 334 | bar: f32, |
359 | } | 335 | } |
360 | 336 | ||
361 | fn test() { | 337 | fn test() { |
362 | let u = MyUnion { foo: 0 }; | 338 | let u = MyUnion { foo: 0 }; |
363 | unsafe { baz(u); } | 339 | unsafe { baz(u); } |
364 | let u = MyUnion { bar: 0.0 }; | 340 | let u = MyUnion { bar: 0.0 }; |
365 | unsafe { baz(u); } | 341 | unsafe { baz(u); } |
366 | } | 342 | } |
367 | 343 | ||
368 | unsafe fn baz(u: MyUnion) { | 344 | unsafe fn baz(u: MyUnion) { |
369 | let inner = u.foo; | 345 | let inner = u.foo; |
370 | let inner = u.bar; | 346 | let inner = u.bar; |
371 | } | 347 | } |
372 | "#, | 348 | "#, |
373 | expect![[r#" | 349 | expect![[r#" |
374 | 57..172 '{ ...); } }': () | 350 | 57..172 '{ ...); } }': () |
375 | 67..68 'u': MyUnion | 351 | 67..68 'u': MyUnion |
@@ -404,19 +380,19 @@ fn infer_union() { | |||
404 | fn infer_refs() { | 380 | fn infer_refs() { |
405 | check_infer( | 381 | check_infer( |
406 | r#" | 382 | r#" |
407 | fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { | 383 | fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { |
408 | a; | 384 | a; |
409 | *a; | 385 | *a; |
410 | &a; | 386 | &a; |
411 | &mut a; | 387 | &mut a; |
412 | b; | 388 | b; |
413 | *b; | 389 | *b; |
414 | &b; | 390 | &b; |
415 | c; | 391 | c; |
416 | *c; | 392 | *c; |
417 | d; | 393 | d; |
418 | *d; | 394 | *d; |
419 | } | 395 | } |
420 | "#, | 396 | "#, |
421 | expect![[r#" | 397 | expect![[r#" |
422 | 8..9 'a': &u32 | 398 | 8..9 'a': &u32 |
@@ -450,11 +426,11 @@ fn infer_refs() { | |||
450 | fn infer_raw_ref() { | 426 | fn infer_raw_ref() { |
451 | check_infer( | 427 | check_infer( |
452 | r#" | 428 | r#" |
453 | fn test(a: i32) { | 429 | fn test(a: i32) { |
454 | &raw mut a; | 430 | &raw mut a; |
455 | &raw const a; | 431 | &raw const a; |
456 | } | 432 | } |
457 | "#, | 433 | "#, |
458 | expect![[r#" | 434 | expect![[r#" |
459 | 8..9 'a': i32 | 435 | 8..9 'a': i32 |
460 | 16..53 '{ ...t a; }': () | 436 | 16..53 '{ ...t a; }': () |
@@ -524,26 +500,26 @@ h"; | |||
524 | fn infer_unary_op() { | 500 | fn infer_unary_op() { |
525 | check_infer( | 501 | check_infer( |
526 | r#" | 502 | r#" |
527 | enum SomeType {} | 503 | enum SomeType {} |
528 | 504 | ||
529 | fn test(x: SomeType) { | 505 | fn test(x: SomeType) { |
530 | let b = false; | 506 | let b = false; |
531 | let c = !b; | 507 | let c = !b; |
532 | let a = 100; | 508 | let a = 100; |
533 | let d: i128 = -a; | 509 | let d: i128 = -a; |
534 | let e = -100; | 510 | let e = -100; |
535 | let f = !!!true; | 511 | let f = !!!true; |
536 | let g = !42; | 512 | let g = !42; |
537 | let h = !10u32; | 513 | let h = !10u32; |
538 | let j = !a; | 514 | let j = !a; |
539 | -3.14; | 515 | -3.14; |
540 | !3; | 516 | !3; |
541 | -x; | 517 | -x; |
542 | !x; | 518 | !x; |
543 | -"hello"; | 519 | -"hello"; |
544 | !"hello"; | 520 | !"hello"; |
545 | } | 521 | } |
546 | "#, | 522 | "#, |
547 | expect![[r#" | 523 | expect![[r#" |
548 | 26..27 'x': SomeType | 524 | 26..27 'x': SomeType |
549 | 39..271 '{ ...lo"; }': () | 525 | 39..271 '{ ...lo"; }': () |
@@ -594,19 +570,19 @@ fn infer_unary_op() { | |||
594 | fn infer_backwards() { | 570 | fn infer_backwards() { |
595 | check_infer( | 571 | check_infer( |
596 | r#" | 572 | r#" |
597 | fn takes_u32(x: u32) {} | 573 | fn takes_u32(x: u32) {} |
598 | 574 | ||
599 | struct S { i32_field: i32 } | 575 | struct S { i32_field: i32 } |
600 | 576 | ||
601 | fn test() -> &mut &f64 { | 577 | fn test() -> &mut &f64 { |
602 | let a = unknown_function(); | 578 | let a = unknown_function(); |
603 | takes_u32(a); | 579 | takes_u32(a); |
604 | let b = unknown_function(); | 580 | let b = unknown_function(); |
605 | S { i32_field: b }; | 581 | S { i32_field: b }; |
606 | let c = unknown_function(); | 582 | let c = unknown_function(); |
607 | &mut &c | 583 | &mut &c |
608 | } | 584 | } |
609 | "#, | 585 | "#, |
610 | expect![[r#" | 586 | expect![[r#" |
611 | 13..14 'x': u32 | 587 | 13..14 'x': u32 |
612 | 21..23 '{}': () | 588 | 21..23 '{}': () |
@@ -636,23 +612,23 @@ fn infer_backwards() { | |||
636 | fn infer_self() { | 612 | fn infer_self() { |
637 | check_infer( | 613 | check_infer( |
638 | r#" | 614 | r#" |
639 | struct S; | 615 | struct S; |
640 | 616 | ||
641 | impl S { | 617 | impl S { |
642 | fn test(&self) { | 618 | fn test(&self) { |
643 | self; | 619 | self; |
644 | } | 620 | } |
645 | fn test2(self: &Self) { | 621 | fn test2(self: &Self) { |
646 | self; | 622 | self; |
647 | } | 623 | } |
648 | fn test3() -> Self { | 624 | fn test3() -> Self { |
649 | S {} | 625 | S {} |
650 | } | 626 | } |
651 | fn test4() -> Self { | 627 | fn test4() -> Self { |
652 | Self {} | 628 | Self {} |
653 | } | 629 | } |
654 | } | 630 | } |
655 | "#, | 631 | "#, |
656 | expect![[r#" | 632 | expect![[r#" |
657 | 33..37 'self': &S | 633 | 33..37 'self': &S |
658 | 39..60 '{ ... }': () | 634 | 39..60 '{ ... }': () |
@@ -672,30 +648,30 @@ fn infer_self() { | |||
672 | fn infer_self_as_path() { | 648 | fn infer_self_as_path() { |
673 | check_infer( | 649 | check_infer( |
674 | r#" | 650 | r#" |
675 | struct S1; | 651 | struct S1; |
676 | struct S2(isize); | 652 | struct S2(isize); |
677 | enum E { | 653 | enum E { |
678 | V1, | 654 | V1, |
679 | V2(u32), | 655 | V2(u32), |
680 | } | 656 | } |
681 | 657 | ||
682 | impl S1 { | 658 | impl S1 { |
683 | fn test() { | 659 | fn test() { |
684 | Self; | 660 | Self; |
685 | } | 661 | } |
686 | } | 662 | } |
687 | impl S2 { | 663 | impl S2 { |
688 | fn test() { | 664 | fn test() { |
689 | Self(1); | 665 | Self(1); |
690 | } | 666 | } |
691 | } | 667 | } |
692 | impl E { | 668 | impl E { |
693 | fn test() { | 669 | fn test() { |
694 | Self::V1; | 670 | Self::V1; |
695 | Self::V2(1); | 671 | Self::V2(1); |
696 | } | 672 | } |
697 | } | 673 | } |
698 | "#, | 674 | "#, |
699 | expect![[r#" | 675 | expect![[r#" |
700 | 86..107 '{ ... }': () | 676 | 86..107 '{ ... }': () |
701 | 96..100 'Self': S1 | 677 | 96..100 'Self': S1 |
@@ -716,26 +692,26 @@ fn infer_self_as_path() { | |||
716 | fn infer_binary_op() { | 692 | fn infer_binary_op() { |
717 | check_infer( | 693 | check_infer( |
718 | r#" | 694 | r#" |
719 | fn f(x: bool) -> i32 { | 695 | fn f(x: bool) -> i32 { |
720 | 0i32 | 696 | 0i32 |
721 | } | 697 | } |
722 | 698 | ||
723 | fn test() -> bool { | 699 | fn test() -> bool { |
724 | let x = a && b; | 700 | let x = a && b; |
725 | let y = true || false; | 701 | let y = true || false; |
726 | let z = x == y; | 702 | let z = x == y; |
727 | let t = x != y; | 703 | let t = x != y; |
728 | let minus_forty: isize = -40isize; | 704 | let minus_forty: isize = -40isize; |
729 | let h = minus_forty <= CONST_2; | 705 | let h = minus_forty <= CONST_2; |
730 | let c = f(z || y) + 5; | 706 | let c = f(z || y) + 5; |
731 | let d = b; | 707 | let d = b; |
732 | let g = minus_forty ^= i; | 708 | let g = minus_forty ^= i; |
733 | let ten: usize = 10; | 709 | let ten: usize = 10; |
734 | let ten_is_eleven = ten == some_num; | 710 | let ten_is_eleven = ten == some_num; |
735 | 711 | ||
736 | ten < 3 | 712 | ten < 3 |
737 | } | 713 | } |
738 | "#, | 714 | "#, |
739 | expect![[r#" | 715 | expect![[r#" |
740 | 5..6 'x': bool | 716 | 5..6 'x': bool |
741 | 21..33 '{ 0i32 }': i32 | 717 | 21..33 '{ 0i32 }': i32 |
@@ -795,11 +771,11 @@ fn infer_binary_op() { | |||
795 | fn infer_shift_op() { | 771 | fn infer_shift_op() { |
796 | check_infer( | 772 | check_infer( |
797 | r#" | 773 | r#" |
798 | fn test() { | 774 | fn test() { |
799 | 1u32 << 5u8; | 775 | 1u32 << 5u8; |
800 | 1u32 >> 5u8; | 776 | 1u32 >> 5u8; |
801 | } | 777 | } |
802 | "#, | 778 | "#, |
803 | expect![[r#" | 779 | expect![[r#" |
804 | 10..47 '{ ...5u8; }': () | 780 | 10..47 '{ ...5u8; }': () |
805 | 16..20 '1u32': u32 | 781 | 16..20 '1u32': u32 |
@@ -816,29 +792,29 @@ fn infer_shift_op() { | |||
816 | fn infer_field_autoderef() { | 792 | fn infer_field_autoderef() { |
817 | check_infer( | 793 | check_infer( |
818 | r#" | 794 | r#" |
819 | struct A { | 795 | struct A { |
820 | b: B, | 796 | b: B, |
821 | } | 797 | } |
822 | struct B; | 798 | struct B; |
823 | |||
824 | fn test1(a: A) { | ||
825 | let a1 = a; | ||
826 | a1.b; | ||
827 | let a2 = &a; | ||
828 | a2.b; | ||
829 | let a3 = &mut a; | ||
830 | a3.b; | ||
831 | let a4 = &&&&&&&a; | ||
832 | a4.b; | ||
833 | let a5 = &mut &&mut &&mut a; | ||
834 | a5.b; | ||
835 | } | ||
836 | 799 | ||
837 | fn test2(a1: *const A, a2: *mut A) { | 800 | fn test1(a: A) { |
838 | a1.b; | 801 | let a1 = a; |
839 | a2.b; | 802 | a1.b; |
840 | } | 803 | let a2 = &a; |
841 | "#, | 804 | a2.b; |
805 | let a3 = &mut a; | ||
806 | a3.b; | ||
807 | let a4 = &&&&&&&a; | ||
808 | a4.b; | ||
809 | let a5 = &mut &&mut &&mut a; | ||
810 | a5.b; | ||
811 | } | ||
812 | |||
813 | fn test2(a1: *const A, a2: *mut A) { | ||
814 | a1.b; | ||
815 | a2.b; | ||
816 | } | ||
817 | "#, | ||
842 | expect![[r#" | 818 | expect![[r#" |
843 | 43..44 'a': A | 819 | 43..44 'a': A |
844 | 49..212 '{ ...5.b; }': () | 820 | 49..212 '{ ...5.b; }': () |
@@ -891,58 +867,53 @@ fn infer_field_autoderef() { | |||
891 | fn infer_argument_autoderef() { | 867 | fn infer_argument_autoderef() { |
892 | check_infer( | 868 | check_infer( |
893 | r#" | 869 | r#" |
894 | #[lang = "deref"] | 870 | //- minicore: deref |
895 | pub trait Deref { | 871 | use core::ops::Deref; |
896 | type Target; | 872 | struct A<T>(T); |
897 | fn deref(&self) -> &Self::Target; | ||
898 | } | ||
899 | 873 | ||
900 | struct A<T>(T); | 874 | impl<T> A<T> { |
901 | 875 | fn foo(&self) -> &T { | |
902 | impl<T> A<T> { | 876 | &self.0 |
903 | fn foo(&self) -> &T { | 877 | } |
904 | &self.0 | 878 | } |
905 | } | ||
906 | } | ||
907 | 879 | ||
908 | struct B<T>(T); | 880 | struct B<T>(T); |
909 | 881 | ||
910 | impl<T> Deref for B<T> { | 882 | impl<T> Deref for B<T> { |
911 | type Target = T; | 883 | type Target = T; |
912 | fn deref(&self) -> &Self::Target { | 884 | fn deref(&self) -> &Self::Target { |
913 | &self.0 | 885 | &self.0 |
914 | } | 886 | } |
915 | } | 887 | } |
916 | 888 | ||
917 | fn test() { | 889 | fn test() { |
918 | let t = A::foo(&&B(B(A(42)))); | 890 | let t = A::foo(&&B(B(A(42)))); |
919 | } | 891 | } |
920 | "#, | 892 | "#, |
921 | expect![[r#" | 893 | expect![[r#" |
922 | 67..71 'self': &Self | 894 | 66..70 'self': &A<T> |
923 | 138..142 'self': &A<T> | 895 | 78..101 '{ ... }': &T |
924 | 150..173 '{ ... }': &T | 896 | 88..95 '&self.0': &T |
925 | 160..167 '&self.0': &T | 897 | 89..93 'self': &A<T> |
926 | 161..165 'self': &A<T> | 898 | 89..95 'self.0': T |
927 | 161..167 'self.0': T | 899 | 182..186 'self': &B<T> |
928 | 254..258 'self': &B<T> | 900 | 205..228 '{ ... }': &T |
929 | 277..300 '{ ... }': &T | 901 | 215..222 '&self.0': &T |
930 | 287..294 '&self.0': &T | 902 | 216..220 'self': &B<T> |
931 | 288..292 'self': &B<T> | 903 | 216..222 'self.0': T |
932 | 288..294 'self.0': T | 904 | 242..280 '{ ...))); }': () |
933 | 314..352 '{ ...))); }': () | 905 | 252..253 't': &i32 |
934 | 324..325 't': &i32 | 906 | 256..262 'A::foo': fn foo<i32>(&A<i32>) -> &i32 |
935 | 328..334 'A::foo': fn foo<i32>(&A<i32>) -> &i32 | 907 | 256..277 'A::foo...42))))': &i32 |
936 | 328..349 'A::foo...42))))': &i32 | 908 | 263..276 '&&B(B(A(42)))': &&B<B<A<i32>>> |
937 | 335..348 '&&B(B(A(42)))': &&B<B<A<i32>>> | 909 | 264..276 '&B(B(A(42)))': &B<B<A<i32>>> |
938 | 336..348 '&B(B(A(42)))': &B<B<A<i32>>> | 910 | 265..266 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> |
939 | 337..338 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> | 911 | 265..276 'B(B(A(42)))': B<B<A<i32>>> |
940 | 337..348 'B(B(A(42)))': B<B<A<i32>>> | 912 | 267..268 'B': B<A<i32>>(A<i32>) -> B<A<i32>> |
941 | 339..340 'B': B<A<i32>>(A<i32>) -> B<A<i32>> | 913 | 267..275 'B(A(42))': B<A<i32>> |
942 | 339..347 'B(A(42))': B<A<i32>> | 914 | 269..270 'A': A<i32>(i32) -> A<i32> |
943 | 341..342 'A': A<i32>(i32) -> A<i32> | 915 | 269..274 'A(42)': A<i32> |
944 | 341..346 'A(42)': A<i32> | 916 | 271..273 '42': i32 |
945 | 343..345 '42': i32 | ||
946 | "#]], | 917 | "#]], |
947 | ); | 918 | ); |
948 | } | 919 | } |
@@ -951,62 +922,57 @@ fn infer_argument_autoderef() { | |||
951 | fn infer_method_argument_autoderef() { | 922 | fn infer_method_argument_autoderef() { |
952 | check_infer( | 923 | check_infer( |
953 | r#" | 924 | r#" |
954 | #[lang = "deref"] | 925 | //- minicore: deref |
955 | pub trait Deref { | 926 | use core::ops::Deref; |
956 | type Target; | 927 | struct A<T>(*mut T); |
957 | fn deref(&self) -> &Self::Target; | ||
958 | } | ||
959 | 928 | ||
960 | struct A<T>(*mut T); | 929 | impl<T> A<T> { |
961 | 930 | fn foo(&self, x: &A<T>) -> &T { | |
962 | impl<T> A<T> { | 931 | &*x.0 |
963 | fn foo(&self, x: &A<T>) -> &T { | 932 | } |
964 | &*x.0 | 933 | } |
965 | } | ||
966 | } | ||
967 | 934 | ||
968 | struct B<T>(T); | 935 | struct B<T>(T); |
969 | 936 | ||
970 | impl<T> Deref for B<T> { | 937 | impl<T> Deref for B<T> { |
971 | type Target = T; | 938 | type Target = T; |
972 | fn deref(&self) -> &Self::Target { | 939 | fn deref(&self) -> &Self::Target { |
973 | &self.0 | 940 | &self.0 |
974 | } | 941 | } |
975 | } | 942 | } |
976 | 943 | ||
977 | fn test(a: A<i32>) { | 944 | fn test(a: A<i32>) { |
978 | let t = A(0 as *mut _).foo(&&B(B(a))); | 945 | let t = A(0 as *mut _).foo(&&B(B(a))); |
979 | } | 946 | } |
980 | "#, | 947 | "#, |
981 | expect![[r#" | 948 | expect![[r#" |
982 | 67..71 'self': &Self | 949 | 71..75 'self': &A<T> |
983 | 143..147 'self': &A<T> | 950 | 77..78 'x': &A<T> |
984 | 149..150 'x': &A<T> | 951 | 93..114 '{ ... }': &T |
985 | 165..186 '{ ... }': &T | 952 | 103..108 '&*x.0': &T |
986 | 175..180 '&*x.0': &T | 953 | 104..108 '*x.0': T |
987 | 176..180 '*x.0': T | 954 | 105..106 'x': &A<T> |
988 | 177..178 'x': &A<T> | 955 | 105..108 'x.0': *mut T |
989 | 177..180 'x.0': *mut T | 956 | 195..199 'self': &B<T> |
990 | 267..271 'self': &B<T> | 957 | 218..241 '{ ... }': &T |
991 | 290..313 '{ ... }': &T | 958 | 228..235 '&self.0': &T |
992 | 300..307 '&self.0': &T | 959 | 229..233 'self': &B<T> |
993 | 301..305 'self': &B<T> | 960 | 229..235 'self.0': T |
994 | 301..307 'self.0': T | 961 | 253..254 'a': A<i32> |
995 | 325..326 'a': A<i32> | 962 | 264..310 '{ ...))); }': () |
996 | 336..382 '{ ...))); }': () | 963 | 274..275 't': &i32 |
997 | 346..347 't': &i32 | 964 | 278..279 'A': A<i32>(*mut i32) -> A<i32> |
998 | 350..351 'A': A<i32>(*mut i32) -> A<i32> | 965 | 278..292 'A(0 as *mut _)': A<i32> |
999 | 350..364 'A(0 as *mut _)': A<i32> | 966 | 278..307 'A(0 as...B(a)))': &i32 |
1000 | 350..379 'A(0 as...B(a)))': &i32 | 967 | 280..281 '0': i32 |
1001 | 352..353 '0': i32 | 968 | 280..291 '0 as *mut _': *mut i32 |
1002 | 352..363 '0 as *mut _': *mut i32 | 969 | 297..306 '&&B(B(a))': &&B<B<A<i32>>> |
1003 | 369..378 '&&B(B(a))': &&B<B<A<i32>>> | 970 | 298..306 '&B(B(a))': &B<B<A<i32>>> |
1004 | 370..378 '&B(B(a))': &B<B<A<i32>>> | 971 | 299..300 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> |
1005 | 371..372 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> | 972 | 299..306 'B(B(a))': B<B<A<i32>>> |
1006 | 371..378 'B(B(a))': B<B<A<i32>>> | 973 | 301..302 'B': B<A<i32>>(A<i32>) -> B<A<i32>> |
1007 | 373..374 'B': B<A<i32>>(A<i32>) -> B<A<i32>> | 974 | 301..305 'B(a)': B<A<i32>> |
1008 | 373..377 'B(a)': B<A<i32>> | 975 | 303..304 'a': A<i32> |
1009 | 375..376 'a': A<i32> | ||
1010 | "#]], | 976 | "#]], |
1011 | ); | 977 | ); |
1012 | } | 978 | } |
@@ -1015,15 +981,15 @@ fn infer_method_argument_autoderef() { | |||
1015 | fn infer_in_elseif() { | 981 | fn infer_in_elseif() { |
1016 | check_infer( | 982 | check_infer( |
1017 | r#" | 983 | r#" |
1018 | struct Foo { field: i32 } | 984 | struct Foo { field: i32 } |
1019 | fn main(foo: Foo) { | 985 | fn main(foo: Foo) { |
1020 | if true { | 986 | if true { |
1021 | 987 | ||
1022 | } else if false { | 988 | } else if false { |
1023 | foo.field | 989 | foo.field |
1024 | } | 990 | } |
1025 | } | 991 | } |
1026 | "#, | 992 | "#, |
1027 | expect![[r#" | 993 | expect![[r#" |
1028 | 34..37 'foo': Foo | 994 | 34..37 'foo': Foo |
1029 | 44..108 '{ ... } }': () | 995 | 44..108 '{ ... } }': () |
@@ -1043,28 +1009,29 @@ fn infer_in_elseif() { | |||
1043 | fn infer_if_match_with_return() { | 1009 | fn infer_if_match_with_return() { |
1044 | check_infer( | 1010 | check_infer( |
1045 | r#" | 1011 | r#" |
1046 | fn foo() { | 1012 | fn foo() { |
1047 | let _x1 = if true { | 1013 | let _x1 = if true { |
1048 | 1 | 1014 | 1 |
1049 | } else { | 1015 | } else { |
1050 | return; | 1016 | return; |
1051 | }; | 1017 | }; |
1052 | let _x2 = if true { | 1018 | let _x2 = if true { |
1053 | 2 | 1019 | 2 |
1054 | } else { | 1020 | } else { |
1055 | return | 1021 | return |
1056 | }; | 1022 | }; |
1057 | let _x3 = match true { | 1023 | let _x3 = match true { |
1058 | true => 3, | 1024 | true => 3, |
1059 | _ => { | 1025 | _ => { |
1060 | return; | 1026 | return; |
1061 | } | 1027 | } |
1062 | }; | 1028 | }; |
1063 | let _x4 = match true { | 1029 | let _x4 = match true { |
1064 | true => 4, | 1030 | true => 4, |
1065 | _ => return | 1031 | _ => return |
1066 | }; | 1032 | }; |
1067 | }"#, | 1033 | } |
1034 | "#, | ||
1068 | expect![[r#" | 1035 | expect![[r#" |
1069 | 9..322 '{ ... }; }': () | 1036 | 9..322 '{ ... }; }': () |
1070 | 19..22 '_x1': i32 | 1037 | 19..22 '_x1': i32 |
@@ -1778,7 +1745,7 @@ impl i32 { fn foo(&self) -> Foo { Foo } } | |||
1778 | fn main() { | 1745 | fn main() { |
1779 | let x: i32 = i32; | 1746 | let x: i32 = i32; |
1780 | x.foo(); | 1747 | x.foo(); |
1781 | //^ Foo | 1748 | //^^^^^^^ Foo |
1782 | }"#, | 1749 | }"#, |
1783 | ); | 1750 | ); |
1784 | } | 1751 | } |
@@ -1796,7 +1763,7 @@ fn main() { | |||
1796 | fn inner() {} | 1763 | fn inner() {} |
1797 | let x: i32 = i32; | 1764 | let x: i32 = i32; |
1798 | x.foo(); | 1765 | x.foo(); |
1799 | //^ Foo | 1766 | //^^^^^^^ Foo |
1800 | }"#, | 1767 | }"#, |
1801 | ); | 1768 | ); |
1802 | } | 1769 | } |
@@ -1814,7 +1781,7 @@ fn foo() -> &'static str { "" } | |||
1814 | 1781 | ||
1815 | fn main() { | 1782 | fn main() { |
1816 | foo(); | 1783 | foo(); |
1817 | //^ &str | 1784 | //^^^^^ &str |
1818 | }"#, | 1785 | }"#, |
1819 | ); | 1786 | ); |
1820 | } | 1787 | } |
@@ -1832,7 +1799,7 @@ fn foo() -> &'static str { "" } | |||
1832 | 1799 | ||
1833 | fn main() { | 1800 | fn main() { |
1834 | str::foo(); | 1801 | str::foo(); |
1835 | //^ u32 | 1802 | //^^^^^^^^^^ u32 |
1836 | }"#, | 1803 | }"#, |
1837 | ); | 1804 | ); |
1838 | } | 1805 | } |
@@ -1858,9 +1825,9 @@ mod d { | |||
1858 | 1825 | ||
1859 | fn main() { | 1826 | fn main() { |
1860 | d::foo(); | 1827 | d::foo(); |
1861 | //^ u8 | 1828 | //^^^^^^^^ u8 |
1862 | d::foo{a:0}; | 1829 | d::foo{a:0}; |
1863 | //^ u8 | 1830 | //^^^^^^^^^^^ foo |
1864 | }"#, | 1831 | }"#, |
1865 | ); | 1832 | ); |
1866 | } | 1833 | } |
@@ -1950,6 +1917,7 @@ fn fn_pointer_return() { | |||
1950 | fn effects_smoke_test() { | 1917 | fn effects_smoke_test() { |
1951 | check_infer( | 1918 | check_infer( |
1952 | r#" | 1919 | r#" |
1920 | //- minicore: future | ||
1953 | async fn main() { | 1921 | async fn main() { |
1954 | let x = unsafe { 92 }; | 1922 | let x = unsafe { 92 }; |
1955 | let y = async { async { () }.await }; | 1923 | let y = async { async { () }.await }; |
@@ -1957,13 +1925,6 @@ fn effects_smoke_test() { | |||
1957 | let w = const { 92 }; | 1925 | let w = const { 92 }; |
1958 | let t = 'a: { 92 }; | 1926 | let t = 'a: { 92 }; |
1959 | } | 1927 | } |
1960 | |||
1961 | #[prelude_import] use future::*; | ||
1962 | |||
1963 | mod future { | ||
1964 | #[lang = "future_trait"] | ||
1965 | pub trait Future { type Output; } | ||
1966 | } | ||
1967 | "#, | 1928 | "#, |
1968 | expect![[r#" | 1929 | expect![[r#" |
1969 | 16..162 '{ ...2 }; }': () | 1930 | 16..162 '{ ...2 }; }': () |
@@ -2639,11 +2600,8 @@ fn f() { | |||
2639 | fn infer_boxed_self_receiver() { | 2600 | fn infer_boxed_self_receiver() { |
2640 | check_infer( | 2601 | check_infer( |
2641 | r#" | 2602 | r#" |
2642 | #[lang = "deref"] | 2603 | //- minicore: deref |
2643 | pub trait Deref { | 2604 | use core::ops::Deref; |
2644 | type Target; | ||
2645 | fn deref(&self) -> &Self::Target; | ||
2646 | } | ||
2647 | 2605 | ||
2648 | struct Box<T>(T); | 2606 | struct Box<T>(T); |
2649 | 2607 | ||
@@ -2675,40 +2633,39 @@ fn main() { | |||
2675 | } | 2633 | } |
2676 | "#, | 2634 | "#, |
2677 | expect![[r#" | 2635 | expect![[r#" |
2678 | 67..71 'self': &Self | 2636 | 104..108 'self': &Box<T> |
2679 | 175..179 'self': &Box<T> | 2637 | 188..192 'self': &Box<Foo<T>> |
2680 | 259..263 'self': &Box<Foo<T>> | 2638 | 218..220 '{}': () |
2681 | 289..291 '{}': () | 2639 | 242..246 'self': &Box<Foo<T>> |
2682 | 313..317 'self': &Box<Foo<T>> | 2640 | 275..277 '{}': () |
2683 | 346..348 '{}': () | 2641 | 297..301 'self': Box<Foo<T>> |
2684 | 368..372 'self': Box<Foo<T>> | 2642 | 322..324 '{}': () |
2685 | 393..395 '{}': () | 2643 | 338..559 '{ ...r(); }': () |
2686 | 409..630 '{ ...r(); }': () | 2644 | 348..353 'boxed': Box<Foo<i32>> |
2687 | 419..424 'boxed': Box<Foo<i32>> | 2645 | 356..359 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>> |
2688 | 427..430 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>> | 2646 | 356..371 'Box(Foo(0_i32))': Box<Foo<i32>> |
2689 | 427..442 'Box(Foo(0_i32))': Box<Foo<i32>> | 2647 | 360..363 'Foo': Foo<i32>(i32) -> Foo<i32> |
2690 | 431..434 'Foo': Foo<i32>(i32) -> Foo<i32> | 2648 | 360..370 'Foo(0_i32)': Foo<i32> |
2691 | 431..441 'Foo(0_i32)': Foo<i32> | 2649 | 364..369 '0_i32': i32 |
2692 | 435..440 '0_i32': i32 | 2650 | 382..386 'bad1': &i32 |
2693 | 453..457 'bad1': &i32 | 2651 | 389..394 'boxed': Box<Foo<i32>> |
2694 | 460..465 'boxed': Box<Foo<i32>> | 2652 | 389..406 'boxed....nner()': &i32 |
2695 | 460..477 'boxed....nner()': &i32 | 2653 | 416..421 'good1': &i32 |
2696 | 487..492 'good1': &i32 | 2654 | 424..438 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32 |
2697 | 495..509 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32 | 2655 | 424..446 'Foo::g...boxed)': &i32 |
2698 | 495..517 'Foo::g...boxed)': &i32 | 2656 | 439..445 '&boxed': &Box<Foo<i32>> |
2699 | 510..516 '&boxed': &Box<Foo<i32>> | 2657 | 440..445 'boxed': Box<Foo<i32>> |
2700 | 511..516 'boxed': Box<Foo<i32>> | 2658 | 457..461 'bad2': &Foo<i32> |
2701 | 528..532 'bad2': &Foo<i32> | 2659 | 464..469 'boxed': Box<Foo<i32>> |
2702 | 535..540 'boxed': Box<Foo<i32>> | 2660 | 464..480 'boxed....self()': &Foo<i32> |
2703 | 535..551 'boxed....self()': &Foo<i32> | 2661 | 490..495 'good2': &Foo<i32> |
2704 | 561..566 'good2': &Foo<i32> | 2662 | 498..511 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32> |
2705 | 569..582 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32> | 2663 | 498..519 'Foo::g...boxed)': &Foo<i32> |
2706 | 569..590 'Foo::g...boxed)': &Foo<i32> | 2664 | 512..518 '&boxed': &Box<Foo<i32>> |
2707 | 583..589 '&boxed': &Box<Foo<i32>> | 2665 | 513..518 'boxed': Box<Foo<i32>> |
2708 | 584..589 'boxed': Box<Foo<i32>> | 2666 | 530..535 'inner': Foo<i32> |
2709 | 601..606 'inner': Foo<i32> | 2667 | 538..543 'boxed': Box<Foo<i32>> |
2710 | 609..614 'boxed': Box<Foo<i32>> | 2668 | 538..556 'boxed....nner()': Foo<i32> |
2711 | 609..627 'boxed....nner()': Foo<i32> | ||
2712 | "#]], | 2669 | "#]], |
2713 | ); | 2670 | ); |
2714 | } | 2671 | } |
@@ -2720,7 +2677,7 @@ fn prelude_2015() { | |||
2720 | //- /main.rs edition:2015 crate:main deps:core | 2677 | //- /main.rs edition:2015 crate:main deps:core |
2721 | fn f() { | 2678 | fn f() { |
2722 | Rust; | 2679 | Rust; |
2723 | //^ Rust | 2680 | //^^^^ Rust |
2724 | } | 2681 | } |
2725 | 2682 | ||
2726 | //- /core.rs crate:core | 2683 | //- /core.rs crate:core |
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 6bcede4c4..a0ddad570 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -1,15 +1,16 @@ | |||
1 | use cov_mark::check; | ||
1 | use expect_test::expect; | 2 | use expect_test::expect; |
2 | 3 | ||
3 | use super::{check_infer, check_infer_with_mismatches, check_types}; | 4 | use super::{check, check_infer, check_infer_with_mismatches, check_types}; |
4 | 5 | ||
5 | #[test] | 6 | #[test] |
6 | fn infer_await() { | 7 | fn infer_await() { |
7 | check_types( | 8 | check_types( |
8 | r#" | 9 | r#" |
9 | //- /main.rs crate:main deps:core | 10 | //- minicore: future |
10 | struct IntFuture; | 11 | struct IntFuture; |
11 | 12 | ||
12 | impl Future for IntFuture { | 13 | impl core::future::Future for IntFuture { |
13 | type Output = u64; | 14 | type Output = u64; |
14 | } | 15 | } |
15 | 16 | ||
@@ -18,16 +19,6 @@ fn test() { | |||
18 | let v = r.await; | 19 | let v = r.await; |
19 | v; | 20 | v; |
20 | } //^ u64 | 21 | } //^ u64 |
21 | |||
22 | //- /core.rs crate:core | ||
23 | pub mod prelude { | ||
24 | pub mod rust_2018 { | ||
25 | #[lang = "future_trait"] | ||
26 | pub trait Future { | ||
27 | type Output; | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | "#, | 22 | "#, |
32 | ); | 23 | ); |
33 | } | 24 | } |
@@ -36,25 +27,14 @@ pub mod prelude { | |||
36 | fn infer_async() { | 27 | fn infer_async() { |
37 | check_types( | 28 | check_types( |
38 | r#" | 29 | r#" |
39 | //- /main.rs crate:main deps:core | 30 | //- minicore: future |
40 | async fn foo() -> u64 { | 31 | async fn foo() -> u64 { 128 } |
41 | 128 | ||
42 | } | ||
43 | 32 | ||
44 | fn test() { | 33 | fn test() { |
45 | let r = foo(); | 34 | let r = foo(); |
46 | let v = r.await; | 35 | let v = r.await; |
47 | v; | 36 | v; |
48 | } //^ u64 | 37 | } //^ u64 |
49 | |||
50 | //- /core.rs crate:core | ||
51 | #[prelude_import] use future::*; | ||
52 | mod future { | ||
53 | #[lang = "future_trait"] | ||
54 | trait Future { | ||
55 | type Output; | ||
56 | } | ||
57 | } | ||
58 | "#, | 38 | "#, |
59 | ); | 39 | ); |
60 | } | 40 | } |
@@ -63,24 +43,13 @@ mod future { | |||
63 | fn infer_desugar_async() { | 43 | fn infer_desugar_async() { |
64 | check_types( | 44 | check_types( |
65 | r#" | 45 | r#" |
66 | //- /main.rs crate:main deps:core | 46 | //- minicore: future |
67 | async fn foo() -> u64 { | 47 | async fn foo() -> u64 { 128 } |
68 | 128 | ||
69 | } | ||
70 | 48 | ||
71 | fn test() { | 49 | fn test() { |
72 | let r = foo(); | 50 | let r = foo(); |
73 | r; | 51 | r; |
74 | } //^ impl Future<Output = u64> | 52 | } //^ impl Future<Output = u64> |
75 | |||
76 | //- /core.rs crate:core | ||
77 | #[prelude_import] use future::*; | ||
78 | mod future { | ||
79 | trait Future { | ||
80 | type Output; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | "#, | 53 | "#, |
85 | ); | 54 | ); |
86 | } | 55 | } |
@@ -89,7 +58,7 @@ mod future { | |||
89 | fn infer_async_block() { | 58 | fn infer_async_block() { |
90 | check_types( | 59 | check_types( |
91 | r#" | 60 | r#" |
92 | //- /main.rs crate:main deps:core | 61 | //- minicore: future, option |
93 | async fn test() { | 62 | async fn test() { |
94 | let a = async { 42 }; | 63 | let a = async { 42 }; |
95 | a; | 64 | a; |
@@ -101,7 +70,7 @@ async fn test() { | |||
101 | b; | 70 | b; |
102 | // ^ () | 71 | // ^ () |
103 | let c = async { | 72 | let c = async { |
104 | let y = Option::None; | 73 | let y = None; |
105 | y | 74 | y |
106 | // ^ Option<u64> | 75 | // ^ Option<u64> |
107 | }; | 76 | }; |
@@ -109,18 +78,6 @@ async fn test() { | |||
109 | c; | 78 | c; |
110 | // ^ impl Future<Output = Option<u64>> | 79 | // ^ impl Future<Output = Option<u64>> |
111 | } | 80 | } |
112 | |||
113 | enum Option<T> { None, Some(T) } | ||
114 | |||
115 | //- /core.rs crate:core | ||
116 | #[prelude_import] use future::*; | ||
117 | mod future { | ||
118 | #[lang = "future_trait"] | ||
119 | trait Future { | ||
120 | type Output; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | "#, | 81 | "#, |
125 | ); | 82 | ); |
126 | } | 83 | } |
@@ -329,7 +286,7 @@ mod ops { | |||
329 | 286 | ||
330 | #[test] | 287 | #[test] |
331 | fn infer_from_bound_1() { | 288 | fn infer_from_bound_1() { |
332 | check_infer( | 289 | check_types( |
333 | r#" | 290 | r#" |
334 | trait Trait<T> {} | 291 | trait Trait<T> {} |
335 | struct S<T>(T); | 292 | struct S<T>(T); |
@@ -337,99 +294,62 @@ impl<U> Trait<U> for S<U> {} | |||
337 | fn foo<T: Trait<u32>>(t: T) {} | 294 | fn foo<T: Trait<u32>>(t: T) {} |
338 | fn test() { | 295 | fn test() { |
339 | let s = S(unknown); | 296 | let s = S(unknown); |
297 | // ^^^^^^^ u32 | ||
340 | foo(s); | 298 | foo(s); |
341 | }"#, | 299 | }"#, |
342 | expect![[r#" | ||
343 | 85..86 't': T | ||
344 | 91..93 '{}': () | ||
345 | 104..143 '{ ...(s); }': () | ||
346 | 114..115 's': S<u32> | ||
347 | 118..119 'S': S<u32>(u32) -> S<u32> | ||
348 | 118..128 'S(unknown)': S<u32> | ||
349 | 120..127 'unknown': u32 | ||
350 | 134..137 'foo': fn foo<S<u32>>(S<u32>) | ||
351 | 134..140 'foo(s)': () | ||
352 | 138..139 's': S<u32> | ||
353 | "#]], | ||
354 | ); | 300 | ); |
355 | } | 301 | } |
356 | 302 | ||
357 | #[test] | 303 | #[test] |
358 | fn infer_from_bound_2() { | 304 | fn infer_from_bound_2() { |
359 | check_infer( | 305 | check_types( |
360 | r#" | 306 | r#" |
361 | trait Trait<T> {} | 307 | trait Trait<T> {} |
362 | struct S<T>(T); | 308 | struct S<T>(T); |
363 | impl<U> Trait<U> for S<U> {} | 309 | impl<U> Trait<U> for S<U> {} |
364 | fn foo<U, T: Trait<U>>(t: T) -> U {} | 310 | fn foo<U, T: Trait<U>>(t: T) -> U { loop {} } |
365 | fn test() { | 311 | fn test() { |
366 | let s = S(unknown); | 312 | let s = S(unknown); |
313 | // ^^^^^^^ u32 | ||
367 | let x: u32 = foo(s); | 314 | let x: u32 = foo(s); |
368 | }"#, | 315 | }"#, |
369 | expect![[r#" | ||
370 | 86..87 't': T | ||
371 | 97..99 '{}': () | ||
372 | 110..162 '{ ...(s); }': () | ||
373 | 120..121 's': S<u32> | ||
374 | 124..125 'S': S<u32>(u32) -> S<u32> | ||
375 | 124..134 'S(unknown)': S<u32> | ||
376 | 126..133 'unknown': u32 | ||
377 | 144..145 'x': u32 | ||
378 | 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32 | ||
379 | 153..159 'foo(s)': u32 | ||
380 | 157..158 's': S<u32> | ||
381 | "#]], | ||
382 | ); | 316 | ); |
383 | } | 317 | } |
384 | 318 | ||
385 | #[test] | 319 | #[test] |
386 | fn trait_default_method_self_bound_implements_trait() { | 320 | fn trait_default_method_self_bound_implements_trait() { |
387 | cov_mark::check!(trait_self_implements_self); | 321 | cov_mark::check!(trait_self_implements_self); |
388 | check_infer( | 322 | check( |
389 | r#" | 323 | r#" |
390 | trait Trait { | 324 | trait Trait { |
391 | fn foo(&self) -> i64; | 325 | fn foo(&self) -> i64; |
392 | fn bar(&self) -> { | 326 | fn bar(&self) -> () { |
393 | let x = self.foo(); | 327 | self.foo(); |
328 | // ^^^^^^^^^^ type: i64 | ||
394 | } | 329 | } |
395 | }"#, | 330 | }"#, |
396 | expect![[r#" | ||
397 | 26..30 'self': &Self | ||
398 | 52..56 'self': &Self | ||
399 | 61..96 '{ ... }': () | ||
400 | 75..76 'x': i64 | ||
401 | 79..83 'self': &Self | ||
402 | 79..89 'self.foo()': i64 | ||
403 | "#]], | ||
404 | ); | 331 | ); |
405 | } | 332 | } |
406 | 333 | ||
407 | #[test] | 334 | #[test] |
408 | fn trait_default_method_self_bound_implements_super_trait() { | 335 | fn trait_default_method_self_bound_implements_super_trait() { |
409 | check_infer( | 336 | check( |
410 | r#" | 337 | r#" |
411 | trait SuperTrait { | 338 | trait SuperTrait { |
412 | fn foo(&self) -> i64; | 339 | fn foo(&self) -> i64; |
413 | } | 340 | } |
414 | trait Trait: SuperTrait { | 341 | trait Trait: SuperTrait { |
415 | fn bar(&self) -> { | 342 | fn bar(&self) -> () { |
416 | let x = self.foo(); | 343 | self.foo(); |
344 | // ^^^^^^^^^^ type: i64 | ||
417 | } | 345 | } |
418 | }"#, | 346 | }"#, |
419 | expect![[r#" | ||
420 | 31..35 'self': &Self | ||
421 | 85..89 'self': &Self | ||
422 | 94..129 '{ ... }': () | ||
423 | 108..109 'x': i64 | ||
424 | 112..116 'self': &Self | ||
425 | 112..122 'self.foo()': i64 | ||
426 | "#]], | ||
427 | ); | 347 | ); |
428 | } | 348 | } |
429 | 349 | ||
430 | #[test] | 350 | #[test] |
431 | fn infer_project_associated_type() { | 351 | fn infer_project_associated_type() { |
432 | check_infer( | 352 | check_types( |
433 | r#" | 353 | r#" |
434 | trait Iterable { | 354 | trait Iterable { |
435 | type Item; | 355 | type Item; |
@@ -438,89 +358,62 @@ struct S; | |||
438 | impl Iterable for S { type Item = u32; } | 358 | impl Iterable for S { type Item = u32; } |
439 | fn test<T: Iterable>() { | 359 | fn test<T: Iterable>() { |
440 | let x: <S as Iterable>::Item = 1; | 360 | let x: <S as Iterable>::Item = 1; |
441 | let y: <T as Iterable>::Item = no_matter; | 361 | // ^ u32 |
442 | let z: T::Item = no_matter; | 362 | let y: <T as Iterable>::Item = u; |
443 | let a: <T>::Item = no_matter; | 363 | // ^ Iterable::Item<T> |
364 | let z: T::Item = u; | ||
365 | // ^ Iterable::Item<T> | ||
366 | let a: <T>::Item = u; | ||
367 | // ^ Iterable::Item<T> | ||
444 | }"#, | 368 | }"#, |
445 | expect![[r#" | ||
446 | 108..261 '{ ...ter; }': () | ||
447 | 118..119 'x': u32 | ||
448 | 145..146 '1': u32 | ||
449 | 156..157 'y': Iterable::Item<T> | ||
450 | 183..192 'no_matter': Iterable::Item<T> | ||
451 | 202..203 'z': Iterable::Item<T> | ||
452 | 215..224 'no_matter': Iterable::Item<T> | ||
453 | 234..235 'a': Iterable::Item<T> | ||
454 | 249..258 'no_matter': Iterable::Item<T> | ||
455 | "#]], | ||
456 | ); | 369 | ); |
457 | } | 370 | } |
458 | 371 | ||
459 | #[test] | 372 | #[test] |
460 | fn infer_return_associated_type() { | 373 | fn infer_return_associated_type() { |
461 | check_infer( | 374 | check_types( |
462 | r#" | 375 | r#" |
463 | trait Iterable { | 376 | trait Iterable { |
464 | type Item; | 377 | type Item; |
465 | } | 378 | } |
466 | struct S; | 379 | struct S; |
467 | impl Iterable for S { type Item = u32; } | 380 | impl Iterable for S { type Item = u32; } |
468 | fn foo1<T: Iterable>(t: T) -> T::Item {} | 381 | fn foo1<T: Iterable>(t: T) -> T::Item { loop {} } |
469 | fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item {} | 382 | fn foo2<T: Iterable>(t: T) -> <T as Iterable>::Item { loop {} } |
470 | fn foo3<T: Iterable>(t: T) -> <T>::Item {} | 383 | fn foo3<T: Iterable>(t: T) -> <T>::Item { loop {} } |
471 | fn test() { | 384 | fn test() { |
472 | let x = foo1(S); | 385 | foo1(S); |
473 | let y = foo2(S); | 386 | // ^^^^^^^ u32 |
474 | let z = foo3(S); | 387 | foo2(S); |
388 | // ^^^^^^^ u32 | ||
389 | foo3(S); | ||
390 | // ^^^^^^^ u32 | ||
475 | }"#, | 391 | }"#, |
476 | expect![[r#" | ||
477 | 106..107 't': T | ||
478 | 123..125 '{}': () | ||
479 | 147..148 't': T | ||
480 | 178..180 '{}': () | ||
481 | 202..203 't': T | ||
482 | 221..223 '{}': () | ||
483 | 234..300 '{ ...(S); }': () | ||
484 | 244..245 'x': u32 | ||
485 | 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item | ||
486 | 248..255 'foo1(S)': u32 | ||
487 | 253..254 'S': S | ||
488 | 265..266 'y': u32 | ||
489 | 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item | ||
490 | 269..276 'foo2(S)': u32 | ||
491 | 274..275 'S': S | ||
492 | 286..287 'z': u32 | ||
493 | 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item | ||
494 | 290..297 'foo3(S)': u32 | ||
495 | 295..296 'S': S | ||
496 | "#]], | ||
497 | ); | 392 | ); |
498 | } | 393 | } |
499 | 394 | ||
500 | #[test] | 395 | #[test] |
501 | fn infer_associated_type_bound() { | 396 | fn infer_associated_type_bound() { |
502 | check_infer( | 397 | check_types( |
503 | r#" | 398 | r#" |
504 | trait Iterable { | 399 | trait Iterable { |
505 | type Item; | 400 | type Item; |
506 | } | 401 | } |
507 | fn test<T: Iterable<Item=u32>>() { | 402 | fn test<T: Iterable<Item=u32>>() { |
508 | let y: T::Item = unknown; | 403 | let y: T::Item = unknown; |
404 | // ^^^^^^^ u32 | ||
509 | }"#, | 405 | }"#, |
510 | expect![[r#" | ||
511 | 67..100 '{ ...own; }': () | ||
512 | 77..78 'y': u32 | ||
513 | 90..97 'unknown': u32 | ||
514 | "#]], | ||
515 | ); | 406 | ); |
516 | } | 407 | } |
517 | 408 | ||
518 | #[test] | 409 | #[test] |
519 | fn infer_const_body() { | 410 | fn infer_const_body() { |
411 | // FIXME make check_types work with other bodies | ||
520 | check_infer( | 412 | check_infer( |
521 | r#" | 413 | r#" |
522 | const A: u32 = 1 + 1; | 414 | const A: u32 = 1 + 1; |
523 | static B: u64 = { let x = 1; x };"#, | 415 | static B: u64 = { let x = 1; x }; |
416 | "#, | ||
524 | expect![[r#" | 417 | expect![[r#" |
525 | 15..16 '1': u32 | 418 | 15..16 '1': u32 |
526 | 15..20 '1 + 1': u32 | 419 | 15..20 '1 + 1': u32 |
@@ -611,11 +504,11 @@ fn indexing_arrays() { | |||
611 | fn infer_ops_index() { | 504 | fn infer_ops_index() { |
612 | check_types( | 505 | check_types( |
613 | r#" | 506 | r#" |
614 | //- /main.rs crate:main deps:std | 507 | //- minicore: index |
615 | struct Bar; | 508 | struct Bar; |
616 | struct Foo; | 509 | struct Foo; |
617 | 510 | ||
618 | impl std::ops::Index<u32> for Bar { | 511 | impl core::ops::Index<u32> for Bar { |
619 | type Output = Foo; | 512 | type Output = Foo; |
620 | } | 513 | } |
621 | 514 | ||
@@ -624,15 +517,6 @@ fn test() { | |||
624 | let b = a[1u32]; | 517 | let b = a[1u32]; |
625 | b; | 518 | b; |
626 | } //^ Foo | 519 | } //^ Foo |
627 | |||
628 | //- /std.rs crate:std | ||
629 | #[prelude_import] use ops::*; | ||
630 | mod ops { | ||
631 | #[lang = "index"] | ||
632 | pub trait Index<Idx> { | ||
633 | type Output; | ||
634 | } | ||
635 | } | ||
636 | "#, | 520 | "#, |
637 | ); | 521 | ); |
638 | } | 522 | } |
@@ -641,16 +525,16 @@ mod ops { | |||
641 | fn infer_ops_index_int() { | 525 | fn infer_ops_index_int() { |
642 | check_types( | 526 | check_types( |
643 | r#" | 527 | r#" |
644 | //- /main.rs crate:main deps:std | 528 | //- minicore: index |
645 | struct Bar; | 529 | struct Bar; |
646 | struct Foo; | 530 | struct Foo; |
647 | 531 | ||
648 | impl std::ops::Index<u32> for Bar { | 532 | impl core::ops::Index<u32> for Bar { |
649 | type Output = Foo; | 533 | type Output = Foo; |
650 | } | 534 | } |
651 | 535 | ||
652 | struct Range; | 536 | struct Range; |
653 | impl std::ops::Index<Range> for Bar { | 537 | impl core::ops::Index<Range> for Bar { |
654 | type Output = Bar; | 538 | type Output = Bar; |
655 | } | 539 | } |
656 | 540 | ||
@@ -660,15 +544,6 @@ fn test() { | |||
660 | b; | 544 | b; |
661 | //^ Foo | 545 | //^ Foo |
662 | } | 546 | } |
663 | |||
664 | //- /std.rs crate:std | ||
665 | #[prelude_import] use ops::*; | ||
666 | mod ops { | ||
667 | #[lang = "index"] | ||
668 | pub trait Index<Idx> { | ||
669 | type Output; | ||
670 | } | ||
671 | } | ||
672 | "#, | 547 | "#, |
673 | ); | 548 | ); |
674 | } | 549 | } |
@@ -677,25 +552,12 @@ mod ops { | |||
677 | fn infer_ops_index_autoderef() { | 552 | fn infer_ops_index_autoderef() { |
678 | check_types( | 553 | check_types( |
679 | r#" | 554 | r#" |
680 | //- /main.rs crate:main deps:std | 555 | //- minicore: index, slice |
681 | fn test() { | 556 | fn test() { |
682 | let a = &[1u32, 2, 3]; | 557 | let a = &[1u32, 2, 3]; |
683 | let b = a[1u32]; | 558 | let b = a[1]; |
684 | b; | 559 | b; |
685 | } //^ u32 | 560 | } //^ u32 |
686 | |||
687 | //- /std.rs crate:std | ||
688 | impl<T> ops::Index<u32> for [T] { | ||
689 | type Output = T; | ||
690 | } | ||
691 | |||
692 | #[prelude_import] use ops::*; | ||
693 | mod ops { | ||
694 | #[lang = "index"] | ||
695 | pub trait Index<Idx> { | ||
696 | type Output; | ||
697 | } | ||
698 | } | ||
699 | "#, | 561 | "#, |
700 | ); | 562 | ); |
701 | } | 563 | } |
@@ -704,25 +566,20 @@ mod ops { | |||
704 | fn deref_trait() { | 566 | fn deref_trait() { |
705 | check_types( | 567 | check_types( |
706 | r#" | 568 | r#" |
707 | #[lang = "deref"] | 569 | //- minicore: deref |
708 | trait Deref { | ||
709 | type Target; | ||
710 | fn deref(&self) -> &Self::Target; | ||
711 | } | ||
712 | |||
713 | struct Arc<T>; | 570 | struct Arc<T>; |
714 | impl<T> Deref for Arc<T> { | 571 | impl<T> core::ops::Deref for Arc<T> { |
715 | type Target = T; | 572 | type Target = T; |
716 | } | 573 | } |
717 | 574 | ||
718 | struct S; | 575 | struct S; |
719 | impl S { | 576 | impl S { |
720 | fn foo(&self) -> u128 {} | 577 | fn foo(&self) -> u128 { 0 } |
721 | } | 578 | } |
722 | 579 | ||
723 | fn test(s: Arc<S>) { | 580 | fn test(s: Arc<S>) { |
724 | (*s, s.foo()); | 581 | (*s, s.foo()); |
725 | } //^ (S, u128) | 582 | } //^^^^^^^^^^^^^ (S, u128) |
726 | "#, | 583 | "#, |
727 | ); | 584 | ); |
728 | } | 585 | } |
@@ -731,16 +588,10 @@ fn test(s: Arc<S>) { | |||
731 | fn deref_trait_with_inference_var() { | 588 | fn deref_trait_with_inference_var() { |
732 | check_types( | 589 | check_types( |
733 | r#" | 590 | r#" |
734 | //- /main.rs | 591 | //- minicore: deref |
735 | #[lang = "deref"] | ||
736 | trait Deref { | ||
737 | type Target; | ||
738 | fn deref(&self) -> &Self::Target; | ||
739 | } | ||
740 | |||
741 | struct Arc<T>; | 592 | struct Arc<T>; |
742 | fn new_arc<T>() -> Arc<T> {} | 593 | fn new_arc<T>() -> Arc<T> { Arc } |
743 | impl<T> Deref for Arc<T> { | 594 | impl<T> core::ops::Deref for Arc<T> { |
744 | type Target = T; | 595 | type Target = T; |
745 | } | 596 | } |
746 | 597 | ||
@@ -749,8 +600,8 @@ fn foo(a: Arc<S>) {} | |||
749 | 600 | ||
750 | fn test() { | 601 | fn test() { |
751 | let a = new_arc(); | 602 | let a = new_arc(); |
752 | let b = (*a); | 603 | let b = *a; |
753 | //^ S | 604 | //^^ S |
754 | foo(a); | 605 | foo(a); |
755 | } | 606 | } |
756 | "#, | 607 | "#, |
@@ -761,21 +612,16 @@ fn test() { | |||
761 | fn deref_trait_infinite_recursion() { | 612 | fn deref_trait_infinite_recursion() { |
762 | check_types( | 613 | check_types( |
763 | r#" | 614 | r#" |
764 | #[lang = "deref"] | 615 | //- minicore: deref |
765 | trait Deref { | ||
766 | type Target; | ||
767 | fn deref(&self) -> &Self::Target; | ||
768 | } | ||
769 | |||
770 | struct S; | 616 | struct S; |
771 | 617 | ||
772 | impl Deref for S { | 618 | impl core::ops::Deref for S { |
773 | type Target = S; | 619 | type Target = S; |
774 | } | 620 | } |
775 | 621 | ||
776 | fn test(s: S) { | 622 | fn test(s: S) { |
777 | s.foo(); | 623 | s.foo(); |
778 | } //^ {unknown} | 624 | } //^^^^^^^ {unknown} |
779 | "#, | 625 | "#, |
780 | ); | 626 | ); |
781 | } | 627 | } |
@@ -784,25 +630,20 @@ fn test(s: S) { | |||
784 | fn deref_trait_with_question_mark_size() { | 630 | fn deref_trait_with_question_mark_size() { |
785 | check_types( | 631 | check_types( |
786 | r#" | 632 | r#" |
787 | #[lang = "deref"] | 633 | //- minicore: deref |
788 | trait Deref { | ||
789 | type Target; | ||
790 | fn deref(&self) -> &Self::Target; | ||
791 | } | ||
792 | |||
793 | struct Arc<T>; | 634 | struct Arc<T>; |
794 | impl<T> Deref for Arc<T> { | 635 | impl<T: ?Sized> core::ops::Deref for Arc<T> { |
795 | type Target = T; | 636 | type Target = T; |
796 | } | 637 | } |
797 | 638 | ||
798 | struct S; | 639 | struct S; |
799 | impl S { | 640 | impl S { |
800 | fn foo(&self) -> u128 {} | 641 | fn foo(&self) -> u128 { 0 } |
801 | } | 642 | } |
802 | 643 | ||
803 | fn test(s: Arc<S>) { | 644 | fn test(s: Arc<S>) { |
804 | (*s, s.foo()); | 645 | (*s, s.foo()); |
805 | } //^ (S, u128) | 646 | } //^^^^^^^^^^^^^ (S, u128) |
806 | "#, | 647 | "#, |
807 | ); | 648 | ); |
808 | } | 649 | } |
@@ -816,11 +657,11 @@ struct S; | |||
816 | trait Trait<T> {} | 657 | trait Trait<T> {} |
817 | impl Trait<u32> for S {} | 658 | impl Trait<u32> for S {} |
818 | 659 | ||
819 | fn foo<T: Trait<U>, U>(t: T) -> U {} | 660 | fn foo<T: Trait<U>, U>(t: T) -> U { loop {} } |
820 | 661 | ||
821 | fn test(s: S) { | 662 | fn test(s: S) { |
822 | (foo(s)); | 663 | foo(s); |
823 | } //^ u32 | 664 | } //^^^^^^ u32 |
824 | "#, | 665 | "#, |
825 | ); | 666 | ); |
826 | } | 667 | } |
@@ -837,12 +678,12 @@ impl Trait<isize> for S {} | |||
837 | 678 | ||
838 | struct O; | 679 | struct O; |
839 | impl O { | 680 | impl O { |
840 | fn foo<T: Trait<U>, U>(&self, t: T) -> U {} | 681 | fn foo<T: Trait<U>, U>(&self, t: T) -> U { loop {} } |
841 | } | 682 | } |
842 | 683 | ||
843 | fn test() { | 684 | fn test() { |
844 | O.foo(S); | 685 | O.foo(S); |
845 | } //^ isize | 686 | } //^^^^^^^^ isize |
846 | "#, | 687 | "#, |
847 | ); | 688 | ); |
848 | } | 689 | } |
@@ -857,12 +698,12 @@ trait Trait<T> {} | |||
857 | impl Trait<i64> for S {} | 698 | impl Trait<i64> for S {} |
858 | 699 | ||
859 | impl S { | 700 | impl S { |
860 | fn foo<U>(&self) -> U where Self: Trait<U> {} | 701 | fn foo<U>(&self) -> U where Self: Trait<U> { loop {} } |
861 | } | 702 | } |
862 | 703 | ||
863 | fn test() { | 704 | fn test() { |
864 | S.foo(); | 705 | S.foo(); |
865 | } //^ i64 | 706 | } //^^^^^^^ i64 |
866 | "#, | 707 | "#, |
867 | ); | 708 | ); |
868 | } | 709 | } |
@@ -878,12 +719,12 @@ impl Trait<&str> for S {} | |||
878 | 719 | ||
879 | struct O<T>; | 720 | struct O<T>; |
880 | impl<U, T: Trait<U>> O<T> { | 721 | impl<U, T: Trait<U>> O<T> { |
881 | fn foo(&self) -> U {} | 722 | fn foo(&self) -> U { loop {} } |
882 | } | 723 | } |
883 | 724 | ||
884 | fn test(o: O<S>) { | 725 | fn test(o: O<S>) { |
885 | o.foo(); | 726 | o.foo(); |
886 | } //^ &str | 727 | } //^^^^^^^ &str |
887 | "#, | 728 | "#, |
888 | ); | 729 | ); |
889 | } | 730 | } |
@@ -898,7 +739,7 @@ struct S; | |||
898 | impl Clone for S {} | 739 | impl Clone for S {} |
899 | impl<T> Trait for T where T: Clone {} | 740 | impl<T> Trait for T where T: Clone {} |
900 | fn test<T: Clone>(t: T) { t.foo(); } | 741 | fn test<T: Clone>(t: T) { t.foo(); } |
901 | //^ u128 | 742 | //^^^^^^^ u128 |
902 | "#, | 743 | "#, |
903 | ); | 744 | ); |
904 | } | 745 | } |
@@ -914,7 +755,7 @@ struct S; | |||
914 | impl Clone for S {} | 755 | impl Clone for S {} |
915 | impl<T> Trait for T where T: Clone {} | 756 | impl<T> Trait for T where T: Clone {} |
916 | fn test<T>(t: T) { t.foo(); } | 757 | fn test<T>(t: T) { t.foo(); } |
917 | //^ {unknown} | 758 | //^^^^^^^ {unknown} |
918 | "#, | 759 | "#, |
919 | ); | 760 | ); |
920 | } | 761 | } |
@@ -927,7 +768,7 @@ trait Trait { fn foo(self) -> u128; } | |||
927 | struct S; | 768 | struct S; |
928 | impl Trait for S {} | 769 | impl Trait for S {} |
929 | fn test<T: Trait>(t: T) { t.foo(); } | 770 | fn test<T: Trait>(t: T) { t.foo(); } |
930 | //^ u128 | 771 | //^^^^^^^ u128 |
931 | "#, | 772 | "#, |
932 | ); | 773 | ); |
933 | } | 774 | } |
@@ -940,7 +781,7 @@ trait Trait { fn foo(self) -> u128; } | |||
940 | struct S; | 781 | struct S; |
941 | impl Trait for S {} | 782 | impl Trait for S {} |
942 | fn test<T>(t: T) { t.foo(); } | 783 | fn test<T>(t: T) { t.foo(); } |
943 | //^ {unknown} | 784 | //^^^^^^^ {unknown} |
944 | "#, | 785 | "#, |
945 | ); | 786 | ); |
946 | } | 787 | } |
@@ -949,16 +790,13 @@ fn test<T>(t: T) { t.foo(); } | |||
949 | fn generic_param_env_deref() { | 790 | fn generic_param_env_deref() { |
950 | check_types( | 791 | check_types( |
951 | r#" | 792 | r#" |
952 | #[lang = "deref"] | 793 | //- minicore: deref |
953 | trait Deref { | ||
954 | type Target; | ||
955 | } | ||
956 | trait Trait {} | 794 | trait Trait {} |
957 | impl<T> Deref for T where T: Trait { | 795 | impl<T> core::ops::Deref for T where T: Trait { |
958 | type Target = i128; | 796 | type Target = i128; |
959 | } | 797 | } |
960 | fn test<T: Trait>(t: T) { (*t); } | 798 | fn test<T: Trait>(t: T) { *t; } |
961 | //^ i128 | 799 | //^^ i128 |
962 | "#, | 800 | "#, |
963 | ); | 801 | ); |
964 | } | 802 | } |
@@ -1475,17 +1313,16 @@ fn test( | |||
1475 | } | 1313 | } |
1476 | 1314 | ||
1477 | #[test] | 1315 | #[test] |
1478 | #[ignore] | ||
1479 | fn error_bound_chalk() { | 1316 | fn error_bound_chalk() { |
1480 | check_types( | 1317 | check_types( |
1481 | r#" | 1318 | r#" |
1482 | trait Trait { | 1319 | trait Trait { |
1483 | fn foo(&self) -> u32 {} | 1320 | fn foo(&self) -> u32 { 0 } |
1484 | } | 1321 | } |
1485 | 1322 | ||
1486 | fn test(x: (impl Trait + UnknownTrait)) { | 1323 | fn test(x: (impl Trait + UnknownTrait)) { |
1487 | x.foo(); | 1324 | x.foo(); |
1488 | } //^ u32 | 1325 | } //^^^^^^^ u32 |
1489 | "#, | 1326 | "#, |
1490 | ); | 1327 | ); |
1491 | } | 1328 | } |
@@ -1558,7 +1395,7 @@ fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) { | |||
1558 | fn impl_trait_assoc_binding_projection_bug() { | 1395 | fn impl_trait_assoc_binding_projection_bug() { |
1559 | check_types( | 1396 | check_types( |
1560 | r#" | 1397 | r#" |
1561 | //- /main.rs crate:main deps:std | 1398 | //- minicore: iterator |
1562 | pub trait Language { | 1399 | pub trait Language { |
1563 | type Kind; | 1400 | type Kind; |
1564 | } | 1401 | } |
@@ -1576,21 +1413,7 @@ trait Clone { | |||
1576 | fn api_walkthrough() { | 1413 | fn api_walkthrough() { |
1577 | for node in foo() { | 1414 | for node in foo() { |
1578 | node.clone(); | 1415 | node.clone(); |
1579 | } //^ {unknown} | 1416 | } //^^^^^^^^^^^^ {unknown} |
1580 | } | ||
1581 | |||
1582 | //- /std.rs crate:std | ||
1583 | #[prelude_import] use iter::*; | ||
1584 | mod iter { | ||
1585 | trait IntoIterator { | ||
1586 | type Item; | ||
1587 | } | ||
1588 | trait Iterator { | ||
1589 | type Item; | ||
1590 | } | ||
1591 | impl<T: Iterator> IntoIterator for T { | ||
1592 | type Item = <T as Iterator>::Item; | ||
1593 | } | ||
1594 | } | 1417 | } |
1595 | "#, | 1418 | "#, |
1596 | ); | 1419 | ); |
@@ -1627,13 +1450,13 @@ fn where_clause_trait_in_scope_for_method_resolution() { | |||
1627 | r#" | 1450 | r#" |
1628 | mod foo { | 1451 | mod foo { |
1629 | trait Trait { | 1452 | trait Trait { |
1630 | fn foo(&self) -> u32 {} | 1453 | fn foo(&self) -> u32 { 0 } |
1631 | } | 1454 | } |
1632 | } | 1455 | } |
1633 | 1456 | ||
1634 | fn test<T: foo::Trait>(x: T) { | 1457 | fn test<T: foo::Trait>(x: T) { |
1635 | x.foo(); | 1458 | x.foo(); |
1636 | } //^ u32 | 1459 | } //^^^^^^^ u32 |
1637 | "#, | 1460 | "#, |
1638 | ); | 1461 | ); |
1639 | } | 1462 | } |
@@ -1838,20 +1661,7 @@ fn test() { | |||
1838 | fn fn_trait_deref_with_ty_default() { | 1661 | fn fn_trait_deref_with_ty_default() { |
1839 | check_infer( | 1662 | check_infer( |
1840 | r#" | 1663 | r#" |
1841 | #[lang = "deref"] | 1664 | //- minicore: deref, fn |
1842 | trait Deref { | ||
1843 | type Target; | ||
1844 | |||
1845 | fn deref(&self) -> &Self::Target; | ||
1846 | } | ||
1847 | |||
1848 | #[lang="fn_once"] | ||
1849 | trait FnOnce<Args> { | ||
1850 | type Output; | ||
1851 | |||
1852 | fn call_once(self, args: Args) -> Self::Output; | ||
1853 | } | ||
1854 | |||
1855 | struct Foo; | 1665 | struct Foo; |
1856 | 1666 | ||
1857 | impl Foo { | 1667 | impl Foo { |
@@ -1864,7 +1674,7 @@ impl<T, F> Lazy<T, F> { | |||
1864 | pub fn new(f: F) -> Lazy<T, F> {} | 1674 | pub fn new(f: F) -> Lazy<T, F> {} |
1865 | } | 1675 | } |
1866 | 1676 | ||
1867 | impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { | 1677 | impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> { |
1868 | type Target = T; | 1678 | type Target = T; |
1869 | } | 1679 | } |
1870 | 1680 | ||
@@ -1878,32 +1688,29 @@ fn test() { | |||
1878 | let r2 = lazy2.foo(); | 1688 | let r2 = lazy2.foo(); |
1879 | }"#, | 1689 | }"#, |
1880 | expect![[r#" | 1690 | expect![[r#" |
1881 | 64..68 'self': &Self | 1691 | 36..40 'self': &Foo |
1882 | 165..169 'self': Self | 1692 | 51..53 '{}': () |
1883 | 171..175 'args': Args | 1693 | 131..132 'f': F |
1884 | 239..243 'self': &Foo | 1694 | 151..153 '{}': () |
1885 | 254..256 '{}': () | 1695 | 251..497 '{ ...o(); }': () |
1886 | 334..335 'f': F | 1696 | 261..266 'lazy1': Lazy<Foo, || -> Foo> |
1887 | 354..356 '{}': () | 1697 | 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo> |
1888 | 443..689 '{ ...o(); }': () | 1698 | 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo> |
1889 | 453..458 'lazy1': Lazy<Foo, || -> Foo> | 1699 | 293..299 '|| Foo': || -> Foo |
1890 | 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo> | 1700 | 296..299 'Foo': Foo |
1891 | 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo> | 1701 | 310..312 'r1': usize |
1892 | 485..491 '|| Foo': || -> Foo | 1702 | 315..320 'lazy1': Lazy<Foo, || -> Foo> |
1893 | 488..491 'Foo': Foo | 1703 | 315..326 'lazy1.foo()': usize |
1894 | 502..504 'r1': usize | 1704 | 368..383 'make_foo_fn_ptr': fn() -> Foo |
1895 | 507..512 'lazy1': Lazy<Foo, || -> Foo> | 1705 | 399..410 'make_foo_fn': fn make_foo_fn() -> Foo |
1896 | 507..518 'lazy1.foo()': usize | 1706 | 420..425 'lazy2': Lazy<Foo, fn() -> Foo> |
1897 | 560..575 'make_foo_fn_ptr': fn() -> Foo | 1707 | 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo> |
1898 | 591..602 'make_foo_fn': fn make_foo_fn() -> Foo | 1708 | 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo> |
1899 | 612..617 'lazy2': Lazy<Foo, fn() -> Foo> | 1709 | 452..467 'make_foo_fn_ptr': fn() -> Foo |
1900 | 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo> | 1710 | 478..480 'r2': usize |
1901 | 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo> | 1711 | 483..488 'lazy2': Lazy<Foo, fn() -> Foo> |
1902 | 644..659 'make_foo_fn_ptr': fn() -> Foo | 1712 | 483..494 'lazy2.foo()': usize |
1903 | 670..672 'r2': usize | 1713 | 357..359 '{}': () |
1904 | 675..680 'lazy2': Lazy<Foo, fn() -> Foo> | ||
1905 | 675..686 'lazy2.foo()': usize | ||
1906 | 549..551 '{}': () | ||
1907 | "#]], | 1714 | "#]], |
1908 | ); | 1715 | ); |
1909 | } | 1716 | } |
@@ -1912,11 +1719,7 @@ fn test() { | |||
1912 | fn closure_1() { | 1719 | fn closure_1() { |
1913 | check_infer_with_mismatches( | 1720 | check_infer_with_mismatches( |
1914 | r#" | 1721 | r#" |
1915 | #[lang = "fn_once"] | 1722 | //- minicore: fn |
1916 | trait FnOnce<Args> { | ||
1917 | type Output; | ||
1918 | } | ||
1919 | |||
1920 | enum Option<T> { Some(T), None } | 1723 | enum Option<T> { Some(T), None } |
1921 | impl<T> Option<T> { | 1724 | impl<T> Option<T> { |
1922 | fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} } | 1725 | fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} } |
@@ -1929,34 +1732,34 @@ fn test() { | |||
1929 | let y: Option<i64> = x.map(|_v| 1); | 1732 | let y: Option<i64> = x.map(|_v| 1); |
1930 | }"#, | 1733 | }"#, |
1931 | expect![[r#" | 1734 | expect![[r#" |
1932 | 147..151 'self': Option<T> | 1735 | 86..90 'self': Option<T> |
1933 | 153..154 'f': F | 1736 | 92..93 'f': F |
1934 | 172..183 '{ loop {} }': Option<U> | 1737 | 111..122 '{ loop {} }': Option<U> |
1935 | 174..181 'loop {}': ! | 1738 | 113..120 'loop {}': ! |
1936 | 179..181 '{}': () | 1739 | 118..120 '{}': () |
1937 | 197..316 '{ ... 1); }': () | 1740 | 136..255 '{ ... 1); }': () |
1938 | 207..208 'x': Option<u32> | 1741 | 146..147 'x': Option<u32> |
1939 | 211..223 'Option::Some': Some<u32>(u32) -> Option<u32> | 1742 | 150..162 'Option::Some': Some<u32>(u32) -> Option<u32> |
1940 | 211..229 'Option...(1u32)': Option<u32> | 1743 | 150..168 'Option...(1u32)': Option<u32> |
1941 | 224..228 '1u32': u32 | 1744 | 163..167 '1u32': u32 |
1942 | 235..236 'x': Option<u32> | 1745 | 174..175 'x': Option<u32> |
1943 | 235..251 'x.map(...v + 1)': Option<u32> | 1746 | 174..190 'x.map(...v + 1)': Option<u32> |
1944 | 241..250 '|v| v + 1': |u32| -> u32 | 1747 | 180..189 '|v| v + 1': |u32| -> u32 |
1945 | 242..243 'v': u32 | 1748 | 181..182 'v': u32 |
1946 | 245..246 'v': u32 | 1749 | 184..185 'v': u32 |
1947 | 245..250 'v + 1': u32 | 1750 | 184..189 'v + 1': u32 |
1948 | 249..250 '1': u32 | 1751 | 188..189 '1': u32 |
1949 | 257..258 'x': Option<u32> | 1752 | 196..197 'x': Option<u32> |
1950 | 257..273 'x.map(... 1u64)': Option<u64> | 1753 | 196..212 'x.map(... 1u64)': Option<u64> |
1951 | 263..272 '|_v| 1u64': |u32| -> u64 | 1754 | 202..211 '|_v| 1u64': |u32| -> u64 |
1952 | 264..266 '_v': u32 | 1755 | 203..205 '_v': u32 |
1953 | 268..272 '1u64': u64 | 1756 | 207..211 '1u64': u64 |
1954 | 283..284 'y': Option<i64> | 1757 | 222..223 'y': Option<i64> |
1955 | 300..301 'x': Option<u32> | 1758 | 239..240 'x': Option<u32> |
1956 | 300..313 'x.map(|_v| 1)': Option<i64> | 1759 | 239..252 'x.map(|_v| 1)': Option<i64> |
1957 | 306..312 '|_v| 1': |u32| -> i64 | 1760 | 245..251 '|_v| 1': |u32| -> i64 |
1958 | 307..309 '_v': u32 | 1761 | 246..248 '_v': u32 |
1959 | 311..312 '1': i64 | 1762 | 250..251 '1': i64 |
1960 | "#]], | 1763 | "#]], |
1961 | ); | 1764 | ); |
1962 | } | 1765 | } |
@@ -2030,11 +1833,7 @@ fn test<F: FnOnce(u32) -> u64>(f: F) { | |||
2030 | fn closure_as_argument_inference_order() { | 1833 | fn closure_as_argument_inference_order() { |
2031 | check_infer_with_mismatches( | 1834 | check_infer_with_mismatches( |
2032 | r#" | 1835 | r#" |
2033 | #[lang = "fn_once"] | 1836 | //- minicore: fn |
2034 | trait FnOnce<Args> { | ||
2035 | type Output; | ||
2036 | } | ||
2037 | |||
2038 | fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} } | 1837 | fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} } |
2039 | fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} } | 1838 | fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} } |
2040 | 1839 | ||
@@ -2053,62 +1852,62 @@ fn test() { | |||
2053 | let x4 = S.foo2(|s| s.method(), S); | 1852 | let x4 = S.foo2(|s| s.method(), S); |
2054 | }"#, | 1853 | }"#, |
2055 | expect![[r#" | 1854 | expect![[r#" |
2056 | 94..95 'x': T | 1855 | 33..34 'x': T |
2057 | 100..101 'f': F | 1856 | 39..40 'f': F |
2058 | 111..122 '{ loop {} }': U | 1857 | 50..61 '{ loop {} }': U |
2059 | 113..120 'loop {}': ! | 1858 | 52..59 'loop {}': ! |
2060 | 118..120 '{}': () | 1859 | 57..59 '{}': () |
2061 | 156..157 'f': F | 1860 | 95..96 'f': F |
2062 | 162..163 'x': T | 1861 | 101..102 'x': T |
2063 | 173..184 '{ loop {} }': U | 1862 | 112..123 '{ loop {} }': U |
2064 | 175..182 'loop {}': ! | 1863 | 114..121 'loop {}': ! |
2065 | 180..182 '{}': () | 1864 | 119..121 '{}': () |
2066 | 219..223 'self': S | 1865 | 158..162 'self': S |
2067 | 271..275 'self': S | 1866 | 210..214 'self': S |
2068 | 277..278 'x': T | 1867 | 216..217 'x': T |
2069 | 283..284 'f': F | 1868 | 222..223 'f': F |
2070 | 294..305 '{ loop {} }': U | 1869 | 233..244 '{ loop {} }': U |
2071 | 296..303 'loop {}': ! | 1870 | 235..242 'loop {}': ! |
2072 | 301..303 '{}': () | 1871 | 240..242 '{}': () |
2073 | 343..347 'self': S | 1872 | 282..286 'self': S |
2074 | 349..350 'f': F | 1873 | 288..289 'f': F |
2075 | 355..356 'x': T | 1874 | 294..295 'x': T |
2076 | 366..377 '{ loop {} }': U | 1875 | 305..316 '{ loop {} }': U |
2077 | 368..375 'loop {}': ! | 1876 | 307..314 'loop {}': ! |
2078 | 373..375 '{}': () | 1877 | 312..314 '{}': () |
2079 | 391..550 '{ ... S); }': () | 1878 | 330..489 '{ ... S); }': () |
2080 | 401..403 'x1': u64 | 1879 | 340..342 'x1': u64 |
2081 | 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64 | 1880 | 345..349 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64 |
2082 | 406..429 'foo1(S...hod())': u64 | 1881 | 345..368 'foo1(S...hod())': u64 |
2083 | 411..412 'S': S | 1882 | 350..351 'S': S |
2084 | 414..428 '|s| s.method()': |S| -> u64 | 1883 | 353..367 '|s| s.method()': |S| -> u64 |
2085 | 415..416 's': S | 1884 | 354..355 's': S |
2086 | 418..419 's': S | 1885 | 357..358 's': S |
2087 | 418..428 's.method()': u64 | 1886 | 357..367 's.method()': u64 |
2088 | 439..441 'x2': u64 | 1887 | 378..380 'x2': u64 |
2089 | 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64 | 1888 | 383..387 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64 |
2090 | 444..467 'foo2(|...(), S)': u64 | 1889 | 383..406 'foo2(|...(), S)': u64 |
2091 | 449..463 '|s| s.method()': |S| -> u64 | 1890 | 388..402 '|s| s.method()': |S| -> u64 |
2092 | 450..451 's': S | 1891 | 389..390 's': S |
2093 | 453..454 's': S | 1892 | 392..393 's': S |
2094 | 453..463 's.method()': u64 | 1893 | 392..402 's.method()': u64 |
2095 | 465..466 'S': S | 1894 | 404..405 'S': S |
2096 | 477..479 'x3': u64 | 1895 | 416..418 'x3': u64 |
2097 | 482..483 'S': S | 1896 | 421..422 'S': S |
2098 | 482..507 'S.foo1...hod())': u64 | 1897 | 421..446 'S.foo1...hod())': u64 |
2099 | 489..490 'S': S | 1898 | 428..429 'S': S |
2100 | 492..506 '|s| s.method()': |S| -> u64 | 1899 | 431..445 '|s| s.method()': |S| -> u64 |
2101 | 493..494 's': S | 1900 | 432..433 's': S |
2102 | 496..497 's': S | 1901 | 435..436 's': S |
2103 | 496..506 's.method()': u64 | 1902 | 435..445 's.method()': u64 |
2104 | 517..519 'x4': u64 | 1903 | 456..458 'x4': u64 |
2105 | 522..523 'S': S | 1904 | 461..462 'S': S |
2106 | 522..547 'S.foo2...(), S)': u64 | 1905 | 461..486 'S.foo2...(), S)': u64 |
2107 | 529..543 '|s| s.method()': |S| -> u64 | 1906 | 468..482 '|s| s.method()': |S| -> u64 |
2108 | 530..531 's': S | 1907 | 469..470 's': S |
2109 | 533..534 's': S | 1908 | 472..473 's': S |
2110 | 533..543 's.method()': u64 | 1909 | 472..482 's.method()': u64 |
2111 | 545..546 'S': S | 1910 | 484..485 'S': S |
2112 | "#]], | 1911 | "#]], |
2113 | ); | 1912 | ); |
2114 | } | 1913 | } |
@@ -2117,14 +1916,10 @@ fn test() { | |||
2117 | fn fn_item_fn_trait() { | 1916 | fn fn_item_fn_trait() { |
2118 | check_types( | 1917 | check_types( |
2119 | r#" | 1918 | r#" |
2120 | #[lang = "fn_once"] | 1919 | //- minicore: fn |
2121 | trait FnOnce<Args> { | ||
2122 | type Output; | ||
2123 | } | ||
2124 | |||
2125 | struct S; | 1920 | struct S; |
2126 | 1921 | ||
2127 | fn foo() -> S {} | 1922 | fn foo() -> S { S } |
2128 | 1923 | ||
2129 | fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() } | 1924 | fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() } |
2130 | 1925 | ||
@@ -2151,7 +1946,7 @@ trait Trait2 { | |||
2151 | fn test<T: Trait>() where T::Item: Trait2 { | 1946 | fn test<T: Trait>() where T::Item: Trait2 { |
2152 | let x: T::Item = no_matter; | 1947 | let x: T::Item = no_matter; |
2153 | x.foo(); | 1948 | x.foo(); |
2154 | } //^ u32 | 1949 | } //^^^^^^^ u32 |
2155 | "#, | 1950 | "#, |
2156 | ); | 1951 | ); |
2157 | } | 1952 | } |
@@ -2171,7 +1966,7 @@ trait Trait2 { | |||
2171 | fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { | 1966 | fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { |
2172 | let x: T::Item = no_matter; | 1967 | let x: T::Item = no_matter; |
2173 | x.foo(); | 1968 | x.foo(); |
2174 | } //^ u32 | 1969 | } //^^^^^^^ u32 |
2175 | "#, | 1970 | "#, |
2176 | ); | 1971 | ); |
2177 | } | 1972 | } |
@@ -2234,7 +2029,7 @@ impl Trait for S { | |||
2234 | 2029 | ||
2235 | fn test() { | 2030 | fn test() { |
2236 | S.f(); | 2031 | S.f(); |
2237 | } //^ u32 | 2032 | } //^^^^^ u32 |
2238 | "#, | 2033 | "#, |
2239 | ); | 2034 | ); |
2240 | } | 2035 | } |
@@ -2262,7 +2057,7 @@ where | |||
2262 | 2057 | ||
2263 | fn foo<I: Interner>(interner: &I, t: Ty<I>) { | 2058 | fn foo<I: Interner>(interner: &I, t: Ty<I>) { |
2264 | fold(interner, t); | 2059 | fold(interner, t); |
2265 | } //^ Ty<I> | 2060 | } //^^^^^^^^^^^^^^^^^ Ty<I> |
2266 | "#, | 2061 | "#, |
2267 | ); | 2062 | ); |
2268 | } | 2063 | } |
@@ -2281,7 +2076,7 @@ impl Trait<Self> for S {} | |||
2281 | 2076 | ||
2282 | fn test() { | 2077 | fn test() { |
2283 | S.foo(); | 2078 | S.foo(); |
2284 | } //^ () | 2079 | } //^^^^^^^ () |
2285 | "#, | 2080 | "#, |
2286 | ); | 2081 | ); |
2287 | } | 2082 | } |
@@ -2300,7 +2095,7 @@ impl Trait for S<Self> {} | |||
2300 | 2095 | ||
2301 | fn test() { | 2096 | fn test() { |
2302 | S.foo(); | 2097 | S.foo(); |
2303 | } //^ {unknown} | 2098 | } //^^^^^^^ {unknown} |
2304 | "#, | 2099 | "#, |
2305 | ); | 2100 | ); |
2306 | } | 2101 | } |
@@ -2318,7 +2113,7 @@ trait Trait2<T> {} | |||
2318 | 2113 | ||
2319 | fn test<T: Trait>() where T: Trait2<T::Item> { | 2114 | fn test<T: Trait>() where T: Trait2<T::Item> { |
2320 | let x: T::Item = no_matter; | 2115 | let x: T::Item = no_matter; |
2321 | } //^ {unknown} | 2116 | } //^^^^^^^^^ {unknown} |
2322 | "#, | 2117 | "#, |
2323 | ); | 2118 | ); |
2324 | } | 2119 | } |
@@ -2335,7 +2130,7 @@ trait Trait<T> { | |||
2335 | 2130 | ||
2336 | fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> { | 2131 | fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> { |
2337 | let x: T::Item = no_matter; | 2132 | let x: T::Item = no_matter; |
2338 | } //^ {unknown} | 2133 | } //^^^^^^^^^ {unknown} |
2339 | "#, | 2134 | "#, |
2340 | ); | 2135 | ); |
2341 | } | 2136 | } |
@@ -2353,7 +2148,7 @@ trait Trait { | |||
2353 | 2148 | ||
2354 | fn test<T>() where T: Trait<OtherItem = T::Item> { | 2149 | fn test<T>() where T: Trait<OtherItem = T::Item> { |
2355 | let x: T::Item = no_matter; | 2150 | let x: T::Item = no_matter; |
2356 | } //^ Trait::Item<T> | 2151 | } //^^^^^^^^^ Trait::Item<T> |
2357 | "#, | 2152 | "#, |
2358 | ); | 2153 | ); |
2359 | } | 2154 | } |
@@ -2385,7 +2180,7 @@ fn test<T>(t: T) where T: UnificationStoreMut { | |||
2385 | t.push(x); | 2180 | t.push(x); |
2386 | let y: Key<T>; | 2181 | let y: Key<T>; |
2387 | (x, y); | 2182 | (x, y); |
2388 | } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>) | 2183 | } //^^^^^^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>) |
2389 | "#, | 2184 | "#, |
2390 | ); | 2185 | ); |
2391 | } | 2186 | } |
@@ -2410,7 +2205,7 @@ impl<T: Iterator> Iterator for S<T> { | |||
2410 | fn test<I: Iterator<Item: OtherTrait<u32>>>() { | 2205 | fn test<I: Iterator<Item: OtherTrait<u32>>>() { |
2411 | let x: <S<I> as Iterator>::Item; | 2206 | let x: <S<I> as Iterator>::Item; |
2412 | x.foo(); | 2207 | x.foo(); |
2413 | } //^ u32 | 2208 | } //^^^^^^^ u32 |
2414 | "#, | 2209 | "#, |
2415 | ); | 2210 | ); |
2416 | } | 2211 | } |
@@ -2560,12 +2355,7 @@ fn test() -> impl Trait<i32> { | |||
2560 | fn assoc_types_from_bounds() { | 2355 | fn assoc_types_from_bounds() { |
2561 | check_infer( | 2356 | check_infer( |
2562 | r#" | 2357 | r#" |
2563 | //- /main.rs | 2358 | //- minicore: fn |
2564 | #[lang = "fn_once"] | ||
2565 | trait FnOnce<Args> { | ||
2566 | type Output; | ||
2567 | } | ||
2568 | |||
2569 | trait T { | 2359 | trait T { |
2570 | type O; | 2360 | type O; |
2571 | } | 2361 | } |
@@ -2584,15 +2374,15 @@ fn main() { | |||
2584 | f::<(), _>(|z| { z; }); | 2374 | f::<(), _>(|z| { z; }); |
2585 | }"#, | 2375 | }"#, |
2586 | expect![[r#" | 2376 | expect![[r#" |
2587 | 133..135 '_v': F | 2377 | 72..74 '_v': F |
2588 | 178..181 '{ }': () | 2378 | 117..120 '{ }': () |
2589 | 193..224 '{ ... }); }': () | 2379 | 132..163 '{ ... }); }': () |
2590 | 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ()) | 2380 | 138..148 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ()) |
2591 | 199..221 'f::<()... z; })': () | 2381 | 138..160 'f::<()... z; })': () |
2592 | 210..220 '|z| { z; }': |&()| -> () | 2382 | 149..159 '|z| { z; }': |&()| -> () |
2593 | 211..212 'z': &() | 2383 | 150..151 'z': &() |
2594 | 214..220 '{ z; }': () | 2384 | 153..159 '{ z; }': () |
2595 | 216..217 'z': &() | 2385 | 155..156 'z': &() |
2596 | "#]], | 2386 | "#]], |
2597 | ); | 2387 | ); |
2598 | } | 2388 | } |
@@ -2617,7 +2407,7 @@ impl<T: Trait> Trait for S<T> { | |||
2617 | fn test<T: Trait>() { | 2407 | fn test<T: Trait>() { |
2618 | let y: <S<T> as Trait>::Item = no_matter; | 2408 | let y: <S<T> as Trait>::Item = no_matter; |
2619 | y.foo(); | 2409 | y.foo(); |
2620 | } //^ u32 | 2410 | } //^^^^^^^ u32 |
2621 | "#, | 2411 | "#, |
2622 | ); | 2412 | ); |
2623 | } | 2413 | } |
@@ -2626,12 +2416,9 @@ fn test<T: Trait>() { | |||
2626 | fn dyn_trait_through_chalk() { | 2416 | fn dyn_trait_through_chalk() { |
2627 | check_types( | 2417 | check_types( |
2628 | r#" | 2418 | r#" |
2419 | //- minicore: deref | ||
2629 | struct Box<T> {} | 2420 | struct Box<T> {} |
2630 | #[lang = "deref"] | 2421 | impl<T> core::ops::Deref for Box<T> { |
2631 | trait Deref { | ||
2632 | type Target; | ||
2633 | } | ||
2634 | impl<T> Deref for Box<T> { | ||
2635 | type Target = T; | 2422 | type Target = T; |
2636 | } | 2423 | } |
2637 | trait Trait { | 2424 | trait Trait { |
@@ -2640,7 +2427,7 @@ trait Trait { | |||
2640 | 2427 | ||
2641 | fn test(x: Box<dyn Trait>) { | 2428 | fn test(x: Box<dyn Trait>) { |
2642 | x.foo(); | 2429 | x.foo(); |
2643 | } //^ () | 2430 | } //^^^^^^^ () |
2644 | "#, | 2431 | "#, |
2645 | ); | 2432 | ); |
2646 | } | 2433 | } |
@@ -2659,7 +2446,7 @@ impl ToOwned for str { | |||
2659 | } | 2446 | } |
2660 | fn test() { | 2447 | fn test() { |
2661 | "foo".to_owned(); | 2448 | "foo".to_owned(); |
2662 | } //^ String | 2449 | } //^^^^^^^^^^^^^^^^ String |
2663 | "#, | 2450 | "#, |
2664 | ); | 2451 | ); |
2665 | } | 2452 | } |
@@ -2668,17 +2455,7 @@ fn test() { | |||
2668 | fn iterator_chain() { | 2455 | fn iterator_chain() { |
2669 | check_infer_with_mismatches( | 2456 | check_infer_with_mismatches( |
2670 | r#" | 2457 | r#" |
2671 | //- /main.rs | 2458 | //- minicore: fn, option |
2672 | #[lang = "fn_once"] | ||
2673 | trait FnOnce<Args> { | ||
2674 | type Output; | ||
2675 | } | ||
2676 | #[lang = "fn_mut"] | ||
2677 | trait FnMut<Args>: FnOnce<Args> { } | ||
2678 | |||
2679 | enum Option<T> { Some(T), None } | ||
2680 | use Option::*; | ||
2681 | |||
2682 | pub trait Iterator { | 2459 | pub trait Iterator { |
2683 | type Item; | 2460 | type Item; |
2684 | 2461 | ||
@@ -2738,46 +2515,46 @@ fn main() { | |||
2738 | .for_each(|y| { y; }); | 2515 | .for_each(|y| { y; }); |
2739 | }"#, | 2516 | }"#, |
2740 | expect![[r#" | 2517 | expect![[r#" |
2741 | 226..230 'self': Self | 2518 | 61..65 'self': Self |
2742 | 232..233 'f': F | 2519 | 67..68 'f': F |
2743 | 317..328 '{ loop {} }': FilterMap<Self, F> | 2520 | 152..163 '{ loop {} }': FilterMap<Self, F> |
2744 | 319..326 'loop {}': ! | 2521 | 154..161 'loop {}': ! |
2745 | 324..326 '{}': () | 2522 | 159..161 '{}': () |
2746 | 349..353 'self': Self | 2523 | 184..188 'self': Self |
2747 | 355..356 'f': F | 2524 | 190..191 'f': F |
2748 | 405..416 '{ loop {} }': () | 2525 | 240..251 '{ loop {} }': () |
2749 | 407..414 'loop {}': ! | 2526 | 242..249 'loop {}': ! |
2750 | 412..414 '{}': () | 2527 | 247..249 '{}': () |
2751 | 525..529 'self': Self | 2528 | 360..364 'self': Self |
2752 | 854..858 'self': I | 2529 | 689..693 'self': I |
2753 | 865..885 '{ ... }': I | 2530 | 700..720 '{ ... }': I |
2754 | 875..879 'self': I | 2531 | 710..714 'self': I |
2755 | 944..955 '{ loop {} }': Vec<T> | 2532 | 779..790 '{ loop {} }': Vec<T> |
2756 | 946..953 'loop {}': ! | 2533 | 781..788 'loop {}': ! |
2757 | 951..953 '{}': () | 2534 | 786..788 '{}': () |
2758 | 1142..1269 '{ ... }); }': () | 2535 | 977..1104 '{ ... }); }': () |
2759 | 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32> | 2536 | 983..998 'Vec::<i32>::new': fn new<i32>() -> Vec<i32> |
2760 | 1148..1165 'Vec::<...:new()': Vec<i32> | 2537 | 983..1000 'Vec::<...:new()': Vec<i32> |
2761 | 1148..1177 'Vec::<...iter()': IntoIter<i32> | 2538 | 983..1012 'Vec::<...iter()': IntoIter<i32> |
2762 | 1148..1240 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>> | 2539 | 983..1075 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>> |
2763 | 1148..1266 'Vec::<... y; })': () | 2540 | 983..1101 'Vec::<... y; })': () |
2764 | 1194..1239 '|x| if...None }': |i32| -> Option<u32> | 2541 | 1029..1074 '|x| if...None }': |i32| -> Option<u32> |
2765 | 1195..1196 'x': i32 | 2542 | 1030..1031 'x': i32 |
2766 | 1198..1239 'if x >...None }': Option<u32> | 2543 | 1033..1074 'if x >...None }': Option<u32> |
2767 | 1201..1202 'x': i32 | 2544 | 1036..1037 'x': i32 |
2768 | 1201..1206 'x > 0': bool | 2545 | 1036..1041 'x > 0': bool |
2769 | 1205..1206 '0': i32 | 2546 | 1040..1041 '0': i32 |
2770 | 1207..1225 '{ Some...u32) }': Option<u32> | 2547 | 1042..1060 '{ Some...u32) }': Option<u32> |
2771 | 1209..1213 'Some': Some<u32>(u32) -> Option<u32> | 2548 | 1044..1048 'Some': Some<u32>(u32) -> Option<u32> |
2772 | 1209..1223 'Some(x as u32)': Option<u32> | 2549 | 1044..1058 'Some(x as u32)': Option<u32> |
2773 | 1214..1215 'x': i32 | 2550 | 1049..1050 'x': i32 |
2774 | 1214..1222 'x as u32': u32 | 2551 | 1049..1057 'x as u32': u32 |
2775 | 1231..1239 '{ None }': Option<u32> | 2552 | 1066..1074 '{ None }': Option<u32> |
2776 | 1233..1237 'None': Option<u32> | 2553 | 1068..1072 'None': Option<u32> |
2777 | 1255..1265 '|y| { y; }': |u32| -> () | 2554 | 1090..1100 '|y| { y; }': |u32| -> () |
2778 | 1256..1257 'y': u32 | 2555 | 1091..1092 'y': u32 |
2779 | 1259..1265 '{ y; }': () | 2556 | 1094..1100 '{ y; }': () |
2780 | 1261..1262 'y': u32 | 2557 | 1096..1097 'y': u32 |
2781 | "#]], | 2558 | "#]], |
2782 | ); | 2559 | ); |
2783 | } | 2560 | } |
@@ -2809,7 +2586,7 @@ impl<T:A> B for T { | |||
2809 | 2586 | ||
2810 | fn main() { | 2587 | fn main() { |
2811 | Bar::foo(); | 2588 | Bar::foo(); |
2812 | } //^ Foo | 2589 | } //^^^^^^^^^^ Foo |
2813 | "#, | 2590 | "#, |
2814 | ); | 2591 | ); |
2815 | } | 2592 | } |
@@ -2841,9 +2618,7 @@ fn test(x: &dyn Foo) { | |||
2841 | fn builtin_copy() { | 2618 | fn builtin_copy() { |
2842 | check_infer_with_mismatches( | 2619 | check_infer_with_mismatches( |
2843 | r#" | 2620 | r#" |
2844 | #[lang = "copy"] | 2621 | //- minicore: copy |
2845 | trait Copy {} | ||
2846 | |||
2847 | struct IsCopy; | 2622 | struct IsCopy; |
2848 | impl Copy for IsCopy {} | 2623 | impl Copy for IsCopy {} |
2849 | struct NotCopy; | 2624 | struct NotCopy; |
@@ -2858,20 +2633,20 @@ fn test() { | |||
2858 | (IsCopy, NotCopy).test(); | 2633 | (IsCopy, NotCopy).test(); |
2859 | }"#, | 2634 | }"#, |
2860 | expect![[r#" | 2635 | expect![[r#" |
2861 | 110..114 'self': &Self | 2636 | 78..82 'self': &Self |
2862 | 166..267 '{ ...t(); }': () | 2637 | 134..235 '{ ...t(); }': () |
2863 | 172..178 'IsCopy': IsCopy | 2638 | 140..146 'IsCopy': IsCopy |
2864 | 172..185 'IsCopy.test()': bool | 2639 | 140..153 'IsCopy.test()': bool |
2865 | 191..198 'NotCopy': NotCopy | 2640 | 159..166 'NotCopy': NotCopy |
2866 | 191..205 'NotCopy.test()': {unknown} | 2641 | 159..173 'NotCopy.test()': {unknown} |
2867 | 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy) | 2642 | 179..195 '(IsCop...sCopy)': (IsCopy, IsCopy) |
2868 | 211..234 '(IsCop...test()': bool | 2643 | 179..202 '(IsCop...test()': bool |
2869 | 212..218 'IsCopy': IsCopy | 2644 | 180..186 'IsCopy': IsCopy |
2870 | 220..226 'IsCopy': IsCopy | 2645 | 188..194 'IsCopy': IsCopy |
2871 | 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy) | 2646 | 208..225 '(IsCop...tCopy)': (IsCopy, NotCopy) |
2872 | 240..264 '(IsCop...test()': {unknown} | 2647 | 208..232 '(IsCop...test()': {unknown} |
2873 | 241..247 'IsCopy': IsCopy | 2648 | 209..215 'IsCopy': IsCopy |
2874 | 249..256 'NotCopy': NotCopy | 2649 | 217..224 'NotCopy': NotCopy |
2875 | "#]], | 2650 | "#]], |
2876 | ); | 2651 | ); |
2877 | } | 2652 | } |
@@ -2880,9 +2655,7 @@ fn test() { | |||
2880 | fn builtin_fn_def_copy() { | 2655 | fn builtin_fn_def_copy() { |
2881 | check_infer_with_mismatches( | 2656 | check_infer_with_mismatches( |
2882 | r#" | 2657 | r#" |
2883 | #[lang = "copy"] | 2658 | //- minicore: copy |
2884 | trait Copy {} | ||
2885 | |||
2886 | fn foo() {} | 2659 | fn foo() {} |
2887 | fn bar<T: Copy>(T) -> T {} | 2660 | fn bar<T: Copy>(T) -> T {} |
2888 | struct Struct(usize); | 2661 | struct Struct(usize); |
@@ -2898,20 +2671,20 @@ fn test() { | |||
2898 | Enum::Variant.test(); | 2671 | Enum::Variant.test(); |
2899 | }"#, | 2672 | }"#, |
2900 | expect![[r#" | 2673 | expect![[r#" |
2901 | 41..43 '{}': () | 2674 | 9..11 '{}': () |
2902 | 60..61 'T': {unknown} | 2675 | 28..29 'T': {unknown} |
2903 | 68..70 '{}': () | 2676 | 36..38 '{}': () |
2904 | 68..70: expected T, got () | 2677 | 36..38: expected T, got () |
2905 | 145..149 'self': &Self | 2678 | 113..117 'self': &Self |
2906 | 201..281 '{ ...t(); }': () | 2679 | 169..249 '{ ...t(); }': () |
2907 | 207..210 'foo': fn foo() | 2680 | 175..178 'foo': fn foo() |
2908 | 207..217 'foo.test()': bool | 2681 | 175..185 'foo.test()': bool |
2909 | 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown} | 2682 | 191..194 'bar': fn bar<{unknown}>({unknown}) -> {unknown} |
2910 | 223..233 'bar.test()': bool | 2683 | 191..201 'bar.test()': bool |
2911 | 239..245 'Struct': Struct(usize) -> Struct | 2684 | 207..213 'Struct': Struct(usize) -> Struct |
2912 | 239..252 'Struct.test()': bool | 2685 | 207..220 'Struct.test()': bool |
2913 | 258..271 'Enum::Variant': Variant(usize) -> Enum | 2686 | 226..239 'Enum::Variant': Variant(usize) -> Enum |
2914 | 258..278 'Enum::...test()': bool | 2687 | 226..246 'Enum::...test()': bool |
2915 | "#]], | 2688 | "#]], |
2916 | ); | 2689 | ); |
2917 | } | 2690 | } |
@@ -2920,9 +2693,7 @@ fn test() { | |||
2920 | fn builtin_fn_ptr_copy() { | 2693 | fn builtin_fn_ptr_copy() { |
2921 | check_infer_with_mismatches( | 2694 | check_infer_with_mismatches( |
2922 | r#" | 2695 | r#" |
2923 | #[lang = "copy"] | 2696 | //- minicore: copy |
2924 | trait Copy {} | ||
2925 | |||
2926 | trait Test { fn test(&self) -> bool; } | 2697 | trait Test { fn test(&self) -> bool; } |
2927 | impl<T: Copy> Test for T {} | 2698 | impl<T: Copy> Test for T {} |
2928 | 2699 | ||
@@ -2932,17 +2703,17 @@ fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) { | |||
2932 | f3.test(); | 2703 | f3.test(); |
2933 | }"#, | 2704 | }"#, |
2934 | expect![[r#" | 2705 | expect![[r#" |
2935 | 54..58 'self': &Self | 2706 | 22..26 'self': &Self |
2936 | 108..110 'f1': fn() | 2707 | 76..78 'f1': fn() |
2937 | 118..120 'f2': fn(usize) -> u8 | 2708 | 86..88 'f2': fn(usize) -> u8 |
2938 | 139..141 'f3': fn(u8, u8) -> &u8 | 2709 | 107..109 'f3': fn(u8, u8) -> &u8 |
2939 | 162..210 '{ ...t(); }': () | 2710 | 130..178 '{ ...t(); }': () |
2940 | 168..170 'f1': fn() | 2711 | 136..138 'f1': fn() |
2941 | 168..177 'f1.test()': bool | 2712 | 136..145 'f1.test()': bool |
2942 | 183..185 'f2': fn(usize) -> u8 | 2713 | 151..153 'f2': fn(usize) -> u8 |
2943 | 183..192 'f2.test()': bool | 2714 | 151..160 'f2.test()': bool |
2944 | 198..200 'f3': fn(u8, u8) -> &u8 | 2715 | 166..168 'f3': fn(u8, u8) -> &u8 |
2945 | 198..207 'f3.test()': bool | 2716 | 166..175 'f3.test()': bool |
2946 | "#]], | 2717 | "#]], |
2947 | ); | 2718 | ); |
2948 | } | 2719 | } |
@@ -2951,9 +2722,7 @@ fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) { | |||
2951 | fn builtin_sized() { | 2722 | fn builtin_sized() { |
2952 | check_infer_with_mismatches( | 2723 | check_infer_with_mismatches( |
2953 | r#" | 2724 | r#" |
2954 | #[lang = "sized"] | 2725 | //- minicore: sized |
2955 | trait Sized {} | ||
2956 | |||
2957 | trait Test { fn test(&self) -> bool; } | 2726 | trait Test { fn test(&self) -> bool; } |
2958 | impl<T: Sized> Test for T {} | 2727 | impl<T: Sized> Test for T {} |
2959 | 2728 | ||
@@ -2964,22 +2733,22 @@ fn test() { | |||
2964 | (1u8, *"foo").test(); // not Sized | 2733 | (1u8, *"foo").test(); // not Sized |
2965 | }"#, | 2734 | }"#, |
2966 | expect![[r#" | 2735 | expect![[r#" |
2967 | 56..60 'self': &Self | 2736 | 22..26 'self': &Self |
2968 | 113..228 '{ ...ized }': () | 2737 | 79..194 '{ ...ized }': () |
2969 | 119..122 '1u8': u8 | 2738 | 85..88 '1u8': u8 |
2970 | 119..129 '1u8.test()': bool | 2739 | 85..95 '1u8.test()': bool |
2971 | 135..150 '(*"foo").test()': {unknown} | 2740 | 101..116 '(*"foo").test()': {unknown} |
2972 | 136..142 '*"foo"': str | 2741 | 102..108 '*"foo"': str |
2973 | 137..142 '"foo"': &str | 2742 | 103..108 '"foo"': &str |
2974 | 169..179 '(1u8, 1u8)': (u8, u8) | 2743 | 135..145 '(1u8, 1u8)': (u8, u8) |
2975 | 169..186 '(1u8, ...test()': bool | 2744 | 135..152 '(1u8, ...test()': bool |
2976 | 170..173 '1u8': u8 | 2745 | 136..139 '1u8': u8 |
2977 | 175..178 '1u8': u8 | 2746 | 141..144 '1u8': u8 |
2978 | 192..205 '(1u8, *"foo")': (u8, str) | 2747 | 158..171 '(1u8, *"foo")': (u8, str) |
2979 | 192..212 '(1u8, ...test()': {unknown} | 2748 | 158..178 '(1u8, ...test()': {unknown} |
2980 | 193..196 '1u8': u8 | 2749 | 159..162 '1u8': u8 |
2981 | 198..204 '*"foo"': str | 2750 | 164..170 '*"foo"': str |
2982 | 199..204 '"foo"': &str | 2751 | 165..170 '"foo"': &str |
2983 | "#]], | 2752 | "#]], |
2984 | ); | 2753 | ); |
2985 | } | 2754 | } |
@@ -3064,45 +2833,23 @@ fn foo() { | |||
3064 | fn infer_fn_trait_arg() { | 2833 | fn infer_fn_trait_arg() { |
3065 | check_infer_with_mismatches( | 2834 | check_infer_with_mismatches( |
3066 | r#" | 2835 | r#" |
3067 | //- /lib.rs deps:std | 2836 | //- minicore: fn, option |
3068 | 2837 | fn foo<F, T>(f: F) -> T | |
3069 | #[lang = "fn_once"] | 2838 | where |
3070 | pub trait FnOnce<Args> { | 2839 | F: Fn(Option<i32>) -> T, |
3071 | type Output; | 2840 | { |
3072 | 2841 | let s = None; | |
3073 | extern "rust-call" fn call_once(&self, args: Args) -> Self::Output; | 2842 | f(s) |
3074 | } | 2843 | } |
3075 | 2844 | "#, | |
3076 | #[lang = "fn"] | ||
3077 | pub trait Fn<Args>:FnOnce<Args> { | ||
3078 | extern "rust-call" fn call(&self, args: Args) -> Self::Output; | ||
3079 | } | ||
3080 | |||
3081 | enum Option<T> { | ||
3082 | None, | ||
3083 | Some(T) | ||
3084 | } | ||
3085 | |||
3086 | fn foo<F, T>(f: F) -> T | ||
3087 | where | ||
3088 | F: Fn(Option<i32>) -> T, | ||
3089 | { | ||
3090 | let s = None; | ||
3091 | f(s) | ||
3092 | } | ||
3093 | "#, | ||
3094 | expect![[r#" | 2845 | expect![[r#" |
3095 | 101..105 'self': &Self | 2846 | 13..14 'f': F |
3096 | 107..111 'args': Args | 2847 | 59..89 '{ ...f(s) }': T |
3097 | 220..224 'self': &Self | 2848 | 69..70 's': Option<i32> |
3098 | 226..230 'args': Args | 2849 | 73..77 'None': Option<i32> |
3099 | 313..314 'f': F | 2850 | 83..84 'f': F |
3100 | 359..389 '{ ...f(s) }': T | 2851 | 83..87 'f(s)': T |
3101 | 369..370 's': Option<i32> | 2852 | 85..86 's': Option<i32> |
3102 | 373..377 'None': Option<i32> | ||
3103 | 383..384 'f': F | ||
3104 | 383..387 'f(s)': T | ||
3105 | 385..386 's': Option<i32> | ||
3106 | "#]], | 2853 | "#]], |
3107 | ); | 2854 | ); |
3108 | } | 2855 | } |
@@ -3112,28 +2859,13 @@ fn infer_box_fn_arg() { | |||
3112 | // The type mismatch is because we don't define Unsize and CoerceUnsized | 2859 | // The type mismatch is because we don't define Unsize and CoerceUnsized |
3113 | check_infer_with_mismatches( | 2860 | check_infer_with_mismatches( |
3114 | r#" | 2861 | r#" |
3115 | //- /lib.rs deps:std | 2862 | //- minicore: fn, deref, option |
3116 | |||
3117 | #[lang = "fn_once"] | ||
3118 | pub trait FnOnce<Args> { | ||
3119 | type Output; | ||
3120 | |||
3121 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
3122 | } | ||
3123 | |||
3124 | #[lang = "deref"] | ||
3125 | pub trait Deref { | ||
3126 | type Target: ?Sized; | ||
3127 | |||
3128 | fn deref(&self) -> &Self::Target; | ||
3129 | } | ||
3130 | |||
3131 | #[lang = "owned_box"] | 2863 | #[lang = "owned_box"] |
3132 | pub struct Box<T: ?Sized> { | 2864 | pub struct Box<T: ?Sized> { |
3133 | inner: *mut T, | 2865 | inner: *mut T, |
3134 | } | 2866 | } |
3135 | 2867 | ||
3136 | impl<T: ?Sized> Deref for Box<T> { | 2868 | impl<T: ?Sized> core::ops::Deref for Box<T> { |
3137 | type Target = T; | 2869 | type Target = T; |
3138 | 2870 | ||
3139 | fn deref(&self) -> &T { | 2871 | fn deref(&self) -> &T { |
@@ -3141,38 +2873,30 @@ impl<T: ?Sized> Deref for Box<T> { | |||
3141 | } | 2873 | } |
3142 | } | 2874 | } |
3143 | 2875 | ||
3144 | enum Option<T> { | ||
3145 | None, | ||
3146 | Some(T) | ||
3147 | } | ||
3148 | |||
3149 | fn foo() { | 2876 | fn foo() { |
3150 | let s = Option::None; | 2877 | let s = None; |
3151 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); | 2878 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); |
3152 | f(&s); | 2879 | f(&s); |
3153 | }"#, | 2880 | }"#, |
3154 | expect![[r#" | 2881 | expect![[r#" |
3155 | 100..104 'self': Self | 2882 | 154..158 'self': &Box<T> |
3156 | 106..110 'args': Args | 2883 | 166..193 '{ ... }': &T |
3157 | 214..218 'self': &Self | 2884 | 176..187 '&self.inner': &*mut T |
3158 | 384..388 'self': &Box<T> | 2885 | 177..181 'self': &Box<T> |
3159 | 396..423 '{ ... }': &T | 2886 | 177..187 'self.inner': *mut T |
3160 | 406..417 '&self.inner': &*mut T | 2887 | 206..296 '{ ...&s); }': () |
3161 | 407..411 'self': &Box<T> | 2888 | 216..217 's': Option<i32> |
3162 | 407..417 'self.inner': *mut T | 2889 | 220..224 'None': Option<i32> |
3163 | 478..576 '{ ...&s); }': () | 2890 | 234..235 'f': Box<dyn FnOnce(&Option<i32>)> |
3164 | 488..489 's': Option<i32> | 2891 | 269..282 'box (|ps| {})': Box<|{unknown}| -> ()> |
3165 | 492..504 'Option::None': Option<i32> | 2892 | 274..281 '|ps| {}': |{unknown}| -> () |
3166 | 514..515 'f': Box<dyn FnOnce(&Option<i32>)> | 2893 | 275..277 'ps': {unknown} |
3167 | 549..562 'box (|ps| {})': Box<|{unknown}| -> ()> | 2894 | 279..281 '{}': () |
3168 | 554..561 '|ps| {}': |{unknown}| -> () | 2895 | 288..289 'f': Box<dyn FnOnce(&Option<i32>)> |
3169 | 555..557 'ps': {unknown} | 2896 | 288..293 'f(&s)': () |
3170 | 559..561 '{}': () | 2897 | 290..292 '&s': &Option<i32> |
3171 | 568..569 'f': Box<dyn FnOnce(&Option<i32>)> | 2898 | 291..292 's': Option<i32> |
3172 | 568..573 'f(&s)': () | 2899 | 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()> |
3173 | 570..572 '&s': &Option<i32> | ||
3174 | 571..572 's': Option<i32> | ||
3175 | 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()> | ||
3176 | "#]], | 2900 | "#]], |
3177 | ); | 2901 | ); |
3178 | } | 2902 | } |
@@ -3181,17 +2905,7 @@ fn foo() { | |||
3181 | fn infer_dyn_fn_output() { | 2905 | fn infer_dyn_fn_output() { |
3182 | check_types( | 2906 | check_types( |
3183 | r#" | 2907 | r#" |
3184 | #[lang = "fn_once"] | 2908 | //- minicore: fn |
3185 | pub trait FnOnce<Args> { | ||
3186 | type Output; | ||
3187 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
3188 | } | ||
3189 | |||
3190 | #[lang = "fn"] | ||
3191 | pub trait Fn<Args>: FnOnce<Args> { | ||
3192 | extern "rust-call" fn call(&self, args: Args) -> Self::Output; | ||
3193 | } | ||
3194 | |||
3195 | fn foo() { | 2909 | fn foo() { |
3196 | let f: &dyn Fn() -> i32; | 2910 | let f: &dyn Fn() -> i32; |
3197 | f(); | 2911 | f(); |
@@ -3204,12 +2918,7 @@ fn foo() { | |||
3204 | fn infer_dyn_fn_once_output() { | 2918 | fn infer_dyn_fn_once_output() { |
3205 | check_types( | 2919 | check_types( |
3206 | r#" | 2920 | r#" |
3207 | #[lang = "fn_once"] | 2921 | //- minicore: fn |
3208 | pub trait FnOnce<Args> { | ||
3209 | type Output; | ||
3210 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
3211 | } | ||
3212 | |||
3213 | fn foo() { | 2922 | fn foo() { |
3214 | let f: dyn FnOnce() -> i32; | 2923 | let f: dyn FnOnce() -> i32; |
3215 | f(); | 2924 | f(); |
@@ -3230,7 +2939,7 @@ fn test() { | |||
3230 | S.get(1); | 2939 | S.get(1); |
3231 | //^^^^^^^^ u128 | 2940 | //^^^^^^^^ u128 |
3232 | S.get(1.); | 2941 | S.get(1.); |
3233 | //^^^^^^^^ f32 | 2942 | //^^^^^^^^^ f32 |
3234 | } | 2943 | } |
3235 | "#, | 2944 | "#, |
3236 | ); | 2945 | ); |
@@ -3644,20 +3353,16 @@ fn main() { | |||
3644 | fn fn_returning_unit() { | 3353 | fn fn_returning_unit() { |
3645 | check_infer_with_mismatches( | 3354 | check_infer_with_mismatches( |
3646 | r#" | 3355 | r#" |
3647 | #[lang = "fn_once"] | 3356 | //- minicore: fn |
3648 | trait FnOnce<Args> { | ||
3649 | type Output; | ||
3650 | } | ||
3651 | |||
3652 | fn test<F: FnOnce()>(f: F) { | 3357 | fn test<F: FnOnce()>(f: F) { |
3653 | let _: () = f(); | 3358 | let _: () = f(); |
3654 | }"#, | 3359 | }"#, |
3655 | expect![[r#" | 3360 | expect![[r#" |
3656 | 82..83 'f': F | 3361 | 21..22 'f': F |
3657 | 88..112 '{ ...f(); }': () | 3362 | 27..51 '{ ...f(); }': () |
3658 | 98..99 '_': () | 3363 | 37..38 '_': () |
3659 | 106..107 'f': F | 3364 | 45..46 'f': F |
3660 | 106..109 'f()': () | 3365 | 45..48 'f()': () |
3661 | "#]], | 3366 | "#]], |
3662 | ); | 3367 | ); |
3663 | } | 3368 | } |
@@ -3696,16 +3401,7 @@ impl foo::Foo for u32 { | |||
3696 | fn infer_async_ret_type() { | 3401 | fn infer_async_ret_type() { |
3697 | check_types( | 3402 | check_types( |
3698 | r#" | 3403 | r#" |
3699 | //- /main.rs crate:main deps:core | 3404 | //- minicore: future, result |
3700 | |||
3701 | enum Result<T, E> { | ||
3702 | Ok(T), | ||
3703 | Err(E), | ||
3704 | } | ||
3705 | |||
3706 | use Result::*; | ||
3707 | |||
3708 | |||
3709 | struct Fooey; | 3405 | struct Fooey; |
3710 | 3406 | ||
3711 | impl Fooey { | 3407 | impl Fooey { |
@@ -3718,31 +3414,21 @@ trait Convert { | |||
3718 | fn new() -> Self; | 3414 | fn new() -> Self; |
3719 | } | 3415 | } |
3720 | impl Convert for u32 { | 3416 | impl Convert for u32 { |
3721 | fn new() -> Self { | 3417 | fn new() -> Self { 0 } |
3722 | 0 | ||
3723 | } | ||
3724 | } | 3418 | } |
3725 | 3419 | ||
3726 | async fn get_accounts() -> Result<u32, ()> { | 3420 | async fn get_accounts() -> Result<u32, ()> { |
3727 | let ret = Fooey.collect(); | 3421 | let ret = Fooey.collect(); |
3728 | // ^ u32 | 3422 | // ^^^^^^^^^^^^^^^ u32 |
3729 | Ok(ret) | 3423 | Ok(ret) |
3730 | } | 3424 | } |
3731 | |||
3732 | //- /core.rs crate:core | ||
3733 | #[prelude_import] use future::*; | ||
3734 | mod future { | ||
3735 | #[lang = "future_trait"] | ||
3736 | trait Future { | ||
3737 | type Output; | ||
3738 | } | ||
3739 | } | ||
3740 | "#, | 3425 | "#, |
3741 | ); | 3426 | ); |
3742 | } | 3427 | } |
3743 | 3428 | ||
3744 | #[test] | 3429 | #[test] |
3745 | fn local_impl_1() { | 3430 | fn local_impl_1() { |
3431 | check!(block_local_impls); | ||
3746 | check_types( | 3432 | check_types( |
3747 | r#" | 3433 | r#" |
3748 | trait Trait<T> { | 3434 | trait Trait<T> { |
@@ -3752,7 +3438,7 @@ trait Trait<T> { | |||
3752 | fn test() { | 3438 | fn test() { |
3753 | struct S; | 3439 | struct S; |
3754 | impl Trait<u32> for S { | 3440 | impl Trait<u32> for S { |
3755 | fn foo(&self) { 0 } | 3441 | fn foo(&self) -> u32 { 0 } |
3756 | } | 3442 | } |
3757 | 3443 | ||
3758 | S.foo(); | 3444 | S.foo(); |
@@ -3764,6 +3450,7 @@ fn test() { | |||
3764 | 3450 | ||
3765 | #[test] | 3451 | #[test] |
3766 | fn local_impl_2() { | 3452 | fn local_impl_2() { |
3453 | check!(block_local_impls); | ||
3767 | check_types( | 3454 | check_types( |
3768 | r#" | 3455 | r#" |
3769 | struct S; | 3456 | struct S; |
@@ -3773,7 +3460,7 @@ fn test() { | |||
3773 | fn foo(&self) -> T; | 3460 | fn foo(&self) -> T; |
3774 | } | 3461 | } |
3775 | impl Trait<u32> for S { | 3462 | impl Trait<u32> for S { |
3776 | fn foo(&self) { 0 } | 3463 | fn foo(&self) -> u32 { 0 } |
3777 | } | 3464 | } |
3778 | 3465 | ||
3779 | S.foo(); | 3466 | S.foo(); |
@@ -3785,6 +3472,7 @@ fn test() { | |||
3785 | 3472 | ||
3786 | #[test] | 3473 | #[test] |
3787 | fn local_impl_3() { | 3474 | fn local_impl_3() { |
3475 | check!(block_local_impls); | ||
3788 | check_types( | 3476 | check_types( |
3789 | r#" | 3477 | r#" |
3790 | trait Trait<T> { | 3478 | trait Trait<T> { |
@@ -3797,7 +3485,7 @@ fn test() { | |||
3797 | struct S2; | 3485 | struct S2; |
3798 | 3486 | ||
3799 | impl Trait<S1> for S2 { | 3487 | impl Trait<S1> for S2 { |
3800 | fn foo(&self) { S1 } | 3488 | fn foo(&self) -> S1 { S1 } |
3801 | } | 3489 | } |
3802 | 3490 | ||
3803 | S2.foo(); | 3491 | S2.foo(); |