diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests/simple.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/simple.rs | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 88309157b..8a5031756 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs | |||
@@ -1997,3 +1997,111 @@ fn foo() { | |||
1997 | "### | 1997 | "### |
1998 | ); | 1998 | ); |
1999 | } | 1999 | } |
2000 | |||
2001 | #[test] | ||
2002 | fn generic_default() { | ||
2003 | assert_snapshot!( | ||
2004 | infer(r#" | ||
2005 | struct Thing<T = ()> { t: T } | ||
2006 | enum OtherThing<T = ()> { | ||
2007 | One { t: T }, | ||
2008 | Two(T), | ||
2009 | } | ||
2010 | |||
2011 | fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) { | ||
2012 | t1.t; | ||
2013 | t3.t; | ||
2014 | match t2 { | ||
2015 | OtherThing::One { t } => { t; }, | ||
2016 | OtherThing::Two(t) => { t; }, | ||
2017 | } | ||
2018 | match t4 { | ||
2019 | OtherThing::One { t } => { t; }, | ||
2020 | OtherThing::Two(t) => { t; }, | ||
2021 | } | ||
2022 | } | ||
2023 | "#), | ||
2024 | @r###" | ||
2025 | 98..100 't1': Thing<()> | ||
2026 | 109..111 't2': OtherThing<()> | ||
2027 | 125..127 't3': Thing<i32> | ||
2028 | 141..143 't4': OtherThing<i32> | ||
2029 | 162..385 '{ ... } }': () | ||
2030 | 168..170 't1': Thing<()> | ||
2031 | 168..172 't1.t': () | ||
2032 | 178..180 't3': Thing<i32> | ||
2033 | 178..182 't3.t': i32 | ||
2034 | 188..283 'match ... }': () | ||
2035 | 194..196 't2': OtherThing<()> | ||
2036 | 207..228 'OtherT... { t }': OtherThing<()> | ||
2037 | 225..226 't': () | ||
2038 | 232..238 '{ t; }': () | ||
2039 | 234..235 't': () | ||
2040 | 248..266 'OtherT...Two(t)': OtherThing<()> | ||
2041 | 264..265 't': () | ||
2042 | 270..276 '{ t; }': () | ||
2043 | 272..273 't': () | ||
2044 | 288..383 'match ... }': () | ||
2045 | 294..296 't4': OtherThing<i32> | ||
2046 | 307..328 'OtherT... { t }': OtherThing<i32> | ||
2047 | 325..326 't': i32 | ||
2048 | 332..338 '{ t; }': () | ||
2049 | 334..335 't': i32 | ||
2050 | 348..366 'OtherT...Two(t)': OtherThing<i32> | ||
2051 | 364..365 't': i32 | ||
2052 | 370..376 '{ t; }': () | ||
2053 | 372..373 't': i32 | ||
2054 | "### | ||
2055 | ); | ||
2056 | } | ||
2057 | |||
2058 | #[test] | ||
2059 | fn generic_default_in_struct_literal() { | ||
2060 | assert_snapshot!( | ||
2061 | infer(r#" | ||
2062 | struct Thing<T = ()> { t: T } | ||
2063 | enum OtherThing<T = ()> { | ||
2064 | One { t: T }, | ||
2065 | Two(T), | ||
2066 | } | ||
2067 | |||
2068 | fn test() { | ||
2069 | let x = Thing { t: loop {} }; | ||
2070 | let y = Thing { t: () }; | ||
2071 | let z = Thing { t: 1i32 }; | ||
2072 | if let Thing { t } = z { | ||
2073 | t; | ||
2074 | } | ||
2075 | |||
2076 | let a = OtherThing::One { t: 1i32 }; | ||
2077 | let b = OtherThing::Two(1i32); | ||
2078 | } | ||
2079 | "#), | ||
2080 | @r###" | ||
2081 | 100..320 '{ ...32); }': () | ||
2082 | 110..111 'x': Thing<!> | ||
2083 | 114..134 'Thing ...p {} }': Thing<!> | ||
2084 | 125..132 'loop {}': ! | ||
2085 | 130..132 '{}': () | ||
2086 | 144..145 'y': Thing<()> | ||
2087 | 148..163 'Thing { t: () }': Thing<()> | ||
2088 | 159..161 '()': () | ||
2089 | 173..174 'z': Thing<i32> | ||
2090 | 177..194 'Thing ...1i32 }': Thing<i32> | ||
2091 | 188..192 '1i32': i32 | ||
2092 | 200..241 'if let... }': () | ||
2093 | 207..218 'Thing { t }': Thing<i32> | ||
2094 | 215..216 't': i32 | ||
2095 | 221..222 'z': Thing<i32> | ||
2096 | 223..241 '{ ... }': () | ||
2097 | 233..234 't': i32 | ||
2098 | 251..252 'a': OtherThing<i32> | ||
2099 | 255..282 'OtherT...1i32 }': OtherThing<i32> | ||
2100 | 276..280 '1i32': i32 | ||
2101 | 292..293 'b': OtherThing<i32> | ||
2102 | 296..311 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32> | ||
2103 | 296..317 'OtherT...(1i32)': OtherThing<i32> | ||
2104 | 312..316 '1i32': i32 | ||
2105 | "### | ||
2106 | ); | ||
2107 | } | ||