aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r--crates/hir_ty/src/tests/macros.rs16
-rw-r--r--crates/hir_ty/src/tests/traits.rs216
2 files changed, 132 insertions, 100 deletions
diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs
index fb3afaedc..af4f8bb11 100644
--- a/crates/hir_ty/src/tests/macros.rs
+++ b/crates/hir_ty/src/tests/macros.rs
@@ -216,6 +216,22 @@ fn expr_macro_expanded_in_various_places() {
216} 216}
217 217
218#[test] 218#[test]
219fn expr_macro_expanded_in_stmts() {
220 check_infer(
221 r#"
222 macro_rules! id { ($($es:tt)*) => { $($es)* } }
223 fn foo() {
224 id! { let a = (); }
225 }
226 "#,
227 expect![[r#"
228 !0..8 'leta=();': ()
229 57..84 '{ ...); } }': ()
230 "#]],
231 );
232}
233
234#[test]
219fn infer_type_value_macro_having_same_name() { 235fn infer_type_value_macro_having_same_name() {
220 check_infer( 236 check_infer(
221 r#" 237 r#"
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index e185b1c0a..93d3ad020 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -1699,7 +1699,7 @@ fn super_trait_assoc_type_bounds() {
1699 1699
1700#[test] 1700#[test]
1701fn fn_trait() { 1701fn fn_trait() {
1702 check_infer( 1702 check_infer_with_mismatches(
1703 r#" 1703 r#"
1704 trait FnOnce<Args> { 1704 trait FnOnce<Args> {
1705 type Output; 1705 type Output;
@@ -1727,7 +1727,7 @@ fn fn_trait() {
1727 1727
1728#[test] 1728#[test]
1729fn fn_ptr_and_item() { 1729fn fn_ptr_and_item() {
1730 check_infer( 1730 check_infer_with_mismatches(
1731 r#" 1731 r#"
1732 #[lang="fn_once"] 1732 #[lang="fn_once"]
1733 trait FnOnce<Args> { 1733 trait FnOnce<Args> {
@@ -1743,12 +1743,12 @@ fn fn_ptr_and_item() {
1743 struct Bar<T>(T); 1743 struct Bar<T>(T);
1744 1744
1745 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> { 1745 impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> {
1746 fn foo(&self) -> (A1, R) {} 1746 fn foo(&self) -> (A1, R) { loop {} }
1747 } 1747 }
1748 1748
1749 enum Opt<T> { None, Some(T) } 1749 enum Opt<T> { None, Some(T) }
1750 impl<T> Opt<T> { 1750 impl<T> Opt<T> {
1751 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> {} 1751 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> { loop {} }
1752 } 1752 }
1753 1753
1754 fn test() { 1754 fn test() {
@@ -1765,19 +1765,23 @@ fn fn_ptr_and_item() {
1765 80..84 'args': Args 1765 80..84 'args': Args
1766 139..143 'self': &Self 1766 139..143 'self': &Self
1767 243..247 'self': &Bar<F> 1767 243..247 'self': &Bar<F>
1768 260..262 '{}': () 1768 260..271 '{ loop {} }': (A1, R)
1769 346..350 'self': Opt<T> 1769 262..269 'loop {}': !
1770 352..353 'f': F 1770 267..269 '{}': ()
1771 368..370 '{}': () 1771 355..359 'self': Opt<T>
1772 384..500 '{ ...(f); }': () 1772 361..362 'f': F
1773 394..397 'bar': Bar<fn(u8) -> u32> 1773 377..388 '{ loop {} }': Opt<U>
1774 423..426 'bar': Bar<fn(u8) -> u32> 1774 379..386 'loop {}': !
1775 423..432 'bar.foo()': (u8, u32) 1775 384..386 '{}': ()
1776 443..446 'opt': Opt<u8> 1776 402..518 '{ ...(f); }': ()
1777 465..466 'f': fn(u8) -> u32 1777 412..415 'bar': Bar<fn(u8) -> u32>
1778 487..490 'opt': Opt<u8> 1778 441..444 'bar': Bar<fn(u8) -> u32>
1779 487..497 'opt.map(f)': Opt<u32> 1779 441..450 'bar.foo()': (u8, u32)
1780 495..496 'f': fn(u8) -> u32 1780 461..464 'opt': Opt<u8>
1781 483..484 'f': fn(u8) -> u32
1782 505..508 'opt': Opt<u8>
1783 505..515 'opt.map(f)': Opt<u32>
1784 513..514 'f': fn(u8) -> u32
1781 "#]], 1785 "#]],
1782 ); 1786 );
1783} 1787}
@@ -1859,7 +1863,7 @@ fn fn_trait_deref_with_ty_default() {
1859 1863
1860#[test] 1864#[test]
1861fn closure_1() { 1865fn closure_1() {
1862 check_infer( 1866 check_infer_with_mismatches(
1863 r#" 1867 r#"
1864 #[lang = "fn_once"] 1868 #[lang = "fn_once"]
1865 trait FnOnce<Args> { 1869 trait FnOnce<Args> {
@@ -1868,7 +1872,7 @@ fn closure_1() {
1868 1872
1869 enum Option<T> { Some(T), None } 1873 enum Option<T> { Some(T), None }
1870 impl<T> Option<T> { 1874 impl<T> Option<T> {
1871 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {} 1875 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { loop {} }
1872 } 1876 }
1873 1877
1874 fn test() { 1878 fn test() {
@@ -1881,37 +1885,39 @@ fn closure_1() {
1881 expect![[r#" 1885 expect![[r#"
1882 147..151 'self': Option<T> 1886 147..151 'self': Option<T>
1883 153..154 'f': F 1887 153..154 'f': F
1884 172..174 '{}': () 1888 172..183 '{ loop {} }': Option<U>
1885 188..307 '{ ... 1); }': () 1889 174..181 'loop {}': !
1886 198..199 'x': Option<u32> 1890 179..181 '{}': ()
1887 202..214 'Option::Some': Some<u32>(u32) -> Option<u32> 1891 197..316 '{ ... 1); }': ()
1888 202..220 'Option...(1u32)': Option<u32> 1892 207..208 'x': Option<u32>
1889 215..219 '1u32': u32 1893 211..223 'Option::Some': Some<u32>(u32) -> Option<u32>
1890 226..227 'x': Option<u32> 1894 211..229 'Option...(1u32)': Option<u32>
1891 226..242 'x.map(...v + 1)': Option<u32> 1895 224..228 '1u32': u32
1892 232..241 '|v| v + 1': |u32| -> u32 1896 235..236 'x': Option<u32>
1893 233..234 'v': u32 1897 235..251 'x.map(...v + 1)': Option<u32>
1894 236..237 'v': u32 1898 241..250 '|v| v + 1': |u32| -> u32
1895 236..241 'v + 1': u32 1899 242..243 'v': u32
1896 240..241 '1': u32 1900 245..246 'v': u32
1897 248..249 'x': Option<u32> 1901 245..250 'v + 1': u32
1898 248..264 'x.map(... 1u64)': Option<u64> 1902 249..250 '1': u32
1899 254..263 '|_v| 1u64': |u32| -> u64 1903 257..258 'x': Option<u32>
1900 255..257 '_v': u32 1904 257..273 'x.map(... 1u64)': Option<u64>
1901 259..263 '1u64': u64 1905 263..272 '|_v| 1u64': |u32| -> u64
1902 274..275 'y': Option<i64> 1906 264..266 '_v': u32
1903 291..292 'x': Option<u32> 1907 268..272 '1u64': u64
1904 291..304 'x.map(|_v| 1)': Option<i64> 1908 283..284 'y': Option<i64>
1905 297..303 '|_v| 1': |u32| -> i64 1909 300..301 'x': Option<u32>
1906 298..300 '_v': u32 1910 300..313 'x.map(|_v| 1)': Option<i64>
1907 302..303 '1': i64 1911 306..312 '|_v| 1': |u32| -> i64
1912 307..309 '_v': u32
1913 311..312 '1': i64
1908 "#]], 1914 "#]],
1909 ); 1915 );
1910} 1916}
1911 1917
1912#[test] 1918#[test]
1913fn closure_2() { 1919fn closure_2() {
1914 check_infer( 1920 check_infer_with_mismatches(
1915 r#" 1921 r#"
1916 trait FnOnce<Args> { 1922 trait FnOnce<Args> {
1917 type Output; 1923 type Output;
@@ -1951,22 +1957,22 @@ fn closure_2() {
1951 1957
1952#[test] 1958#[test]
1953fn closure_as_argument_inference_order() { 1959fn closure_as_argument_inference_order() {
1954 check_infer( 1960 check_infer_with_mismatches(
1955 r#" 1961 r#"
1956 #[lang = "fn_once"] 1962 #[lang = "fn_once"]
1957 trait FnOnce<Args> { 1963 trait FnOnce<Args> {
1958 type Output; 1964 type Output;
1959 } 1965 }
1960 1966
1961 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U {} 1967 fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U { loop {} }
1962 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U {} 1968 fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U { loop {} }
1963 1969
1964 struct S; 1970 struct S;
1965 impl S { 1971 impl S {
1966 fn method(self) -> u64; 1972 fn method(self) -> u64;
1967 1973
1968 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U {} 1974 fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U { loop {} }
1969 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U {} 1975 fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U { loop {} }
1970 } 1976 }
1971 1977
1972 fn test() { 1978 fn test() {
@@ -1979,52 +1985,60 @@ fn closure_as_argument_inference_order() {
1979 expect![[r#" 1985 expect![[r#"
1980 94..95 'x': T 1986 94..95 'x': T
1981 100..101 'f': F 1987 100..101 'f': F
1982 111..113 '{}': () 1988 111..122 '{ loop {} }': U
1983 147..148 'f': F 1989 113..120 'loop {}': !
1984 153..154 'x': T 1990 118..120 '{}': ()
1985 164..166 '{}': () 1991 156..157 'f': F
1986 201..205 'self': S 1992 162..163 'x': T
1987 253..257 'self': S 1993 173..184 '{ loop {} }': U
1988 259..260 'x': T 1994 175..182 'loop {}': !
1989 265..266 'f': F 1995 180..182 '{}': ()
1990 276..278 '{}': () 1996 219..223 'self': S
1991 316..320 'self': S 1997 271..275 'self': S
1992 322..323 'f': F 1998 277..278 'x': T
1993 328..329 'x': T 1999 283..284 'f': F
1994 339..341 '{}': () 2000 294..305 '{ loop {} }': U
1995 355..514 '{ ... S); }': () 2001 296..303 'loop {}': !
1996 365..367 'x1': u64 2002 301..303 '{}': ()
1997 370..374 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64 2003 343..347 'self': S
1998 370..393 'foo1(S...hod())': u64 2004 349..350 'f': F
1999 375..376 'S': S 2005 355..356 'x': T
2000 378..392 '|s| s.method()': |S| -> u64 2006 366..377 '{ loop {} }': U
2001 379..380 's': S 2007 368..375 'loop {}': !
2002 382..383 's': S 2008 373..375 '{}': ()
2003 382..392 's.method()': u64 2009 391..550 '{ ... S); }': ()
2004 403..405 'x2': u64 2010 401..403 'x1': u64
2005 408..412 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64 2011 406..410 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
2006 408..431 'foo2(|...(), S)': u64 2012 406..429 'foo1(S...hod())': u64
2007 413..427 '|s| s.method()': |S| -> u64 2013 411..412 'S': S
2008 414..415 's': S 2014 414..428 '|s| s.method()': |S| -> u64
2009 417..418 's': S 2015 415..416 's': S
2010 417..427 's.method()': u64 2016 418..419 's': S
2011 429..430 'S': S 2017 418..428 's.method()': u64
2012 441..443 'x3': u64 2018 439..441 'x2': u64
2013 446..447 'S': S 2019 444..448 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
2014 446..471 'S.foo1...hod())': u64 2020 444..467 'foo2(|...(), S)': u64
2015 453..454 'S': S 2021 449..463 '|s| s.method()': |S| -> u64
2016 456..470 '|s| s.method()': |S| -> u64 2022 450..451 's': S
2017 457..458 's': S 2023 453..454 's': S
2018 460..461 's': S 2024 453..463 's.method()': u64
2019 460..470 's.method()': u64 2025 465..466 'S': S
2020 481..483 'x4': u64 2026 477..479 'x3': u64
2021 486..487 'S': S 2027 482..483 'S': S
2022 486..511 'S.foo2...(), S)': u64 2028 482..507 'S.foo1...hod())': u64
2023 493..507 '|s| s.method()': |S| -> u64 2029 489..490 'S': S
2024 494..495 's': S 2030 492..506 '|s| s.method()': |S| -> u64
2025 497..498 's': S 2031 493..494 's': S
2026 497..507 's.method()': u64 2032 496..497 's': S
2027 509..510 'S': S 2033 496..506 's.method()': u64
2034 517..519 'x4': u64
2035 522..523 'S': S
2036 522..547 'S.foo2...(), S)': u64
2037 529..543 '|s| s.method()': |S| -> u64
2038 530..531 's': S
2039 533..534 's': S
2040 533..543 's.method()': u64
2041 545..546 'S': S
2028 "#]], 2042 "#]],
2029 ); 2043 );
2030} 2044}
@@ -2536,7 +2550,7 @@ fn test() {
2536 2550
2537#[test] 2551#[test]
2538fn iterator_chain() { 2552fn iterator_chain() {
2539 check_infer( 2553 check_infer_with_mismatches(
2540 r#" 2554 r#"
2541 //- /main.rs 2555 //- /main.rs
2542 #[lang = "fn_once"] 2556 #[lang = "fn_once"]
@@ -2939,7 +2953,7 @@ fn infer_closure_arg() {
2939 2953
2940#[test] 2954#[test]
2941fn infer_fn_trait_arg() { 2955fn infer_fn_trait_arg() {
2942 check_infer( 2956 check_infer_with_mismatches(
2943 r#" 2957 r#"
2944 //- /lib.rs deps:std 2958 //- /lib.rs deps:std
2945 2959
@@ -2986,7 +3000,8 @@ fn infer_fn_trait_arg() {
2986 3000
2987#[test] 3001#[test]
2988fn infer_box_fn_arg() { 3002fn infer_box_fn_arg() {
2989 check_infer( 3003 // The type mismatch is a bug
3004 check_infer_with_mismatches(
2990 r#" 3005 r#"
2991 //- /lib.rs deps:std 3006 //- /lib.rs deps:std
2992 3007
@@ -3025,7 +3040,7 @@ fn infer_box_fn_arg() {
3025 fn foo() { 3040 fn foo() {
3026 let s = Option::None; 3041 let s = Option::None;
3027 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); 3042 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
3028 f(&s) 3043 f(&s);
3029 } 3044 }
3030 "#, 3045 "#,
3031 expect![[r#" 3046 expect![[r#"
@@ -3037,7 +3052,7 @@ fn infer_box_fn_arg() {
3037 406..417 '&self.inner': &*mut T 3052 406..417 '&self.inner': &*mut T
3038 407..411 'self': &Box<T> 3053 407..411 'self': &Box<T>
3039 407..417 'self.inner': *mut T 3054 407..417 'self.inner': *mut T
3040 478..575 '{ ...(&s) }': FnOnce::Output<dyn FnOnce(&Option<i32>), (&Option<i32>,)> 3055 478..576 '{ ...&s); }': ()
3041 488..489 's': Option<i32> 3056 488..489 's': Option<i32>
3042 492..504 'Option::None': Option<i32> 3057 492..504 'Option::None': Option<i32>
3043 514..515 'f': Box<dyn FnOnce(&Option<i32>)> 3058 514..515 'f': Box<dyn FnOnce(&Option<i32>)>
@@ -3049,6 +3064,7 @@ fn infer_box_fn_arg() {
3049 568..573 'f(&s)': FnOnce::Output<dyn FnOnce(&Option<i32>), (&Option<i32>,)> 3064 568..573 'f(&s)': FnOnce::Output<dyn FnOnce(&Option<i32>), (&Option<i32>,)>
3050 570..572 '&s': &Option<i32> 3065 570..572 '&s': &Option<i32>
3051 571..572 's': Option<i32> 3066 571..572 's': Option<i32>
3067 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|_| -> ()>
3052 "#]], 3068 "#]],
3053 ); 3069 );
3054} 3070}