From 13cb4a1b370038dee51ae739a42d6b98acaef385 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Wed, 30 Jan 2019 21:14:26 +0100 Subject: Add test for passing on ref expectations --- crates/ra_hir/src/expr.rs | 8 ++++---- crates/ra_hir/src/ty/snapshots/tests__infer_array.snap | 14 ++++++++++---- crates/ra_hir/src/ty/tests.rs | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index b01d53e5c..f2d9af2ba 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -615,10 +615,10 @@ impl ExprCollector { .map(|arm| MatchArm { pats: arm.pats().map(|p| self.collect_pat(p)).collect(), expr: self.collect_expr_opt(arm.expr()), - guard: arm.guard().map(|guard| { - let e = guard.expr().expect("every guard should have an expr"); - self.collect_expr(e) - }), + guard: arm + .guard() + .and_then(|guard| guard.expr()) + .map(|e| self.collect_expr(e)), }) .collect() } else { diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_array.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_array.snap index 3f2faa598..042248c35 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_array.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_array.snap @@ -1,12 +1,12 @@ --- -created: "2019-01-22T14:44:59.880187500+00:00" -creator: insta@0.4.0 +created: "2019-01-30T20:08:05.185312835+00:00" +creator: insta@0.5.2 expression: "&result" -source: "crates\\ra_hir\\src\\ty\\tests.rs" +source: crates/ra_hir/src/ty/tests.rs --- [9; 10) 'x': &str [18; 19) 'y': isize -[28; 293) '{ ... []; }': () +[28; 324) '{ ... 3]; }': () [38; 39) 'a': [&str] [42; 45) '[x]': [&str] [43; 44) 'x': &str @@ -56,4 +56,10 @@ source: "crates\\ra_hir\\src\\ty\\tests.rs" [260; 263) '"b"': &str [275; 276) 'x': [u8] [288; 290) '[]': [u8] +[300; 301) 'z': &[u8] +[311; 321) '&[1, 2, 3]': &[u8] +[312; 321) '[1, 2, 3]': [u8] +[313; 314) '1': u8 +[316; 317) '2': u8 +[319; 320) '3': u8 diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 8aa188059..812d1238c 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -366,6 +366,7 @@ fn test(x: &str, y: isize) { let b = [a, ["b"]]; let x: [u8; 0] = []; + let z: &[u8] = &[1, 2, 3]; } "#, ); -- cgit v1.2.3