]> git.lizzy.rs Git - rust.git/blob - crates/hir_ty/src/tests/regression.rs
Add test for #8686
[rust.git] / crates / hir_ty / src / tests / regression.rs
1 use expect_test::expect;
2
3 use super::{check_infer, check_types};
4
5 #[test]
6 fn bug_484() {
7     check_infer(
8         r#"
9         fn test() {
10             let x = if true {};
11         }
12         "#,
13         expect![[r#"
14             10..37 '{     ... {}; }': ()
15             20..21 'x': ()
16             24..34 'if true {}': ()
17             27..31 'true': bool
18             32..34 '{}': ()
19         "#]],
20     );
21 }
22
23 #[test]
24 fn no_panic_on_field_of_enum() {
25     check_infer(
26         r#"
27         enum X {}
28
29         fn test(x: X) {
30             x.some_field;
31         }
32         "#,
33         expect![[r#"
34             19..20 'x': X
35             25..46 '{     ...eld; }': ()
36             31..32 'x': X
37             31..43 'x.some_field': {unknown}
38         "#]],
39     );
40 }
41
42 #[test]
43 fn bug_585() {
44     check_infer(
45         r#"
46         fn test() {
47             X {};
48             match x {
49                 A::B {} => (),
50                 A::Y() => (),
51             }
52         }
53         "#,
54         expect![[r#"
55             10..88 '{     ...   } }': ()
56             16..20 'X {}': {unknown}
57             26..86 'match ...     }': ()
58             32..33 'x': {unknown}
59             44..51 'A::B {}': {unknown}
60             55..57 '()': ()
61             67..73 'A::Y()': {unknown}
62             77..79 '()': ()
63         "#]],
64     );
65 }
66
67 #[test]
68 fn bug_651() {
69     check_infer(
70         r#"
71         fn quux() {
72             let y = 92;
73             1 + y;
74         }
75         "#,
76         expect![[r#"
77             10..40 '{     ...+ y; }': ()
78             20..21 'y': i32
79             24..26 '92': i32
80             32..33 '1': i32
81             32..37 '1 + y': i32
82             36..37 'y': i32
83         "#]],
84     );
85 }
86
87 #[test]
88 fn recursive_vars() {
89     cov_mark::check!(type_var_cycles_resolve_completely);
90     cov_mark::check!(type_var_cycles_resolve_as_possible);
91     check_infer(
92         r#"
93         fn test() {
94             let y = unknown;
95             [y, &y];
96         }
97         "#,
98         expect![[r#"
99             10..47 '{     ...&y]; }': ()
100             20..21 'y': &{unknown}
101             24..31 'unknown': &{unknown}
102             37..44 '[y, &y]': [&&{unknown}; _]
103             38..39 'y': &{unknown}
104             41..43 '&y': &&{unknown}
105             42..43 'y': &{unknown}
106         "#]],
107     );
108 }
109
110 #[test]
111 fn recursive_vars_2() {
112     check_infer(
113         r#"
114         fn test() {
115             let x = unknown;
116             let y = unknown;
117             [(x, y), (&y, &x)];
118         }
119         "#,
120         expect![[r#"
121             10..79 '{     ...x)]; }': ()
122             20..21 'x': &&{unknown}
123             24..31 'unknown': &&{unknown}
124             41..42 'y': &&{unknown}
125             45..52 'unknown': &&{unknown}
126             58..76 '[(x, y..., &x)]': [(&&&{unknown}, &&&{unknown}); _]
127             59..65 '(x, y)': (&&&{unknown}, &&&{unknown})
128             60..61 'x': &&{unknown}
129             63..64 'y': &&{unknown}
130             67..75 '(&y, &x)': (&&&{unknown}, &&&{unknown})
131             68..70 '&y': &&&{unknown}
132             69..70 'y': &&{unknown}
133             72..74 '&x': &&&{unknown}
134             73..74 'x': &&{unknown}
135         "#]],
136     );
137 }
138
139 #[test]
140 fn infer_std_crash_1() {
141     // caused stack overflow, taken from std
142     check_infer(
143         r#"
144         enum Maybe<T> {
145             Real(T),
146             Fake,
147         }
148
149         fn write() {
150             match something_unknown {
151                 Maybe::Real(ref mut something) => (),
152             }
153         }
154         "#,
155         expect![[r#"
156             53..138 '{     ...   } }': ()
157             59..136 'match ...     }': ()
158             65..82 'someth...nknown': Maybe<{unknown}>
159             93..123 'Maybe:...thing)': Maybe<{unknown}>
160             105..122 'ref mu...ething': &mut {unknown}
161             127..129 '()': ()
162         "#]],
163     );
164 }
165
166 #[test]
167 fn infer_std_crash_2() {
168     cov_mark::check!(type_var_resolves_to_int_var);
169     // caused "equating two type variables, ...", taken from std
170     check_infer(
171         r#"
172         fn test_line_buffer() {
173             &[0, b'\n', 1, b'\n'];
174         }
175         "#,
176         expect![[r#"
177             22..52 '{     ...n']; }': ()
178             28..49 '&[0, b...b'\n']': &[u8; _]
179             29..49 '[0, b'...b'\n']': [u8; _]
180             30..31 '0': u8
181             33..38 'b'\n'': u8
182             40..41 '1': u8
183             43..48 'b'\n'': u8
184         "#]],
185     );
186 }
187
188 #[test]
189 fn infer_std_crash_3() {
190     // taken from rustc
191     check_infer(
192         r#"
193         pub fn compute() {
194             match nope!() {
195                 SizeSkeleton::Pointer { non_zero: true, tail } => {}
196             }
197         }
198         "#,
199         expect![[r#"
200             17..107 '{     ...   } }': ()
201             23..105 'match ...     }': ()
202             29..36 'nope!()': {unknown}
203             47..93 'SizeSk...tail }': {unknown}
204             81..85 'true': bool
205             81..85 'true': bool
206             87..91 'tail': {unknown}
207             97..99 '{}': ()
208         "#]],
209     );
210 }
211
212 #[test]
213 fn infer_std_crash_4() {
214     // taken from rustc
215     check_infer(
216         r#"
217         pub fn primitive_type() {
218             match *self {
219                 BorrowedRef { type_: Primitive(p), ..} => {},
220             }
221         }
222         "#,
223         expect![[r#"
224             24..105 '{     ...   } }': ()
225             30..103 'match ...     }': ()
226             36..41 '*self': {unknown}
227             37..41 'self': {unknown}
228             52..90 'Borrow...), ..}': {unknown}
229             73..85 'Primitive(p)': {unknown}
230             83..84 'p': {unknown}
231             94..96 '{}': ()
232         "#]],
233     );
234 }
235
236 #[test]
237 fn infer_std_crash_5() {
238     // taken from rustc
239     check_infer(
240         r#"
241         fn extra_compiler_flags() {
242             for content in doesnt_matter {
243                 let name = if doesnt_matter {
244                     first
245                 } else {
246                     &content
247                 };
248
249                 let content = if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&name) {
250                     name
251                 } else {
252                     content
253                 };
254             }
255         }
256         "#,
257         expect![[r#"
258             26..322 '{     ...   } }': ()
259             32..320 'for co...     }': ()
260             36..43 'content': &{unknown}
261             47..60 'doesnt_matter': {unknown}
262             61..320 '{     ...     }': ()
263             75..79 'name': &&{unknown}
264             82..166 'if doe...     }': &&{unknown}
265             85..98 'doesnt_matter': bool
266             99..128 '{     ...     }': &&{unknown}
267             113..118 'first': &&{unknown}
268             134..166 '{     ...     }': &&{unknown}
269             148..156 '&content': &&{unknown}
270             149..156 'content': &{unknown}
271             181..188 'content': &{unknown}
272             191..313 'if ICE...     }': &{unknown}
273             194..231 'ICE_RE..._VALUE': {unknown}
274             194..247 'ICE_RE...&name)': bool
275             241..246 '&name': &&&{unknown}
276             242..246 'name': &&{unknown}
277             248..276 '{     ...     }': &&{unknown}
278             262..266 'name': &&{unknown}
279             282..313 '{     ...     }': &{unknown}
280             296..303 'content': &{unknown}
281         "#]],
282     );
283 }
284
285 #[test]
286 fn infer_nested_generics_crash() {
287     // another crash found typechecking rustc
288     check_infer(
289         r#"
290         struct Canonical<V> {
291             value: V,
292         }
293         struct QueryResponse<V> {
294             value: V,
295         }
296         fn test<R>(query_response: Canonical<QueryResponse<R>>) {
297             &query_response.value;
298         }
299         "#,
300         expect![[r#"
301             91..105 'query_response': Canonical<QueryResponse<R>>
302             136..166 '{     ...lue; }': ()
303             142..163 '&query....value': &QueryResponse<R>
304             143..157 'query_response': Canonical<QueryResponse<R>>
305             143..163 'query_....value': QueryResponse<R>
306         "#]],
307     );
308 }
309
310 #[test]
311 fn infer_paren_macro_call() {
312     check_infer(
313         r#"
314         macro_rules! bar { () => {0u32} }
315         fn test() {
316             let a = (bar!());
317         }
318         "#,
319         expect![[r#"
320             !0..4 '0u32': u32
321             44..69 '{     ...()); }': ()
322             54..55 'a': u32
323         "#]],
324     );
325 }
326
327 #[test]
328 fn infer_array_macro_call() {
329     check_infer(
330         r#"
331         macro_rules! bar { () => {0u32} }
332         fn test() {
333             let a = [bar!()];
334         }
335         "#,
336         expect![[r#"
337             !0..4 '0u32': u32
338             44..69 '{     ...()]; }': ()
339             54..55 'a': [u32; _]
340             58..66 '[bar!()]': [u32; _]
341         "#]],
342     );
343 }
344
345 #[test]
346 fn bug_1030() {
347     check_infer(
348         r#"
349         struct HashSet<T, H>;
350         struct FxHasher;
351         type FxHashSet<T> = HashSet<T, FxHasher>;
352
353         impl<T, H> HashSet<T, H> {
354             fn default() -> HashSet<T, H> {}
355         }
356
357         pub fn main_loop() {
358             FxHashSet::default();
359         }
360         "#,
361         expect![[r#"
362             143..145 '{}': ()
363             168..197 '{     ...t(); }': ()
364             174..192 'FxHash...efault': fn default<{unknown}, FxHasher>() -> HashSet<{unknown}, FxHasher>
365             174..194 'FxHash...ault()': HashSet<{unknown}, FxHasher>
366         "#]],
367     );
368 }
369
370 #[test]
371 fn issue_2669() {
372     check_infer(
373         r#"
374         trait A {}
375         trait Write {}
376         struct Response<T> {}
377
378         trait D {
379             fn foo();
380         }
381
382         impl<T:A> D for Response<T> {
383             fn foo() {
384                 end();
385                 fn end<W: Write>() {
386                     let _x: T =  loop {};
387                 }
388             }
389         }
390         "#,
391         expect![[r#"
392             119..214 '{     ...     }': ()
393             129..132 'end': fn end<{unknown}>()
394             129..134 'end()': ()
395             163..208 '{     ...     }': ()
396             181..183 '_x': !
397             190..197 'loop {}': !
398             195..197 '{}': ()
399         "#]],
400     )
401 }
402
403 #[test]
404 fn issue_2705() {
405     check_infer(
406         r#"
407         trait Trait {}
408         fn test() {
409             <Trait<u32>>::foo()
410         }
411         "#,
412         expect![[r#"
413             25..52 '{     ...oo() }': ()
414             31..48 '<Trait...>::foo': {unknown}
415             31..50 '<Trait...:foo()': ()
416         "#]],
417     );
418 }
419
420 #[test]
421 fn issue_2683_chars_impl() {
422     check_types(
423         r#"
424 //- /main.rs crate:main deps:std
425 fn test() {
426     let chars: std::str::Chars<'_>;
427     (chars.next(), chars.nth(1));
428 } //^ (Option<char>, Option<char>)
429
430 //- /std.rs crate:std
431 #[prelude_import]
432 use prelude::*;
433
434 pub mod prelude {
435     pub use crate::iter::Iterator;
436     pub use crate::option::Option;
437 }
438
439 pub mod iter {
440     pub use self::traits::Iterator;
441     pub mod traits {
442         pub use self::iterator::Iterator;
443
444         pub mod iterator {
445             pub trait Iterator {
446                 type Item;
447                 fn next(&mut self) -> Option<Self::Item>;
448                 fn nth(&mut self, n: usize) -> Option<Self::Item> {}
449             }
450         }
451     }
452 }
453
454 pub mod option {
455     pub enum Option<T> {}
456 }
457
458 pub mod str {
459     pub struct Chars<'a> {}
460     impl<'a> Iterator for Chars<'a> {
461         type Item = char;
462         fn next(&mut self) -> Option<char> {}
463     }
464 }
465 "#,
466     );
467 }
468
469 #[test]
470 fn issue_3642_bad_macro_stackover() {
471     check_types(
472         r#"
473 #[macro_export]
474 macro_rules! match_ast {
475     (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
476
477     (match ($node:expr) {
478         $( ast::$ast:ident($it:ident) => $res:expr, )*
479         _ => $catch_all:expr $(,)?
480     }) => {{
481         $( if let Some($it) = ast::$ast::cast($node.clone()) { $res } else )*
482         { $catch_all }
483     }};
484 }
485
486 fn main() {
487     let anchor = match_ast! {
488        //^ ()
489         match parent {
490             as => {},
491             _ => return None
492         }
493     };
494 }"#,
495     );
496 }
497
498 #[test]
499 fn issue_3999_slice() {
500     check_infer(
501         r#"
502         fn foo(params: &[usize]) {
503             match params {
504                 [ps @ .., _] => {}
505             }
506         }
507         "#,
508         expect![[r#"
509             7..13 'params': &[usize]
510             25..80 '{     ...   } }': ()
511             31..78 'match ...     }': ()
512             37..43 'params': &[usize]
513             54..66 '[ps @ .., _]': [usize]
514             55..62 'ps @ ..': &[usize]
515             60..62 '..': [usize]
516             64..65 '_': usize
517             70..72 '{}': ()
518         "#]],
519     );
520 }
521
522 #[test]
523 fn issue_3999_struct() {
524     // rust-analyzer should not panic on seeing this malformed
525     // record pattern.
526     check_infer(
527         r#"
528         struct Bar {
529             a: bool,
530         }
531         fn foo(b: Bar) {
532             match b {
533                 Bar { a: .. } => {},
534             }
535         }
536         "#,
537         expect![[r#"
538             35..36 'b': Bar
539             43..95 '{     ...   } }': ()
540             49..93 'match ...     }': ()
541             55..56 'b': Bar
542             67..80 'Bar { a: .. }': Bar
543             76..78 '..': bool
544             84..86 '{}': ()
545         "#]],
546     );
547 }
548
549 #[test]
550 fn issue_4235_name_conflicts() {
551     check_infer(
552         r#"
553         struct FOO {}
554         static FOO:FOO = FOO {};
555
556         impl FOO {
557             fn foo(&self) {}
558         }
559
560         fn main() {
561             let a = &FOO;
562             a.foo();
563         }
564         "#,
565         expect![[r#"
566             31..37 'FOO {}': FOO
567             63..67 'self': &FOO
568             69..71 '{}': ()
569             85..119 '{     ...o(); }': ()
570             95..96 'a': &FOO
571             99..103 '&FOO': &FOO
572             100..103 'FOO': FOO
573             109..110 'a': &FOO
574             109..116 'a.foo()': ()
575         "#]],
576     );
577 }
578
579 #[test]
580 fn issue_4465_dollar_crate_at_type() {
581     check_infer(
582         r#"
583         pub struct Foo {}
584         pub fn anything<T>() -> T {
585             loop {}
586         }
587         macro_rules! foo {
588             () => {{
589                 let r: $crate::Foo = anything();
590                 r
591             }};
592         }
593         fn main() {
594             let _a = foo!();
595         }
596         "#,
597         expect![[r#"
598             44..59 '{     loop {} }': T
599             50..57 'loop {}': !
600             55..57 '{}': ()
601             !0..31 '{letr:...g();r}': Foo
602             !4..5 'r': Foo
603             !18..26 'anything': fn anything<Foo>() -> Foo
604             !18..28 'anything()': Foo
605             !29..30 'r': Foo
606             163..187 '{     ...!(); }': ()
607             173..175 '_a': Foo
608         "#]],
609     );
610 }
611
612 #[test]
613 fn issue_6811() {
614     check_infer(
615         r#"
616         macro_rules! profile_function {
617             () => {
618                 let _a = 1;
619                 let _b = 1;
620             };
621         }
622         fn main() {
623             profile_function!();
624         }
625         "#,
626         expect![[r#"
627             !3..5 '_a': i32
628             !6..7 '1': i32
629             !11..13 '_b': i32
630             !14..15 '1': i32
631             103..131 '{     ...!(); }': ()
632         "#]],
633     );
634 }
635
636 #[test]
637 fn issue_4053_diesel_where_clauses() {
638     check_infer(
639         r#"
640         trait BoxedDsl<DB> {
641             type Output;
642             fn internal_into_boxed(self) -> Self::Output;
643         }
644
645         struct SelectStatement<From, Select, Distinct, Where, Order, LimitOffset, GroupBy, Locking> {
646             order: Order,
647         }
648
649         trait QueryFragment<DB: Backend> {}
650
651         trait Into<T> { fn into(self) -> T; }
652
653         impl<F, S, D, W, O, LOf, DB> BoxedDsl<DB>
654             for SelectStatement<F, S, D, W, O, LOf, G>
655         where
656             O: Into<dyn QueryFragment<DB>>,
657         {
658             type Output = XXX;
659
660             fn internal_into_boxed(self) -> Self::Output {
661                 self.order.into();
662             }
663         }
664         "#,
665         expect![[r#"
666             65..69 'self': Self
667             267..271 'self': Self
668             466..470 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
669             488..522 '{     ...     }': ()
670             498..502 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
671             498..508 'self.order': O
672             498..515 'self.o...into()': dyn QueryFragment<DB>
673         "#]],
674     );
675 }
676
677 #[test]
678 fn issue_4953() {
679     check_infer(
680         r#"
681         pub struct Foo(pub i64);
682         impl Foo {
683             fn test() -> Self { Self(0i64) }
684         }
685         "#,
686         expect![[r#"
687             58..72 '{ Self(0i64) }': Foo
688             60..64 'Self': Foo(i64) -> Foo
689             60..70 'Self(0i64)': Foo
690             65..69 '0i64': i64
691         "#]],
692     );
693     check_infer(
694         r#"
695         pub struct Foo<T>(pub T);
696         impl Foo<i64> {
697             fn test() -> Self { Self(0i64) }
698         }
699         "#,
700         expect![[r#"
701             64..78 '{ Self(0i64) }': Foo<i64>
702             66..70 'Self': Foo<i64>(i64) -> Foo<i64>
703             66..76 'Self(0i64)': Foo<i64>
704             71..75 '0i64': i64
705         "#]],
706     );
707 }
708
709 #[test]
710 fn issue_4931() {
711     check_infer(
712         r#"
713         trait Div<T> {
714             type Output;
715         }
716
717         trait CheckedDiv: Div<()> {}
718
719         trait PrimInt: CheckedDiv<Output = ()> {
720             fn pow(self);
721         }
722
723         fn check<T: PrimInt>(i: T) {
724             i.pow();
725         }
726         "#,
727         expect![[r#"
728             117..121 'self': Self
729             148..149 'i': T
730             154..170 '{     ...w(); }': ()
731             160..161 'i': T
732             160..167 'i.pow()': ()
733         "#]],
734     );
735 }
736
737 #[test]
738 fn issue_4885() {
739     check_infer(
740         r#"
741         #[lang = "coerce_unsized"]
742         pub trait CoerceUnsized<T> {}
743
744         trait Future {
745             type Output;
746         }
747         trait Foo<R> {
748             type Bar;
749         }
750         fn foo<R, K>(key: &K) -> impl Future<Output = K::Bar>
751         where
752             K: Foo<R>,
753         {
754             bar(key)
755         }
756         fn bar<R, K>(key: &K) -> impl Future<Output = K::Bar>
757         where
758             K: Foo<R>,
759         {
760         }
761         "#,
762         expect![[r#"
763             136..139 'key': &K
764             198..214 '{     ...key) }': impl Future<Output = <K as Foo<R>>::Bar>
765             204..207 'bar': fn bar<R, K>(&K) -> impl Future<Output = <K as Foo<R>>::Bar>
766             204..212 'bar(key)': impl Future<Output = <K as Foo<R>>::Bar>
767             208..211 'key': &K
768             228..231 'key': &K
769             290..293 '{ }': ()
770         "#]],
771     );
772 }
773
774 #[test]
775 fn issue_4800() {
776     check_infer(
777         r#"
778         trait Debug {}
779
780         struct Foo<T>;
781
782         type E1<T> = (T, T, T);
783         type E2<T> = E1<E1<E1<(T, T, T)>>>;
784
785         impl Debug for Foo<E2<()>> {}
786
787         struct Request;
788
789         pub trait Future {
790             type Output;
791         }
792
793         pub struct PeerSet<D>;
794
795         impl<D> Service<Request> for PeerSet<D>
796         where
797             D: Discover,
798             D::Key: Debug,
799         {
800             type Error = ();
801             type Future = dyn Future<Output = Self::Error>;
802
803             fn call(&mut self) -> Self::Future {
804                 loop {}
805             }
806         }
807
808         pub trait Discover {
809             type Key;
810         }
811
812         pub trait Service<Request> {
813             type Error;
814             type Future: Future<Output = Self::Error>;
815             fn call(&mut self) -> Self::Future;
816         }
817         "#,
818         expect![[r#"
819             379..383 'self': &mut PeerSet<D>
820             401..424 '{     ...     }': dyn Future<Output = ()>
821             411..418 'loop {}': !
822             416..418 '{}': ()
823             575..579 'self': &mut Self
824         "#]],
825     );
826 }
827
828 #[test]
829 fn issue_4966() {
830     check_infer(
831         r#"
832         pub trait IntoIterator {
833             type Item;
834         }
835
836         struct Repeat<A> { element: A }
837
838         struct Map<F> { f: F }
839
840         struct Vec<T> {}
841
842         #[lang = "deref"]
843         pub trait Deref {
844             type Target;
845         }
846
847         impl<T> Deref for Vec<T> {
848             type Target = [T];
849         }
850
851         fn from_iter<A, T: IntoIterator<Item = A>>(iter: T) -> Vec<A> {}
852
853         fn main() {
854             let inner = Map { f: |_: &f64| 0.0 };
855
856             let repeat = Repeat { element: inner };
857
858             let vec = from_iter(repeat);
859
860             vec.foo_bar();
861         }
862         "#,
863         expect![[r#"
864             270..274 'iter': T
865             289..291 '{}': ()
866             303..447 '{     ...r(); }': ()
867             313..318 'inner': Map<|&f64| -> f64>
868             321..345 'Map { ... 0.0 }': Map<|&f64| -> f64>
869             330..343 '|_: &f64| 0.0': |&f64| -> f64
870             331..332 '_': &f64
871             340..343 '0.0': f64
872             356..362 'repeat': Repeat<Map<|&f64| -> f64>>
873             365..390 'Repeat...nner }': Repeat<Map<|&f64| -> f64>>
874             383..388 'inner': Map<|&f64| -> f64>
875             401..404 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
876             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>>>>
877             407..424 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
878             417..423 'repeat': Repeat<Map<|&f64| -> f64>>
879             431..434 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
880             431..444 'vec.foo_bar()': {unknown}
881         "#]],
882     );
883 }
884
885 #[test]
886 fn issue_6628() {
887     check_infer(
888         r#"
889         #[lang = "fn_once"]
890         pub trait FnOnce<Args> {
891             type Output;
892         }
893
894         struct S<T>();
895         impl<T> S<T> {
896             fn f(&self, _t: T) {}
897             fn g<F: FnOnce(&T)>(&self, _f: F) {}
898         }
899         fn main() {
900             let s = S();
901             s.g(|_x| {});
902             s.f(10);
903         }
904         "#,
905         expect![[r#"
906             105..109 'self': &S<T>
907             111..113 '_t': T
908             118..120 '{}': ()
909             146..150 'self': &S<T>
910             152..154 '_f': F
911             159..161 '{}': ()
912             174..225 '{     ...10); }': ()
913             184..185 's': S<i32>
914             188..189 'S': S<i32>() -> S<i32>
915             188..191 'S()': S<i32>
916             197..198 's': S<i32>
917             197..209 's.g(|_x| {})': ()
918             201..208 '|_x| {}': |&i32| -> ()
919             202..204 '_x': &i32
920             206..208 '{}': ()
921             215..216 's': S<i32>
922             215..222 's.f(10)': ()
923             219..221 '10': i32
924         "#]],
925     );
926 }
927
928 #[test]
929 fn issue_6852() {
930     check_infer(
931         r#"
932         #[lang = "deref"]
933         pub trait Deref {
934             type Target;
935         }
936
937         struct BufWriter {}
938
939         struct Mutex<T> {}
940         struct MutexGuard<'a, T> {}
941         impl<T> Mutex<T> {
942             fn lock(&self) -> MutexGuard<'_, T> {}
943         }
944         impl<'a, T: 'a> Deref for MutexGuard<'a, T> {
945             type Target = T;
946         }
947         fn flush(&self) {
948             let w: &Mutex<BufWriter>;
949             *(w.lock());
950         }
951         "#,
952         expect![[r#"
953             156..160 'self': &Mutex<T>
954             183..185 '{}': ()
955             267..271 'self': &{unknown}
956             273..323 '{     ...()); }': ()
957             283..284 'w': &Mutex<BufWriter>
958             309..320 '*(w.lock())': BufWriter
959             311..312 'w': &Mutex<BufWriter>
960             311..319 'w.lock()': MutexGuard<BufWriter>
961         "#]],
962     );
963 }
964
965 #[test]
966 fn param_overrides_fn() {
967     check_types(
968         r#"
969         fn example(example: i32) {
970             fn f() {}
971             example;
972           //^^^^^^^ i32
973         }
974         "#,
975     )
976 }
977
978 #[test]
979 fn lifetime_from_chalk_during_deref() {
980     check_types(
981         r#"
982         #[lang = "deref"]
983         pub trait Deref {
984             type Target;
985         }
986
987         struct Box<T: ?Sized> {}
988         impl<T> Deref for Box<T> {
989             type Target = T;
990
991             fn deref(&self) -> &Self::Target {
992                 loop {}
993             }
994         }
995
996         trait Iterator {
997             type Item;
998         }
999
1000         pub struct Iter<'a, T: 'a> {
1001             inner: Box<dyn IterTrait<'a, T, Item = &'a T> + 'a>,
1002         }
1003
1004         trait IterTrait<'a, T: 'a>: Iterator<Item = &'a T> {
1005             fn clone_box(&self);
1006         }
1007
1008         fn clone_iter<T>(s: Iter<T>) {
1009             s.inner.clone_box();
1010           //^^^^^^^^^^^^^^^^^^^ ()
1011         }
1012         "#,
1013     )
1014 }
1015
1016 #[test]
1017 fn issue_8686() {
1018     check_infer(
1019         r#"
1020 pub trait Try: FromResidual {
1021     type Output;
1022     type Residual;
1023 }
1024 pub trait FromResidual<R = <Self as Try>::Residual> {
1025      fn from_residual(residual: R) -> Self;
1026 }
1027
1028 struct ControlFlow<B, C>;
1029 impl<B, C> Try for ControlFlow<B, C> {
1030     type Output = C;
1031     type Residual = ControlFlow<B, !>;
1032 }
1033 impl<B, C> FromResidual for ControlFlow<B, C> {
1034     fn from_residual(r: ControlFlow<B, !>) -> Self { ControlFlow }
1035 }
1036
1037 fn test() {
1038     ControlFlow::from_residual(ControlFlow::<u32, !>);
1039 }
1040         "#,
1041         expect![[r#"
1042         "#]],
1043     );
1044 }