mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
Merge #586
586: Fix panic trying to get substs on unknown type r=matklad a=flodiebold Fixes #585. Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
commit
0d2cb60f93
3 changed files with 27 additions and 3 deletions
|
@ -1134,7 +1134,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
|
||||
self.unify(&ty, expected);
|
||||
|
||||
let substs = ty.substs().expect("adt should have substs");
|
||||
let substs = ty.substs().unwrap_or_else(Substs::empty);
|
||||
|
||||
for (i, &subpat) in subpats.iter().enumerate() {
|
||||
let expected_ty = fields
|
||||
|
@ -1155,7 +1155,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
|
||||
self.unify(&ty, expected);
|
||||
|
||||
let substs = ty.substs().expect("adt should have substs");
|
||||
let substs = ty.substs().unwrap_or_else(Substs::empty);
|
||||
|
||||
for subpat in subpats {
|
||||
let matching_field = fields.iter().find(|field| field.name() == &subpat.name);
|
||||
|
@ -1403,7 +1403,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
spread,
|
||||
} => {
|
||||
let (ty, def_id) = self.resolve_variant(path.as_ref());
|
||||
let substs = ty.substs().expect("adt should have substs");
|
||||
let substs = ty.substs().unwrap_or_else(Substs::empty);
|
||||
for field in fields {
|
||||
let field_ty = if let Some(def_id) = def_id {
|
||||
self.db
|
||||
|
|
|
@ -521,6 +521,22 @@ fn test(x: X) {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bug_585() {
|
||||
check_inference(
|
||||
r#"
|
||||
fn test() {
|
||||
X {};
|
||||
match x {
|
||||
A::B {} => (),
|
||||
A::Y() => (),
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"bug_585.txt",
|
||||
);
|
||||
}
|
||||
|
||||
fn infer(content: &str) -> String {
|
||||
let (db, _, file_id) = MockDatabase::with_single_file(content);
|
||||
let source_file = db.source_file(file_id);
|
||||
|
|
8
crates/ra_hir/src/ty/tests/data/bug_585.txt
Normal file
8
crates/ra_hir/src/ty/tests/data/bug_585.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
[11; 89) '{ ... } }': ()
|
||||
[17; 21) 'X {}': [unknown]
|
||||
[27; 87) 'match ... }': ()
|
||||
[33; 34) 'x': [unknown]
|
||||
[45; 52) 'A::B {}': [unknown]
|
||||
[56; 58) '()': ()
|
||||
[68; 74) 'A::Y()': [unknown]
|
||||
[78; 80) '()': ()
|
Loading…
Reference in a new issue