aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-10 15:59:49 +0000
committerGitHub <[email protected]>2021-02-10 15:59:49 +0000
commit7ec03439a89943e46a22fa3c158eb7fffb205666 (patch)
tree2a9098516877f68242a6d8c7c8fb8bbfd615e19e /crates/hir_ty/src/tests
parent82a1b91f205ac9c3d397b2bea033639f5df9e6b6 (diff)
parent3c5734712a074a5bb3100dbec8b690e60b5beac0 (diff)
Merge #7627
7627: infer: update resolver when descending into block r=jonas-schievink a=jonas-schievink Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r--crates/hir_ty/src/tests/simple.rs47
-rw-r--r--crates/hir_ty/src/tests/traits.rs51
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]
2420fn 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]
2442fn 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]
3156fn inner_use() {
3157 check_types(
3158 r#"
3159mod m {
3160 pub trait Tr {
3161 fn method(&self) -> u8 { 0 }
3162 }
3163
3164 impl Tr for () {}
3165}
3166
3167fn f() {
3168 use m::Tr;
3169
3170 ().method();
3171 //^^^^^^^^^^^ u8
3172}
3173 "#,
3174 );
3175}
3176
3177#[test]
3178fn inner_use_in_block() {
3179 check_types(
3180 r#"
3181mod m {
3182 pub trait Tr {
3183 fn method(&self) -> u8 { 0 }
3184 }
3185
3186 impl Tr for () {}
3187}
3188
3189fn f() {
3190 {
3191 use m::Tr;
3192
3193 ().method();
3194 //^^^^^^^^^^^ u8
3195 }
3196
3197 {
3198 ().method();
3199 //^^^^^^^^^^^ {unknown}
3200 }
3201}
3202 "#,
3203 );
3204}