diff options
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r-- | crates/hir_ty/src/tests/simple.rs | 47 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 51 |
2 files changed, 98 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index 16682f76f..20ceb7415 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs | |||
@@ -2415,3 +2415,50 @@ fn infer_const_params() { | |||
2415 | "#]], | 2415 | "#]], |
2416 | ); | 2416 | ); |
2417 | } | 2417 | } |
2418 | |||
2419 | #[test] | ||
2420 | fn infer_inner_type() { | ||
2421 | check_infer( | ||
2422 | r#" | ||
2423 | fn foo() { | ||
2424 | struct S { field: u32 } | ||
2425 | let s = S { field: 0 }; | ||
2426 | let f = s.field; | ||
2427 | } | ||
2428 | "#, | ||
2429 | expect![[r#" | ||
2430 | 9..89 '{ ...eld; }': () | ||
2431 | 47..48 's': S | ||
2432 | 51..65 'S { field: 0 }': S | ||
2433 | 62..63 '0': u32 | ||
2434 | 75..76 'f': u32 | ||
2435 | 79..80 's': S | ||
2436 | 79..86 's.field': u32 | ||
2437 | "#]], | ||
2438 | ); | ||
2439 | } | ||
2440 | |||
2441 | #[test] | ||
2442 | fn infer_nested_inner_type() { | ||
2443 | check_infer( | ||
2444 | r#" | ||
2445 | fn foo() { | ||
2446 | { | ||
2447 | let s = S { field: 0 }; | ||
2448 | let f = s.field; | ||
2449 | } | ||
2450 | struct S { field: u32 } | ||
2451 | } | ||
2452 | "#, | ||
2453 | expect![[r#" | ||
2454 | 9..109 '{ ...32 } }': () | ||
2455 | 15..79 '{ ... }': () | ||
2456 | 29..30 's': S | ||
2457 | 33..47 'S { field: 0 }': S | ||
2458 | 44..45 '0': u32 | ||
2459 | 61..62 'f': u32 | ||
2460 | 65..66 's': S | ||
2461 | 65..72 's.field': u32 | ||
2462 | "#]], | ||
2463 | ); | ||
2464 | } | ||
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index e5a3f95a6..e030f4a97 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -3151,3 +3151,54 @@ fn test() { | |||
3151 | "#, | 3151 | "#, |
3152 | ); | 3152 | ); |
3153 | } | 3153 | } |
3154 | |||
3155 | #[test] | ||
3156 | fn inner_use() { | ||
3157 | check_types( | ||
3158 | r#" | ||
3159 | mod m { | ||
3160 | pub trait Tr { | ||
3161 | fn method(&self) -> u8 { 0 } | ||
3162 | } | ||
3163 | |||
3164 | impl Tr for () {} | ||
3165 | } | ||
3166 | |||
3167 | fn f() { | ||
3168 | use m::Tr; | ||
3169 | |||
3170 | ().method(); | ||
3171 | //^^^^^^^^^^^ u8 | ||
3172 | } | ||
3173 | "#, | ||
3174 | ); | ||
3175 | } | ||
3176 | |||
3177 | #[test] | ||
3178 | fn inner_use_in_block() { | ||
3179 | check_types( | ||
3180 | r#" | ||
3181 | mod m { | ||
3182 | pub trait Tr { | ||
3183 | fn method(&self) -> u8 { 0 } | ||
3184 | } | ||
3185 | |||
3186 | impl Tr for () {} | ||
3187 | } | ||
3188 | |||
3189 | fn f() { | ||
3190 | { | ||
3191 | use m::Tr; | ||
3192 | |||
3193 | ().method(); | ||
3194 | //^^^^^^^^^^^ u8 | ||
3195 | } | ||
3196 | |||
3197 | { | ||
3198 | ().method(); | ||
3199 | //^^^^^^^^^^^ {unknown} | ||
3200 | } | ||
3201 | } | ||
3202 | "#, | ||
3203 | ); | ||
3204 | } | ||