From 9c2d83a4c809b0b11ca389bb454e197859e5116c Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Wed, 16 Jan 2019 17:47:59 +0100 Subject: Add crude implementation of tuplestruct pattern inference --- crates/ra_hir/src/ty/tests.rs | 36 +++++++++++++++---------- crates/ra_hir/src/ty/tests/data/adt_pattern.txt | 12 +++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 crates/ra_hir/src/ty/tests/data/adt_pattern.txt (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index ff2c8b0d4..75fe2cc6e 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -359,31 +359,39 @@ fn test(x: &str, y: isize) { } #[test] -fn infer_pattern() { +fn infer_simple_pattern() { check_inference( r#" -enum E { - A { x: usize }, - B -} - fn test(x: &i32) { let y = x; let &z = x; let a = z; let (c, d) = (1, "hello"); +} +"#, + "pattern.txt", + ); +} + +#[test] +fn infer_adt_pattern() { + check_inference( + r#" +enum E { + A { x: usize }, + B +} + +struct S(u32, E); +fn test() { let e = E::A { x: 3 }; - if let E::A { x: x } = e { - x - }; - match e { - E::A { x } => x, - E::B => 1, - }; + + let S(y, z) = foo; + let E::A { x: new_var } = e; } "#, - "pattern.txt", + "adt_pattern.txt", ); } diff --git a/crates/ra_hir/src/ty/tests/data/adt_pattern.txt b/crates/ra_hir/src/ty/tests/data/adt_pattern.txt new file mode 100644 index 000000000..d23b865a0 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/adt_pattern.txt @@ -0,0 +1,12 @@ +[49; 192) '{ ... }; }': () +[59; 60) 'e': E +[63; 76) 'E::A { x: 3 }': E +[73; 74) '3': usize +[82; 124) 'if let... }': [unknown] +[105; 106) 'e': E +[107; 124) '{ ... }': [unknown] +[117; 118) 'x': [unknown] +[130; 189) 'match ... }': [unknown] +[136; 137) 'e': E +[162; 163) 'x': [unknown] +[181; 182) '1': i32 -- cgit v1.2.3