From 073a1ef834be5e2e1ae6733c6c299d2ae68050d8 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 6 Mar 2020 15:26:49 +0100 Subject: Support aliases and Self in struct literals Fixes #3306. --- crates/ra_hir_ty/src/tests/simple.rs | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 3803f5938..c140bd513 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -50,6 +50,47 @@ fn test() { assert_eq!("Nat", type_at_pos(&db, pos)); } +#[test] +fn self_in_struct_lit() { + assert_snapshot!(infer( + r#" +//- /main.rs +struct S { x: T } + +impl S { + fn foo() { + Self { x: 1 }; + } +} +"#, + ), @r###" + [63; 93) '{ ... }': () + [73; 86) 'Self { x: 1 }': S + [83; 84) '1': u32 + "###); +} + +#[test] +fn type_alias_in_struct_lit() { + assert_snapshot!(infer( + r#" +//- /main.rs +struct S { x: T } + +type SS = S; + +fn foo() { + SS { x: 1 }; +} + +"#, + ), @r###" + [64; 84) '{ ...1 }; }': () + [70; 81) 'SS { x: 1 }': S + [78; 79) '1': u32 + "###); +} + #[test] fn infer_ranges() { let (db, pos) = TestDB::with_position( -- cgit v1.2.3