From ccfc6b11c1e55e28e42bb79414d8349e8eb36086 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 16 Feb 2019 20:29:36 +0100 Subject: [PATCH] Add a test for impl generics --- .../snapshots/tests__infer_impl_generics.snap | 39 +++++++++++++++++++ crates/ra_hir/src/ty/tests.rs | 32 +++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics.snap diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics.snap new file mode 100644 index 0000000000..99df39fc2f --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_impl_generics.snap @@ -0,0 +1,39 @@ +--- +created: "2019-02-16T19:27:11.573533475Z" +creator: insta@0.6.2 +source: crates/ra_hir/src/ty/tests.rs +expression: "&result" +--- +[74; 78) 'self': A<[unknown], [unknown]> +[85; 107) '{ ... }': [unknown] +[95; 99) 'self': A<[unknown], [unknown]> +[95; 101) 'self.x': [unknown] +[117; 121) 'self': A<[unknown], [unknown]> +[128; 150) '{ ... }': [unknown] +[138; 142) 'self': A<[unknown], [unknown]> +[138; 144) 'self.y': [unknown] +[163; 167) 'self': A<[unknown], [unknown]> +[169; 170) 't': T +[188; 223) '{ ... }': ([unknown], [unknown], T) +[198; 217) '(self.....y, t)': ([unknown], [unknown], T) +[199; 203) 'self': A<[unknown], [unknown]> +[199; 205) 'self.x': [unknown] +[207; 211) 'self': A<[unknown], [unknown]> +[207; 213) 'self.y': [unknown] +[215; 216) 't': T +[245; 342) '{ ...(1); }': () +[255; 256) 'a': A +[259; 281) 'A { x:...1i64 }': A +[266; 270) '1u64': u64 +[275; 279) '1i64': i64 +[287; 288) 'a': A +[287; 292) 'a.x()': [unknown] +[298; 299) 'a': A +[298; 303) 'a.y()': [unknown] +[309; 310) 'a': A +[309; 319) 'a.z(1i128)': ([unknown], [unknown], i128) +[313; 318) '1i128': i128 +[325; 326) 'a': A +[325; 339) 'a.z::(1)': ([unknown], [unknown], i32) +[337; 338) '1': i32 + diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 203f1fe4d0..1eca68dc54 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -506,6 +506,38 @@ fn test() { ); } +#[test] +fn infer_impl_generics() { + check_inference( + "infer_impl_generics", + r#" +struct A { + x: T1, + y: T2, +} +impl A { + fn x(self) -> X { + self.x + } + fn y(self) -> Y { + self.y + } + fn z(self, t: T) -> (X, Y, T) { + (self.x, self.y, t) + } +} + +fn test() -> i128 { + let a = A { x: 1u64, y: 1i64 }; + a.x(); + a.y(); + a.z(1i128); + a.z::(1); +} +"#, + ); +} + #[test] fn infer_generic_chain() { check_inference(