diff options
author | Florian Diebold <[email protected]> | 2019-02-09 19:55:51 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-02-09 20:37:30 +0000 |
commit | c0c3b37255423b3547614d74311c4193c0717b56 (patch) | |
tree | 1727ab1e847dff6142d7b596793a8be4417b5aa0 /crates/ra_hir | |
parent | f1afc933530a87bd0cc7b25726c9a7fff3f3e007 (diff) |
Fix another crash found when analyzing rustc
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_4.snap | 16 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 15 |
3 files changed, 38 insertions, 7 deletions
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 { | |||
831 | p.field_pat_list().expect("every struct should have a field list"); | 831 | p.field_pat_list().expect("every struct should have a field list"); |
832 | let mut fields: Vec<_> = field_pat_list | 832 | let mut fields: Vec<_> = field_pat_list |
833 | .bind_pats() | 833 | .bind_pats() |
834 | .map(|bind_pat| { | 834 | .filter_map(|bind_pat| { |
835 | let ast_pat = ast::Pat::cast(bind_pat.syntax()).expect("bind pat is a pat"); | 835 | let ast_pat = ast::Pat::cast(bind_pat.syntax()).expect("bind pat is a pat"); |
836 | let pat = self.collect_pat(ast_pat); | 836 | let pat = self.collect_pat(ast_pat); |
837 | let name = bind_pat.name().expect("bind pat has a name").as_name(); | 837 | let name = bind_pat.name()?.as_name(); |
838 | FieldPat { name, pat } | 838 | Some(FieldPat { name, pat }) |
839 | }) | 839 | }) |
840 | .collect(); | 840 | .collect(); |
841 | let iter = field_pat_list.field_pats().map(|f| { | 841 | let iter = field_pat_list.field_pats().filter_map(|f| { |
842 | let ast_pat = f.pat().expect("field pat always contains a pattern"); | 842 | let ast_pat = f.pat()?; |
843 | let pat = self.collect_pat(ast_pat); | 843 | let pat = self.collect_pat(ast_pat); |
844 | let name = f.name().expect("field pats always have a name").as_name(); | 844 | let name = f.name()?.as_name(); |
845 | FieldPat { name, pat } | 845 | Some(FieldPat { name, pat }) |
846 | }); | 846 | }); |
847 | fields.extend(iter); | 847 | fields.extend(iter); |
848 | 848 | ||
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 @@ | |||
1 | --- | ||
2 | created: "2019-02-09T19:55:39.712470520Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_hir/src/ty/tests.rs | ||
5 | expression: "&result" | ||
6 | --- | ||
7 | [25; 110) '{ ... } }': () | ||
8 | [31; 108) 'match ... }': () | ||
9 | [37; 42) '*self': [unknown] | ||
10 | [38; 42) 'self': [unknown] | ||
11 | [53; 95) 'Borrow...), ..}': [unknown] | ||
12 | [74; 77) 'box': [unknown] | ||
13 | [78; 87) 'Primitive': [unknown] | ||
14 | [88; 89) 'p': [unknown] | ||
15 | [99; 101) '{}': () | ||
16 | |||
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() { | |||
678 | ); | 678 | ); |
679 | } | 679 | } |
680 | 680 | ||
681 | #[test] | ||
682 | fn infer_std_crash_4() { | ||
683 | // taken from rustc | ||
684 | check_inference( | ||
685 | "infer_std_crash_4", | ||
686 | r#" | ||
687 | pub fn primitive_type() { | ||
688 | match *self { | ||
689 | BorrowedRef { type_: box Primitive(p), ..} => {}, | ||
690 | } | ||
691 | } | ||
692 | "#, | ||
693 | ); | ||
694 | } | ||
695 | |||
681 | fn infer(content: &str) -> String { | 696 | fn infer(content: &str) -> String { |
682 | let (db, _, file_id) = MockDatabase::with_single_file(content); | 697 | let (db, _, file_id) = MockDatabase::with_single_file(content); |
683 | let source_file = db.parse(file_id); | 698 | let source_file = db.parse(file_id); |