diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index bf423d3d88..b30e11abb7 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 0000000000..fb31883ce8 --- /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 e0b5a64717..e088df97c4 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);