aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests/traits.rs')
-rw-r--r--crates/hir_ty/src/tests/traits.rs516
1 files changed, 181 insertions, 335 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index c830e576e..065cca74f 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -6,10 +6,10 @@ use super::{check_infer, check_infer_with_mismatches, check_types};
6fn infer_await() { 6fn infer_await() {
7 check_types( 7 check_types(
8 r#" 8 r#"
9//- /main.rs crate:main deps:core 9//- minicore: future
10struct IntFuture; 10struct IntFuture;
11 11
12impl Future for IntFuture { 12impl core::future::Future for IntFuture {
13 type Output = u64; 13 type Output = u64;
14} 14}
15 15
@@ -18,16 +18,6 @@ fn test() {
18 let v = r.await; 18 let v = r.await;
19 v; 19 v;
20} //^ u64 20} //^ u64
21
22//- /core.rs crate:core
23pub mod prelude {
24 pub mod rust_2018 {
25 #[lang = "future_trait"]
26 pub trait Future {
27 type Output;
28 }
29 }
30}
31"#, 21"#,
32 ); 22 );
33} 23}
@@ -36,25 +26,14 @@ pub mod prelude {
36fn infer_async() { 26fn infer_async() {
37 check_types( 27 check_types(
38 r#" 28 r#"
39//- /main.rs crate:main deps:core 29//- minicore: future
40async fn foo() -> u64 { 30async fn foo() -> u64 { 128 }
41 128
42}
43 31
44fn test() { 32fn test() {
45 let r = foo(); 33 let r = foo();
46 let v = r.await; 34 let v = r.await;
47 v; 35 v;
48} //^ u64 36} //^ u64
49
50//- /core.rs crate:core
51#[prelude_import] use future::*;
52mod future {
53 #[lang = "future_trait"]
54 trait Future {
55 type Output;
56 }
57}
58"#, 37"#,
59 ); 38 );
60} 39}
@@ -63,24 +42,13 @@ mod future {
63fn infer_desugar_async() { 42fn infer_desugar_async() {
64 check_types( 43 check_types(
65 r#" 44 r#"
66//- /main.rs crate:main deps:core 45//- minicore: future
67async fn foo() -> u64 { 46async fn foo() -> u64 { 128 }
68 128
69}
70 47
71fn test() { 48fn test() {
72 let r = foo(); 49 let r = foo();
73 r; 50 r;
74} //^ impl Future<Output = u64> 51} //^ impl Future<Output = u64>
75
76//- /core.rs crate:core
77#[prelude_import] use future::*;
78mod future {
79 trait Future {
80 type Output;
81 }
82}
83
84"#, 52"#,
85 ); 53 );
86} 54}
@@ -89,7 +57,7 @@ mod future {
89fn infer_async_block() { 57fn infer_async_block() {
90 check_types( 58 check_types(
91 r#" 59 r#"
92//- /main.rs crate:main deps:core 60//- minicore: future, option
93async fn test() { 61async fn test() {
94 let a = async { 42 }; 62 let a = async { 42 };
95 a; 63 a;
@@ -101,7 +69,7 @@ async fn test() {
101 b; 69 b;
102// ^ () 70// ^ ()
103 let c = async { 71 let c = async {
104 let y = Option::None; 72 let y = None;
105 y 73 y
106 // ^ Option<u64> 74 // ^ Option<u64>
107 }; 75 };
@@ -109,18 +77,6 @@ async fn test() {
109 c; 77 c;
110// ^ impl Future<Output = Option<u64>> 78// ^ impl Future<Output = Option<u64>>
111} 79}
112
113enum Option<T> { None, Some(T) }
114
115//- /core.rs crate:core
116#[prelude_import] use future::*;
117mod future {
118 #[lang = "future_trait"]
119 trait Future {
120 type Output;
121 }
122}
123
124"#, 80"#,
125 ); 81 );
126} 82}
@@ -704,14 +660,9 @@ mod ops {
704fn deref_trait() { 660fn deref_trait() {
705 check_types( 661 check_types(
706 r#" 662 r#"
707#[lang = "deref"] 663//- minicore: deref
708trait Deref {
709 type Target;
710 fn deref(&self) -> &Self::Target;
711}
712
713struct Arc<T>; 664struct Arc<T>;
714impl<T> Deref for Arc<T> { 665impl<T> core::ops::Deref for Arc<T> {
715 type Target = T; 666 type Target = T;
716} 667}
717 668
@@ -731,16 +682,10 @@ fn test(s: Arc<S>) {
731fn deref_trait_with_inference_var() { 682fn deref_trait_with_inference_var() {
732 check_types( 683 check_types(
733 r#" 684 r#"
734//- /main.rs 685//- minicore: deref
735#[lang = "deref"]
736trait Deref {
737 type Target;
738 fn deref(&self) -> &Self::Target;
739}
740
741struct Arc<T>; 686struct Arc<T>;
742fn new_arc<T>() -> Arc<T> {} 687fn new_arc<T>() -> Arc<T> {}
743impl<T> Deref for Arc<T> { 688impl<T> core::ops::Deref for Arc<T> {
744 type Target = T; 689 type Target = T;
745} 690}
746 691
@@ -761,15 +706,10 @@ fn test() {
761fn deref_trait_infinite_recursion() { 706fn deref_trait_infinite_recursion() {
762 check_types( 707 check_types(
763 r#" 708 r#"
764#[lang = "deref"] 709//- minicore: deref
765trait Deref {
766 type Target;
767 fn deref(&self) -> &Self::Target;
768}
769
770struct S; 710struct S;
771 711
772impl Deref for S { 712impl core::ops::Deref for S {
773 type Target = S; 713 type Target = S;
774} 714}
775 715
@@ -784,14 +724,9 @@ fn test(s: S) {
784fn deref_trait_with_question_mark_size() { 724fn deref_trait_with_question_mark_size() {
785 check_types( 725 check_types(
786 r#" 726 r#"
787#[lang = "deref"] 727//- minicore: deref
788trait Deref {
789 type Target;
790 fn deref(&self) -> &Self::Target;
791}
792
793struct Arc<T>; 728struct Arc<T>;
794impl<T> Deref for Arc<T> { 729impl<T: ?Sized> core::ops::Deref for Arc<T> {
795 type Target = T; 730 type Target = T;
796} 731}
797 732
@@ -1911,11 +1846,7 @@ fn test() {
1911fn closure_1() { 1846fn closure_1() {
1912 check_infer_with_mismatches( 1847 check_infer_with_mismatches(
1913 r#" 1848 r#"
1914#[lang = "fn_once"] 1849//- minicore: fn
1915trait FnOnce<Args> {
1916 type Output;
1917}
1918
1919enum Option<T> { Some(T), None } 1850enum Option<T> { Some(T), None }
1920impl<T> Option<T> { 1851impl<T> Option<T> {
1921 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} } 1852 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
@@ -1928,34 +1859,34 @@ fn test() {
1928 let y: Option<i64> = x.map(|_v| 1); 1859 let y: Option<i64> = x.map(|_v| 1);
1929}"#, 1860}"#,
1930 expect![[r#" 1861 expect![[r#"
1931 147..151 'self': Option<T> 1862 86..90 'self': Option<T>
1932 153..154 'f': F 1863 92..93 'f': F
1933 172..183 '{ loop {} }': Option<U> 1864 111..122 '{ loop {} }': Option<U>
1934 174..181 'loop {}': ! 1865 113..120 'loop {}': !
1935 179..181 '{}': () 1866 118..120 '{}': ()
1936 197..316 '{ ... 1); }': () 1867 136..255 '{ ... 1); }': ()
1937 207..208 'x': Option<u32> 1868 146..147 'x': Option<u32>
1938 211..223 'Option::Some': Some<u32>(u32) -> Option<u32> 1869 150..162 'Option::Some': Some<u32>(u32) -> Option<u32>
1939 211..229 'Option...(1u32)': Option<u32> 1870 150..168 'Option...(1u32)': Option<u32>
1940 224..228 '1u32': u32 1871 163..167 '1u32': u32
1941 235..236 'x': Option<u32> 1872 174..175 'x': Option<u32>
1942 235..251 'x.map(...v + 1)': Option<u32> 1873 174..190 'x.map(...v + 1)': Option<u32>
1943 241..250 '|v| v + 1': |u32| -> u32 1874 180..189 '|v| v + 1': |u32| -> u32
1944 242..243 'v': u32 1875 181..182 'v': u32
1945 245..246 'v': u32 1876 184..185 'v': u32
1946 245..250 'v + 1': u32 1877 184..189 'v + 1': u32
1947 249..250 '1': u32 1878 188..189 '1': u32
1948 257..258 'x': Option<u32> 1879 196..197 'x': Option<u32>
1949 257..273 'x.map(... 1u64)': Option<u64> 1880 196..212 'x.map(... 1u64)': Option<u64>
1950 263..272 '|_v| 1u64': |u32| -> u64 1881 202..211 '|_v| 1u64': |u32| -> u64
1951 264..266 '_v': u32 1882 203..205 '_v': u32
1952 268..272 '1u64': u64 1883 207..211 '1u64': u64
1953 283..284 'y': Option<i64> 1884 222..223 'y': Option<i64>
1954 300..301 'x': Option<u32> 1885 239..240 'x': Option<u32>
1955 300..313 'x.map(|_v| 1)': Option<i64> 1886 239..252 'x.map(|_v| 1)': Option<i64>
1956 306..312 '|_v| 1': |u32| -> i64 1887 245..251 '|_v| 1': |u32| -> i64
1957 307..309 '_v': u32 1888 246..248 '_v': u32
1958 311..312 '1': i64 1889 250..251 '1': i64
1959 "#]], 1890 "#]],
1960 ); 1891 );
1961} 1892}
@@ -2029,11 +1960,7 @@ fn test<F: FnOnce(u32) -> u64>(f: F) {
2029fn closure_as_argument_inference_order() { 1960fn closure_as_argument_inference_order() {
2030 check_infer_with_mismatches( 1961 check_infer_with_mismatches(
2031 r#" 1962 r#"
2032#[lang = "fn_once"] 1963//- minicore: fn
2033trait FnOnce<Args> {
2034 type Output;
2035}
2036
2037fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} } 1964fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
2038fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} } 1965fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
2039 1966
@@ -2052,62 +1979,62 @@ fn test() {
2052 let x4 = S.foo2(|s| s.method(), S); 1979 let x4 = S.foo2(|s| s.method(), S);
2053}"#, 1980}"#,
2054 expect![[r#" 1981 expect![[r#"
2055 94..95 'x': T 1982 33..34 'x': T
2056 100..101 'f': F 1983 39..40 'f': F
2057 111..122 '{ loop {} }': U 1984 50..61 '{ loop {} }': U
2058 113..120 'loop {}': ! 1985 52..59 'loop {}': !
2059 118..120 '{}': () 1986 57..59 '{}': ()
2060 156..157 'f': F 1987 95..96 'f': F
2061 162..163 'x': T 1988 101..102 'x': T
2062 173..184 '{ loop {} }': U 1989 112..123 '{ loop {} }': U
2063 175..182 'loop {}': ! 1990 114..121 'loop {}': !
2064 180..182 '{}': () 1991 119..121 '{}': ()
2065 219..223 'self': S 1992 158..162 'self': S
2066 271..275 'self': S 1993 210..214 'self': S
2067 277..278 'x': T 1994 216..217 'x': T
2068 283..284 'f': F 1995 222..223 'f': F
2069 294..305 '{ loop {} }': U 1996 233..244 '{ loop {} }': U
2070 296..303 'loop {}': ! 1997 235..242 'loop {}': !
2071 301..303 '{}': () 1998 240..242 '{}': ()
2072 343..347 'self': S 1999 282..286 'self': S
2073 349..350 'f': F 2000 288..289 'f': F
2074 355..356 'x': T 2001 294..295 'x': T
2075 366..377 '{ loop {} }': U 2002 305..316 '{ loop {} }': U
2076 368..375 'loop {}': ! 2003 307..314 'loop {}': !
2077 373..375 '{}': () 2004 312..314 '{}': ()
2078 391..550 '{ ... S); }': () 2005 330..489 '{ ... S); }': ()
2079 401..403 'x1': u64 2006 340..342 'x1': u64
2080 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64 2007 345..349 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2081 406..429 'foo1(S...hod())': u64 2008 345..368 'foo1(S...hod())': u64
2082 411..412 'S': S 2009 350..351 'S': S
2083 414..428 '|s| s.method()': |S| -> u64 2010 353..367 '|s| s.method()': |S| -> u64
2084 415..416 's': S 2011 354..355 's': S
2085 418..419 's': S 2012 357..358 's': S
2086 418..428 's.method()': u64 2013 357..367 's.method()': u64
2087 439..441 'x2': u64 2014 378..380 'x2': u64
2088 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64 2015 383..387 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2089 444..467 'foo2(|...(), S)': u64 2016 383..406 'foo2(|...(), S)': u64
2090 449..463 '|s| s.method()': |S| -> u64 2017 388..402 '|s| s.method()': |S| -> u64
2091 450..451 's': S 2018 389..390 's': S
2092 453..454 's': S 2019 392..393 's': S
2093 453..463 's.method()': u64 2020 392..402 's.method()': u64
2094 465..466 'S': S 2021 404..405 'S': S
2095 477..479 'x3': u64 2022 416..418 'x3': u64
2096 482..483 'S': S 2023 421..422 'S': S
2097 482..507 'S.foo1...hod())': u64 2024 421..446 'S.foo1...hod())': u64
2098 489..490 'S': S 2025 428..429 'S': S
2099 492..506 '|s| s.method()': |S| -> u64 2026 431..445 '|s| s.method()': |S| -> u64
2100 493..494 's': S 2027 432..433 's': S
2101 496..497 's': S 2028 435..436 's': S
2102 496..506 's.method()': u64 2029 435..445 's.method()': u64
2103 517..519 'x4': u64 2030 456..458 'x4': u64
2104 522..523 'S': S 2031 461..462 'S': S
2105 522..547 'S.foo2...(), S)': u64 2032 461..486 'S.foo2...(), S)': u64
2106 529..543 '|s| s.method()': |S| -> u64 2033 468..482 '|s| s.method()': |S| -> u64
2107 530..531 's': S 2034 469..470 's': S
2108 533..534 's': S 2035 472..473 's': S
2109 533..543 's.method()': u64 2036 472..482 's.method()': u64
2110 545..546 'S': S 2037 484..485 'S': S
2111 "#]], 2038 "#]],
2112 ); 2039 );
2113} 2040}
@@ -2116,11 +2043,7 @@ fn test() {
2116fn fn_item_fn_trait() { 2043fn fn_item_fn_trait() {
2117 check_types( 2044 check_types(
2118 r#" 2045 r#"
2119#[lang = "fn_once"] 2046//- minicore: fn
2120trait FnOnce<Args> {
2121 type Output;
2122}
2123
2124struct S; 2047struct S;
2125 2048
2126fn foo() -> S {} 2049fn foo() -> S {}
@@ -2559,12 +2482,7 @@ fn test() -> impl Trait<i32> {
2559fn assoc_types_from_bounds() { 2482fn assoc_types_from_bounds() {
2560 check_infer( 2483 check_infer(
2561 r#" 2484 r#"
2562//- /main.rs 2485//- minicore: fn
2563#[lang = "fn_once"]
2564trait FnOnce<Args> {
2565 type Output;
2566}
2567
2568trait T { 2486trait T {
2569 type O; 2487 type O;
2570} 2488}
@@ -2583,15 +2501,15 @@ fn main() {
2583 f::<(), _>(|z| { z; }); 2501 f::<(), _>(|z| { z; });
2584}"#, 2502}"#,
2585 expect![[r#" 2503 expect![[r#"
2586 133..135 '_v': F 2504 72..74 '_v': F
2587 178..181 '{ }': () 2505 117..120 '{ }': ()
2588 193..224 '{ ... }); }': () 2506 132..163 '{ ... }); }': ()
2589 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ()) 2507 138..148 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2590 199..221 'f::<()... z; })': () 2508 138..160 'f::<()... z; })': ()
2591 210..220 '|z| { z; }': |&()| -> () 2509 149..159 '|z| { z; }': |&()| -> ()
2592 211..212 'z': &() 2510 150..151 'z': &()
2593 214..220 '{ z; }': () 2511 153..159 '{ z; }': ()
2594 216..217 'z': &() 2512 155..156 'z': &()
2595 "#]], 2513 "#]],
2596 ); 2514 );
2597} 2515}
@@ -2625,12 +2543,9 @@ fn test<T: Trait>() {
2625fn dyn_trait_through_chalk() { 2543fn dyn_trait_through_chalk() {
2626 check_types( 2544 check_types(
2627 r#" 2545 r#"
2546//- minicore: deref
2628struct Box<T> {} 2547struct Box<T> {}
2629#[lang = "deref"] 2548impl<T> core::ops::Deref for Box<T> {
2630trait Deref {
2631 type Target;
2632}
2633impl<T> Deref for Box<T> {
2634 type Target = T; 2549 type Target = T;
2635} 2550}
2636trait Trait { 2551trait Trait {
@@ -2667,17 +2582,7 @@ fn test() {
2667fn iterator_chain() { 2582fn iterator_chain() {
2668 check_infer_with_mismatches( 2583 check_infer_with_mismatches(
2669 r#" 2584 r#"
2670//- /main.rs 2585//- minicore: fn, option
2671#[lang = "fn_once"]
2672trait FnOnce<Args> {
2673 type Output;
2674}
2675#[lang = "fn_mut"]
2676trait FnMut<Args>: FnOnce<Args> { }
2677
2678enum Option<T> { Some(T), None }
2679use Option::*;
2680
2681pub trait Iterator { 2586pub trait Iterator {
2682 type Item; 2587 type Item;
2683 2588
@@ -2737,46 +2642,46 @@ fn main() {
2737 .for_each(|y| { y; }); 2642 .for_each(|y| { y; });
2738}"#, 2643}"#,
2739 expect![[r#" 2644 expect![[r#"
2740 226..230 'self': Self 2645 61..65 'self': Self
2741 232..233 'f': F 2646 67..68 'f': F
2742 317..328 '{ loop {} }': FilterMap<Self, F> 2647 152..163 '{ loop {} }': FilterMap<Self, F>
2743 319..326 'loop {}': ! 2648 154..161 'loop {}': !
2744 324..326 '{}': () 2649 159..161 '{}': ()
2745 349..353 'self': Self 2650 184..188 'self': Self
2746 355..356 'f': F 2651 190..191 'f': F
2747 405..416 '{ loop {} }': () 2652 240..251 '{ loop {} }': ()
2748 407..414 'loop {}': ! 2653 242..249 'loop {}': !
2749 412..414 '{}': () 2654 247..249 '{}': ()
2750 525..529 'self': Self 2655 360..364 'self': Self
2751 854..858 'self': I 2656 689..693 'self': I
2752 865..885 '{ ... }': I 2657 700..720 '{ ... }': I
2753 875..879 'self': I 2658 710..714 'self': I
2754 944..955 '{ loop {} }': Vec<T> 2659 779..790 '{ loop {} }': Vec<T>
2755 946..953 'loop {}': ! 2660 781..788 'loop {}': !
2756 951..953 '{}': () 2661 786..788 '{}': ()
2757 1142..1269 '{ ... }); }': () 2662 977..1104 '{ ... }); }': ()
2758 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32> 2663 983..998 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2759 1148..1165 'Vec::<...:new()': Vec<i32> 2664 983..1000 'Vec::<...:new()': Vec<i32>
2760 1148..1177 'Vec::<...iter()': IntoIter<i32> 2665 983..1012 'Vec::<...iter()': IntoIter<i32>
2761 1148..1240 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>> 2666 983..1075 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2762 1148..1266 'Vec::<... y; })': () 2667 983..1101 'Vec::<... y; })': ()
2763 1194..1239 '|x| if...None }': |i32| -> Option<u32> 2668 1029..1074 '|x| if...None }': |i32| -> Option<u32>
2764 1195..1196 'x': i32 2669 1030..1031 'x': i32
2765 1198..1239 'if x >...None }': Option<u32> 2670 1033..1074 'if x >...None }': Option<u32>
2766 1201..1202 'x': i32 2671 1036..1037 'x': i32
2767 1201..1206 'x > 0': bool 2672 1036..1041 'x > 0': bool
2768 1205..1206 '0': i32 2673 1040..1041 '0': i32
2769 1207..1225 '{ Some...u32) }': Option<u32> 2674 1042..1060 '{ Some...u32) }': Option<u32>
2770 1209..1213 'Some': Some<u32>(u32) -> Option<u32> 2675 1044..1048 'Some': Some<u32>(u32) -> Option<u32>
2771 1209..1223 'Some(x as u32)': Option<u32> 2676 1044..1058 'Some(x as u32)': Option<u32>
2772 1214..1215 'x': i32 2677 1049..1050 'x': i32
2773 1214..1222 'x as u32': u32 2678 1049..1057 'x as u32': u32
2774 1231..1239 '{ None }': Option<u32> 2679 1066..1074 '{ None }': Option<u32>
2775 1233..1237 'None': Option<u32> 2680 1068..1072 'None': Option<u32>
2776 1255..1265 '|y| { y; }': |u32| -> () 2681 1090..1100 '|y| { y; }': |u32| -> ()
2777 1256..1257 'y': u32 2682 1091..1092 'y': u32
2778 1259..1265 '{ y; }': () 2683 1094..1100 '{ y; }': ()
2779 1261..1262 'y': u32 2684 1096..1097 'y': u32
2780 "#]], 2685 "#]],
2781 ); 2686 );
2782} 2687}
@@ -3063,45 +2968,23 @@ fn foo() {
3063fn infer_fn_trait_arg() { 2968fn infer_fn_trait_arg() {
3064 check_infer_with_mismatches( 2969 check_infer_with_mismatches(
3065 r#" 2970 r#"
3066 //- /lib.rs deps:std 2971//- minicore: fn, option
3067 2972fn foo<F, T>(f: F) -> T
3068 #[lang = "fn_once"] 2973where
3069 pub trait FnOnce<Args> { 2974 F: Fn(Option<i32>) -> T,
3070 type Output; 2975{
3071 2976 let s = None;
3072 extern "rust-call" fn call_once(&self, args: Args) -> Self::Output; 2977 f(s)
3073 } 2978}
3074 2979"#,
3075 #[lang = "fn"]
3076 pub trait Fn<Args>:FnOnce<Args> {
3077 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3078 }
3079
3080 enum Option<T> {
3081 None,
3082 Some(T)
3083 }
3084
3085 fn foo<F, T>(f: F) -> T
3086 where
3087 F: Fn(Option<i32>) -> T,
3088 {
3089 let s = None;
3090 f(s)
3091 }
3092 "#,
3093 expect![[r#" 2980 expect![[r#"
3094 101..105 'self': &Self 2981 13..14 'f': F
3095 107..111 'args': Args 2982 59..89 '{ ...f(s) }': T
3096 220..224 'self': &Self 2983 69..70 's': Option<i32>
3097 226..230 'args': Args 2984 73..77 'None': Option<i32>
3098 313..314 'f': F 2985 83..84 'f': F
3099 359..389 '{ ...f(s) }': T 2986 83..87 'f(s)': T
3100 369..370 's': Option<i32> 2987 85..86 's': Option<i32>
3101 373..377 'None': Option<i32>
3102 383..384 'f': F
3103 383..387 'f(s)': T
3104 385..386 's': Option<i32>
3105 "#]], 2988 "#]],
3106 ); 2989 );
3107} 2990}
@@ -3180,17 +3063,7 @@ fn foo() {
3180fn infer_dyn_fn_output() { 3063fn infer_dyn_fn_output() {
3181 check_types( 3064 check_types(
3182 r#" 3065 r#"
3183#[lang = "fn_once"] 3066//- minicore: fn
3184pub trait FnOnce<Args> {
3185 type Output;
3186 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3187}
3188
3189#[lang = "fn"]
3190pub trait Fn<Args>: FnOnce<Args> {
3191 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3192}
3193
3194fn foo() { 3067fn foo() {
3195 let f: &dyn Fn() -> i32; 3068 let f: &dyn Fn() -> i32;
3196 f(); 3069 f();
@@ -3203,12 +3076,7 @@ fn foo() {
3203fn infer_dyn_fn_once_output() { 3076fn infer_dyn_fn_once_output() {
3204 check_types( 3077 check_types(
3205 r#" 3078 r#"
3206#[lang = "fn_once"] 3079//- minicore: fn
3207pub trait FnOnce<Args> {
3208 type Output;
3209 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3210}
3211
3212fn foo() { 3080fn foo() {
3213 let f: dyn FnOnce() -> i32; 3081 let f: dyn FnOnce() -> i32;
3214 f(); 3082 f();
@@ -3643,20 +3511,16 @@ fn main() {
3643fn fn_returning_unit() { 3511fn fn_returning_unit() {
3644 check_infer_with_mismatches( 3512 check_infer_with_mismatches(
3645 r#" 3513 r#"
3646#[lang = "fn_once"] 3514//- minicore: fn
3647trait FnOnce<Args> {
3648 type Output;
3649}
3650
3651fn test<F: FnOnce()>(f: F) { 3515fn test<F: FnOnce()>(f: F) {
3652 let _: () = f(); 3516 let _: () = f();
3653}"#, 3517}"#,
3654 expect![[r#" 3518 expect![[r#"
3655 82..83 'f': F 3519 21..22 'f': F
3656 88..112 '{ ...f(); }': () 3520 27..51 '{ ...f(); }': ()
3657 98..99 '_': () 3521 37..38 '_': ()
3658 106..107 'f': F 3522 45..46 'f': F
3659 106..109 'f()': () 3523 45..48 'f()': ()
3660 "#]], 3524 "#]],
3661 ); 3525 );
3662} 3526}
@@ -3695,16 +3559,7 @@ impl foo::Foo for u32 {
3695fn infer_async_ret_type() { 3559fn infer_async_ret_type() {
3696 check_types( 3560 check_types(
3697 r#" 3561 r#"
3698//- /main.rs crate:main deps:core 3562//- minicore: future, result
3699
3700enum Result<T, E> {
3701 Ok(T),
3702 Err(E),
3703}
3704
3705use Result::*;
3706
3707
3708struct Fooey; 3563struct Fooey;
3709 3564
3710impl Fooey { 3565impl Fooey {
@@ -3727,15 +3582,6 @@ async fn get_accounts() -> Result<u32, ()> {
3727 // ^ u32 3582 // ^ u32
3728 Ok(ret) 3583 Ok(ret)
3729} 3584}
3730
3731//- /core.rs crate:core
3732#[prelude_import] use future::*;
3733mod future {
3734 #[lang = "future_trait"]
3735 trait Future {
3736 type Output;
3737 }
3738}
3739"#, 3585"#,
3740 ); 3586 );
3741} 3587}