mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Implement box pattern inference
This commit is contained in:
parent
2de6eb7bc8
commit
07a704e31c
3 changed files with 20 additions and 2 deletions
|
@ -209,6 +209,18 @@ impl<'a> InferenceContext<'a> {
|
|||
end_ty
|
||||
}
|
||||
Pat::Lit(expr) => self.infer_expr(*expr, &Expectation::has_type(expected.clone())),
|
||||
Pat::Box { inner } => match self.resolve_boxed_box() {
|
||||
Some(box_adt) => {
|
||||
let inner_expected = match expected.as_adt() {
|
||||
Some((adt, substs)) if adt == box_adt => substs.as_single(),
|
||||
_ => &Ty::Unknown,
|
||||
};
|
||||
|
||||
let inner_ty = self.infer_pat(*inner, inner_expected, default_bm);
|
||||
Ty::apply_one(TypeCtor::Adt(box_adt), inner_ty)
|
||||
}
|
||||
None => Ty::Unknown,
|
||||
},
|
||||
Pat::Missing => Ty::Unknown,
|
||||
};
|
||||
// use a new type variable if we got Ty::Unknown here
|
||||
|
@ -236,6 +248,6 @@ fn is_non_ref_pat(body: &hir_def::body::Body, pat: PatId) -> bool {
|
|||
Expr::Literal(Literal::String(..)) => false,
|
||||
_ => true,
|
||||
},
|
||||
Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Missing => false,
|
||||
Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Box { .. } | Pat::Missing => false,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue