Fix another crash found when analyzing rustc

This commit is contained in:
Florian Diebold 2019-02-09 20:55:51 +01:00
parent f1afc93353
commit c0c3b37255
3 changed files with 38 additions and 7 deletions

View file

@ -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);

View file

@ -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) '{}': ()

View file

@ -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);