From 3c5734712a074a5bb3100dbec8b690e60b5beac0 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 10 Feb 2021 15:54:21 +0100 Subject: Add more tests --- crates/hir_ty/src/tests/simple.rs | 41 +++++++++++++++++++++++++------ crates/hir_ty/src/tests/traits.rs | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 8 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index b364c2e58..20ceb7415 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs @@ -2427,13 +2427,38 @@ fn infer_inner_type() { } "#, expect![[r#" - 9..89 '{ ...eld; }': () - 47..48 's': S - 51..65 'S { field: 0 }': S - 62..63 '0': u32 - 75..76 'f': u32 - 79..80 's': S - 79..86 's.field': u32 - "#]], + 9..89 '{ ...eld; }': () + 47..48 's': S + 51..65 'S { field: 0 }': S + 62..63 '0': u32 + 75..76 'f': u32 + 79..80 's': S + 79..86 's.field': u32 + "#]], + ); +} + +#[test] +fn infer_nested_inner_type() { + check_infer( + r#" + fn foo() { + { + let s = S { field: 0 }; + let f = s.field; + } + struct S { field: u32 } + } + "#, + expect![[r#" + 9..109 '{ ...32 } }': () + 15..79 '{ ... }': () + 29..30 's': S + 33..47 'S { field: 0 }': S + 44..45 '0': u32 + 61..62 'f': u32 + 65..66 's': S + 65..72 's.field': u32 + "#]], ); } 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() { "#, ); } + +#[test] +fn inner_use() { + check_types( + r#" +mod m { + pub trait Tr { + fn method(&self) -> u8 { 0 } + } + + impl Tr for () {} +} + +fn f() { + use m::Tr; + + ().method(); + //^^^^^^^^^^^ u8 +} + "#, + ); +} + +#[test] +fn inner_use_in_block() { + check_types( + r#" +mod m { + pub trait Tr { + fn method(&self) -> u8 { 0 } + } + + impl Tr for () {} +} + +fn f() { + { + use m::Tr; + + ().method(); + //^^^^^^^^^^^ u8 + } + + { + ().method(); + //^^^^^^^^^^^ {unknown} + } +} + "#, + ); +} -- cgit v1.2.3