From c0c3b37255423b3547614d74311c4193c0717b56 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 9 Feb 2019 20:55:51 +0100 Subject: Fix another crash found when analyzing rustc --- crates/ra_hir/src/expr.rs | 14 +++++++------- .../src/ty/snapshots/tests__infer_std_crash_4.snap | 16 ++++++++++++++++ crates/ra_hir/src/ty/tests.rs | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_4.snap (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index bf423d3d8..b30e11abb 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -831,18 +831,18 @@ impl ExprCollector { p.field_pat_list().expect("every struct should have a field list"); let mut fields: Vec<_> = field_pat_list .bind_pats() - .map(|bind_pat| { + .filter_map(|bind_pat| { let ast_pat = ast::Pat::cast(bind_pat.syntax()).expect("bind pat is a pat"); let pat = self.collect_pat(ast_pat); - let name = bind_pat.name().expect("bind pat has a name").as_name(); - FieldPat { name, pat } + let name = bind_pat.name()?.as_name(); + Some(FieldPat { name, pat }) }) .collect(); - let iter = field_pat_list.field_pats().map(|f| { - let ast_pat = f.pat().expect("field pat always contains a pattern"); + let iter = field_pat_list.field_pats().filter_map(|f| { + let ast_pat = f.pat()?; let pat = self.collect_pat(ast_pat); - let name = f.name().expect("field pats always have a name").as_name(); - FieldPat { name, pat } + let name = f.name()?.as_name(); + Some(FieldPat { name, pat }) }); fields.extend(iter); diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_4.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_4.snap new file mode 100644 index 000000000..fb31883ce --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_4.snap @@ -0,0 +1,16 @@ +--- +created: "2019-02-09T19:55:39.712470520Z" +creator: insta@0.6.1 +source: crates/ra_hir/src/ty/tests.rs +expression: "&result" +--- +[25; 110) '{ ... } }': () +[31; 108) 'match ... }': () +[37; 42) '*self': [unknown] +[38; 42) 'self': [unknown] +[53; 95) 'Borrow...), ..}': [unknown] +[74; 77) 'box': [unknown] +[78; 87) 'Primitive': [unknown] +[88; 89) 'p': [unknown] +[99; 101) '{}': () + diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index e0b5a6471..e088df97c 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -678,6 +678,21 @@ pub fn compute() { ); } +#[test] +fn infer_std_crash_4() { + // taken from rustc + check_inference( + "infer_std_crash_4", + r#" +pub fn primitive_type() { + match *self { + BorrowedRef { type_: box Primitive(p), ..} => {}, + } +} +"#, + ); +} + fn infer(content: &str) -> String { let (db, _, file_id) = MockDatabase::with_single_file(content); let source_file = db.parse(file_id); -- cgit v1.2.3