diff options
author | Florian Diebold <[email protected]> | 2019-01-21 20:42:19 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-01-21 20:42:19 +0000 |
commit | e45f476d5691a6a0d994eb6f777bbf291348f93e (patch) | |
tree | e786aad9c46072c992c634466e834feb64c856fb /crates | |
parent | e0d8c86563b72e5414cf10fe16da5e88201447e2 (diff) |
Fix panic trying to get substs on unknown type
Fixes #585.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/bug_585.txt | 8 |
3 files changed, 27 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index c602450e1..e690ae158 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -1134,7 +1134,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1134 | 1134 | ||
1135 | self.unify(&ty, expected); | 1135 | self.unify(&ty, expected); |
1136 | 1136 | ||
1137 | let substs = ty.substs().expect("adt should have substs"); | 1137 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
1138 | 1138 | ||
1139 | for (i, &subpat) in subpats.iter().enumerate() { | 1139 | for (i, &subpat) in subpats.iter().enumerate() { |
1140 | let expected_ty = fields | 1140 | let expected_ty = fields |
@@ -1155,7 +1155,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1155 | 1155 | ||
1156 | self.unify(&ty, expected); | 1156 | self.unify(&ty, expected); |
1157 | 1157 | ||
1158 | let substs = ty.substs().expect("adt should have substs"); | 1158 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
1159 | 1159 | ||
1160 | for subpat in subpats { | 1160 | for subpat in subpats { |
1161 | let matching_field = fields.iter().find(|field| field.name() == &subpat.name); | 1161 | let matching_field = fields.iter().find(|field| field.name() == &subpat.name); |
@@ -1403,7 +1403,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1403 | spread, | 1403 | spread, |
1404 | } => { | 1404 | } => { |
1405 | let (ty, def_id) = self.resolve_variant(path.as_ref()); | 1405 | let (ty, def_id) = self.resolve_variant(path.as_ref()); |
1406 | let substs = ty.substs().expect("adt should have substs"); | 1406 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
1407 | for field in fields { | 1407 | for field in fields { |
1408 | let field_ty = if let Some(def_id) = def_id { | 1408 | let field_ty = if let Some(def_id) = def_id { |
1409 | self.db | 1409 | self.db |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 5aa24a29b..dc9b626dc 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -521,6 +521,22 @@ fn test(x: X) { | |||
521 | ); | 521 | ); |
522 | } | 522 | } |
523 | 523 | ||
524 | #[test] | ||
525 | fn bug_585() { | ||
526 | check_inference( | ||
527 | r#" | ||
528 | fn test() { | ||
529 | X {}; | ||
530 | match x { | ||
531 | A::B {} => (), | ||
532 | A::Y() => (), | ||
533 | } | ||
534 | } | ||
535 | "#, | ||
536 | "bug_585.txt", | ||
537 | ); | ||
538 | } | ||
539 | |||
524 | fn infer(content: &str) -> String { | 540 | fn infer(content: &str) -> String { |
525 | let (db, _, file_id) = MockDatabase::with_single_file(content); | 541 | let (db, _, file_id) = MockDatabase::with_single_file(content); |
526 | let source_file = db.source_file(file_id); | 542 | let source_file = db.source_file(file_id); |
diff --git a/crates/ra_hir/src/ty/tests/data/bug_585.txt b/crates/ra_hir/src/ty/tests/data/bug_585.txt new file mode 100644 index 000000000..627702a38 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/bug_585.txt | |||
@@ -0,0 +1,8 @@ | |||
1 | [11; 89) '{ ... } }': () | ||
2 | [17; 21) 'X {}': [unknown] | ||
3 | [27; 87) 'match ... }': () | ||
4 | [33; 34) 'x': [unknown] | ||
5 | [45; 52) 'A::B {}': [unknown] | ||
6 | [56; 58) '()': () | ||
7 | [68; 74) 'A::Y()': [unknown] | ||
8 | [78; 80) '()': () | ||