From b79fd82559642f4fe504c0c382b86d57c666be1d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 18 Apr 2020 22:16:04 +0200 Subject: Correctly infer types in guard expressions The root cause was that we forgot to add bindings from the arm to the guard expression closes #3980 --- crates/ra_hir_ty/src/tests/patterns.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index 07cbc521a..6ea51d5d3 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs @@ -455,3 +455,29 @@ fn test() { "### ); } + +#[test] +fn infer_guard() { + assert_snapshot!( + infer(r#" +struct S; +impl S { fn foo(&self) -> bool { false } } + +fn main() { + match S { + s if s.foo() => (), + } +} + "#), @" + [28; 32) 'self': &S + [42; 51) '{ false }': bool + [44; 49) 'false': bool + [65; 116) '{ ... } }': () + [71; 114) 'match ... }': () + [77; 78) 'S': S + [89; 90) 's': S + [94; 95) 's': S + [94; 101) 's.foo()': bool + [105; 107) '()': () + ") +} -- cgit v1.2.3