Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
use expect_test::expect;

use crate::tests::{check_infer, check_no_mismatches, check_types};

#[test]
fn regression_20365() {
    check_infer(
        r#"
//- minicore: iterator
struct Vec<T>(T);
struct IntoIter<T>(T);
impl<T> IntoIterator for Vec<T> {
    type IntoIter = IntoIter<T>;
    type Item = T;
}
impl<T> Iterator for IntoIter<T> {
    type Item = T;
}

fn f<T: Space>(a: Vec<u8>) {
    let iter = a.into_iter();
}

pub trait Space: IntoIterator {
    type Ty: Space;
}
impl Space for [u8; 1] {
    type Ty = Self;
}
    "#,
        expect![[r#"
            201..202 'a': Vec<u8>
            213..246 '{     ...r(); }': ()
            223..227 'iter': IntoIter<u8>
            230..231 'a': Vec<u8>
            230..243 'a.into_iter()': IntoIter<u8>
        "#]],
    );
}

#[test]
fn regression_19971() {
    check_infer(
        r#"
//- minicore: pointee
fn make<T>(_thin: *const (), _meta: core::ptr::DynMetadata<T>) -> *const T
where
    T: core::ptr::Pointee<Metadata = core::ptr::DynMetadata<T>> + ?Sized,
{
    loop {}
}
trait Foo {
    fn foo(&self) -> i32 {
        loop {}
    }
}

fn test() -> i32 {
    struct F {}
    impl Foo for F {}
    let meta = core::ptr::metadata(0 as *const F as *const dyn Foo);

    let f = F {};
    let fat_ptr = make(&f as *const F as *const (), meta); // <-- infers type as `*const {unknown}`

    let fat_ref = unsafe { &*fat_ptr }; // <-- infers type as `&{unknown}`
    fat_ref.foo() // cannot 'go to definition' on `foo`
}

    "#,
        expect![[r#"
            11..16 '_thin': *const ()
            29..34 '_meta': DynMetadata<T>
            155..170 '{     loop {} }': *const T
            161..168 'loop {}': !
            166..168 '{}': ()
            195..199 'self': &'? Self
            208..231 '{     ...     }': i32
            218..225 'loop {}': !
            223..225 '{}': ()
            252..613 '{     ...foo` }': i32
            300..304 'meta': DynMetadata<dyn Foo + '?>
            307..326 'core::...tadata': fn metadata<dyn Foo + '?>(*const (dyn Foo + '?)) -> <dyn Foo + '? as Pointee>::Metadata
            307..359 'core::...n Foo)': DynMetadata<dyn Foo + '?>
            327..328 '0': usize
            327..340 '0 as *const F': *const F
            327..358 '0 as *...yn Foo': *const (dyn Foo + 'static)
            370..371 'f': F
            374..378 'F {}': F
            388..395 'fat_ptr': *const (dyn Foo + '?)
            398..402 'make': fn make<dyn Foo + '?>(*const (), DynMetadata<dyn Foo + '?>) -> *const (dyn Foo + '?)
            398..437 'make(&... meta)': *const (dyn Foo + '?)
            403..405 '&f': &'? F
            403..417 '&f as *const F': *const F
            403..430 '&f as ...nst ()': *const ()
            404..405 'f': F
            432..436 'meta': DynMetadata<dyn Foo + '?>
            489..496 'fat_ref': &'? (dyn Foo + '?)
            499..519 'unsafe..._ptr }': &'? (dyn Foo + '?)
            508..517 '&*fat_ptr': &'? (dyn Foo + '?)
            509..517 '*fat_ptr': dyn Foo + '?
            510..517 'fat_ptr': *const (dyn Foo + '?)
            560..567 'fat_ref': &'? (dyn Foo + '?)
            560..573 'fat_ref.foo()': i32
        "#]],
    );
}

#[test]
fn regression_19752() {
    check_no_mismatches(
        r#"
//- minicore: sized, copy
trait T1<T: T2>: Sized + Copy {
    fn a(self, other: Self) -> Self {
        other
    }

    fn b(&mut self, other: Self) {
        *self = self.a(other);
    }
}

trait T2: Sized {
    type T1: T1<Self>;
}
    "#,
    );
}

#[test]
fn regression_type_checker_does_not_eagerly_select_predicates_from_where_clauses() {
    // This was a very long standing issue (#5514) with a lot of duplicates, that was
    // fixed by the switch to the new trait solver, so it deserves a long name and a
    // honorable mention.
    check_infer(
        r#"
//- minicore: from

struct Foo;
impl Foo {
    fn method(self) -> i32 { 0 }
}

fn f<T: Into<Foo>>(u: T) {
    let x = u.into();
    x.method();
}
    "#,
        expect![[r#"
            38..42 'self': Foo
            51..56 '{ 0 }': i32
            53..54 '0': i32
            79..80 'u': T
            85..126 '{     ...d(); }': ()
            95..96 'x': Foo
            99..100 'u': T
            99..107 'u.into()': Foo
            113..114 'x': Foo
            113..123 'x.method()': i32
        "#]],
    );
}

#[test]
fn opaque_generics() {
    check_infer(
        r#"
//- minicore: iterator
pub struct Grid {}

impl<'a> IntoIterator for &'a Grid {
    type Item = &'a ();

    type IntoIter = impl Iterator<Item = &'a ()>;

    fn into_iter(self) -> Self::IntoIter {
    }
}
    "#,
        expect![[r#"
            150..154 'self': &'a Grid
            174..181 '{     }': <&'a Grid as IntoIterator>::IntoIter
        "#]],
    );
}

#[test]
fn normalization() {
    check_infer(
        r#"
//- minicore: iterator, iterators
fn main() {
    _ = [0i32].into_iter().filter_map(|_n| Some(1i32));
}
    "#,
        expect![[r#"
            10..69 '{     ...2)); }': ()
            16..17 '_': FilterMap<IntoIter<i32, 1>, impl FnMut(i32) -> Option<i32>>
            16..66 '_ = [0...1i32))': ()
            20..26 '[0i32]': [i32; 1]
            20..38 '[0i32]...iter()': IntoIter<i32, 1>
            20..66 '[0i32]...1i32))': FilterMap<IntoIter<i32, 1>, impl FnMut(i32) -> Option<i32>>
            21..25 '0i32': i32
            50..65 '|_n| Some(1i32)': impl FnMut(i32) -> Option<i32>
            51..53 '_n': i32
            55..59 'Some': fn Some<i32>(i32) -> Option<i32>
            55..65 'Some(1i32)': Option<i32>
            60..64 '1i32': i32
        "#]],
    );
}

#[test]
fn regression_20487() {
    check_no_mismatches(
        r#"
//- minicore: coerce_unsized, dispatch_from_dyn
trait Foo {
    fn bar(&self) -> u32 {
        0xCAFE
    }
}

fn debug(_: &dyn Foo) {}

impl Foo for i32 {}

fn main() {
    debug(&1);
}"#,
    );
}

#[test]
fn projection_is_not_associated_type() {
    check_no_mismatches(
        r#"
//- minicore: fn
trait Iterator {
    type Item;

    fn partition<F>(self, f: F)
    where
        F: FnMut(&Self::Item) -> bool,
    {
    }
}

struct Iter;
impl Iterator for Iter {
    type Item = i32;
}

fn main() {
    Iter.partition(|n| true);
}
    "#,
    );
}

#[test]
fn cast_error_type() {
    check_infer(
        r#"
fn main() {
  let foo: [_; _] = [false] as _;
}
    "#,
        expect![[r#"
            10..47 '{   le...s _; }': ()
            18..21 'foo': [bool; 1]
            32..39 '[false]': [bool; 1]
            32..44 '[false] as _': [bool; 1]
            33..38 'false': bool
        "#]],
    );
}

#[test]
fn no_infinite_loop_on_super_predicates_elaboration() {
    check_infer(
        r#"
//- minicore: sized
trait DimMax<Other: Dimension> {
    type Output: Dimension;
}

trait Dimension: DimMax<<Self as Dimension>:: Smaller, Output = Self> {
    type Smaller: Dimension;
}

fn test<T, U>(t: T)
where
    T: DimMax<U>,
    U: Dimension,
{
    let t: <T as DimMax<U>>::Output = loop {};
}
"#,
        expect![[r#"
            182..183 't': T
            230..280 '{     ... {}; }': ()
            240..241 't': <T as DimMax<U>>::Output
            270..277 'loop {}': !
            275..277 '{}': ()
        "#]],
    )
}

#[test]
fn fn_coercion() {
    check_no_mismatches(
        r#"
fn foo() {
    let _is_suffix_start: fn(&(usize, char)) -> bool = match true {
        true => |(_, c)| *c == ' ',
        _ => |(_, c)| *c == 'v',
    };
}
    "#,
    );
}

#[test]
fn coercion_with_errors() {
    check_no_mismatches(
        r#"
//- minicore: unsize, coerce_unsized
fn foo(_v: i32) -> [u8; _] { loop {} }
fn bar(_v: &[u8]) {}

fn main() {
    bar(&foo());
}
    "#,
    );
}

#[test]
fn another_20654_case() {
    check_no_mismatches(
        r#"
//- minicore: sized, unsize, coerce_unsized, dispatch_from_dyn, fn
struct Region<'db>(&'db ());

trait TypeFoldable<I: Interner> {}

trait Interner {
    type Region;
    type GenericArg;
}

struct DbInterner<'db>(&'db ());
impl<'db> Interner for DbInterner<'db> {
    type Region = Region<'db>;
    type GenericArg = GenericArg<'db>;
}

trait GenericArgExt<I: Interner<GenericArg = Self>> {
    fn expect_region(&self) -> I::Region {
        loop {}
    }
}
impl<'db> GenericArgExt<DbInterner<'db>> for GenericArg<'db> {}

enum GenericArg<'db> {
    Region(Region<'db>),
}

fn foo<'db, T: TypeFoldable<DbInterner<'db>>>(arg: GenericArg<'db>) {
    let regions = &mut || arg.expect_region();
    let f: &'_ mut (dyn FnMut() -> Region<'db> + '_) = regions;
}
    "#,
    );
}

#[test]
fn trait_solving_with_error() {
    check_infer(
        r#"
//- minicore: size_of
struct Vec<T>(T);

trait Foo {
    type Item;
    fn to_vec(self) -> Vec<Self::Item> {
        loop {}
    }
}

impl<'a, T, const N: usize> Foo for &'a [T; N] {
    type Item = T;
}

fn to_bytes() -> [u8; _] {
    loop {}
}

fn foo() {
    let _x = to_bytes().to_vec();
}
    "#,
        expect![[r#"
            60..64 'self': Self
            85..108 '{     ...     }': Vec<<Self as Foo>::Item>
            95..102 'loop {}': !
            100..102 '{}': ()
            208..223 '{     loop {} }': [u8; _]
            214..221 'loop {}': !
            219..221 '{}': ()
            234..271 '{     ...c(); }': ()
            244..246 '_x': {unknown}
            249..257 'to_bytes': fn to_bytes() -> [u8; _]
            249..259 'to_bytes()': [u8; _]
            249..268 'to_byt..._vec()': Vec<<[u8; _] as Foo>::Item>
        "#]],
    );
}

#[test]
fn regression_19637() {
    check_no_mismatches(
        r#"
//- minicore: coerce_unsized
pub trait Any {}

impl<T: 'static> Any for T {}

pub trait Trait: Any {
    type F;
}

pub struct TT {}

impl Trait for TT {
    type F = f32;
}

pub fn coercion(x: &mut dyn Any) -> &mut dyn Any {
    x
}

fn main() {
    let mut t = TT {};
    let tt = &mut t as &mut dyn Trait<F = f32>;
    let st = coercion(tt);
}
    "#,
    );
}

#[test]
fn double_into_iter() {
    check_types(
        r#"
//- minicore: iterator

fn intoiter_issue<A, B>(foo: A)
where
    A: IntoIterator<Item = B>,
    B: IntoIterator<Item = usize>,
{
    for x in foo {
    //  ^ B
        for m in x {
        //  ^ usize
        }
    }
}
"#,
    );
}

#[test]
fn regression_16282() {
    check_infer(
        r#"
//- minicore: coerce_unsized, dispatch_from_dyn
trait MapLookup<Q> {
    type MapValue;
}

impl<K> MapLookup<K> for K {
    type MapValue = K;
}

trait Map: MapLookup<<Self as Map>::Key> {
    type Key;
}

impl<K> Map for K {
    type Key = K;
}


fn main() {
    let _ = &()
        as &dyn Map<Key=u32,MapValue=u32>;
}
"#,
        expect![[r#"
            210..272 '{     ...32>; }': ()
            220..221 '_': &'? (dyn Map<MapValue = u32, Key = u32> + '?)
            224..227 '&()': &'? ()
            224..269 '&()   ...e=u32>': &'? (dyn Map<MapValue = u32, Key = u32> + 'static)
            225..227 '()': ()
        "#]],
    );
}

#[test]
fn regression_18692() {
    check_no_mismatches(
        r#"
//- minicore: coerce_unsized, dispatch_from_dyn, send
trait Trait: Send {}

fn f(_: *const (dyn Trait + Send)) {}
fn g(it: *const (dyn Trait)) {
    f(it);
}
"#,
    );
}

#[test]
fn regression_20951() {
    check_infer(
        r#"
//- minicore: async_fn
trait DoesSomething {
    fn do_something(&self) -> impl Future<Output = usize>;
}

impl<F> DoesSomething for F
where
    F: AsyncFn() -> usize,
{
    fn do_something(&self) -> impl Future<Output = usize> {
        self()
    }
}
"#,
        expect![[r#"
            43..47 'self': &'? Self
            168..172 'self': &'? F
            205..227 '{     ...     }': <F as AsyncFnMut<()>>::CallRefFuture<'<erased>>
            215..219 'self': &'? F
            215..221 'self()': <F as AsyncFnMut<()>>::CallRefFuture<'<erased>>
        "#]],
    );
}