From 72712b8a428e17d63c413522c770e8f1f0587455 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 20 Feb 2019 22:36:54 +0100 Subject: Fix handling of generics in tuple variants and refactor a bit Also make them display a tiny bit nicer. Fixes #860. --- .../src/ty/snapshots/tests__infer_struct.snap | 6 +++--- .../tests__infer_tuple_struct_generics.snap | 23 ++++++++++++++++++++++ crates/ra_hir/src/ty/tests.rs | 21 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap index 294186b06..32f1fa108 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_struct.snap @@ -1,19 +1,19 @@ --- -created: "2019-02-17T16:16:58.863630956Z" +created: "2019-02-20T21:31:12.910924715Z" creator: insta@0.6.2 source: crates/ra_hir/src/ty/tests.rs expression: "&result" --- [72; 154) '{ ...a.c; }': () [82; 83) 'c': C -[86; 87) 'C': fn C(usize) -> C +[86; 87) 'C': C(usize) -> C [86; 90) 'C(1)': C [88; 89) '1': usize [96; 97) 'B': B [107; 108) 'a': A [114; 133) 'A { b:...C(1) }': A [121; 122) 'B': B -[127; 128) 'C': fn C(usize) -> C +[127; 128) 'C': C(usize) -> C [127; 131) 'C(1)': C [129; 130) '1': usize [139; 140) 'a': A diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap new file mode 100644 index 000000000..783795cfd --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_tuple_struct_generics.snap @@ -0,0 +1,23 @@ +--- +created: "2019-02-20T21:31:12.911275141Z" +creator: insta@0.6.2 +source: crates/ra_hir/src/ty/tests.rs +expression: "&result" +--- +[77; 185) '{ ...one; }': () +[83; 84) 'A': A(T) -> A +[83; 88) 'A(42)': A +[85; 87) '42': i32 +[94; 95) 'A': A(T) -> A +[94; 103) 'A(42u128)': A +[96; 102) '42u128': u128 +[109; 113) 'Some': Some<&str>(T) -> Option +[109; 118) 'Some("x")': Option<&str> +[114; 117) '"x"': &str +[124; 136) 'Option::Some': Some<&str>(T) -> Option +[124; 141) 'Option...e("x")': Option<&str> +[137; 140) '"x"': &str +[147; 151) 'None': Option<[unknown]> +[161; 162) 'x': Option +[178; 182) 'None': Option + diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 4ab442b8a..3affcb4fe 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -465,6 +465,27 @@ fn test(a1: A, i: i32) { ); } +#[test] +fn infer_tuple_struct_generics() { + check_inference( + "infer_tuple_struct_generics", + r#" +struct A(T); +enum Option { Some(T), None }; +use Option::*; + +fn test() { + A(42); + A(42u128); + Some("x"); + Option::Some("x"); + None; + let x: Option = None; +} +"#, + ); +} + #[test] fn infer_generics_in_patterns() { check_inference( -- cgit v1.2.3