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