Support aliases and Self in struct literals

Fixes #3306.
This commit is contained in:
Florian Diebold 2020-03-06 15:26:49 +01:00
parent 1cc6879576
commit 073a1ef834
3 changed files with 95 additions and 1 deletions

View file

@ -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<T> { x: T }
impl S<u32> {
fn foo() {
Self { x: 1 };
}
}
"#,
), @r###"
[63; 93) '{ ... }': ()
[73; 86) 'Self { x: 1 }': S<u32>
[83; 84) '1': u32
"###);
}
#[test]
fn type_alias_in_struct_lit() {
assert_snapshot!(infer(
r#"
//- /main.rs
struct S<T> { x: T }
type SS = S<u32>;
fn foo() {
SS { x: 1 };
}
"#,
), @r###"
[64; 84) '{ ...1 }; }': ()
[70; 81) 'SS { x: 1 }': S<u32>
[78; 79) '1': u32
"###);
}
#[test]
fn infer_ranges() {
let (db, pos) = TestDB::with_position(