aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/infer.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-12 11:53:29 +0100
committerGitHub <[email protected]>2019-09-12 11:53:29 +0100
commita1261631a89f7169a3f84dec33aff61758c601e3 (patch)
tree773c687fe89b8cec009de17142b3a59e80468b21 /crates/ra_hir/src/ty/infer.rs
parent561e7aea5bdaf6c51e0a87da9ff1d73e2df52be1 (diff)
parent8c078a01641518a6b093922d4b1d27d1a98bad08 (diff)
Merge #1818
1818: Infer box expression r=matklad a=uHOOCCOOHu Infer `box e` to be `std::boxed::Box<T>` where `e: T` Co-authored-by: uHOOCCOOHu <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r--crates/ra_hir/src/ty/infer.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 9244ff3cb..1057bbbec 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -1259,6 +1259,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1259 let inner_ty = self.infer_expr(*expr, &expectation); 1259 let inner_ty = self.infer_expr(*expr, &expectation);
1260 Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty) 1260 Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty)
1261 } 1261 }
1262 Expr::Box { expr } => {
1263 let inner_ty = self.infer_expr(*expr, &Expectation::none());
1264 if let Some(box_) = self.resolve_boxed_box() {
1265 Ty::apply_one(TypeCtor::Adt(box_), inner_ty)
1266 } else {
1267 Ty::Unknown
1268 }
1269 }
1262 Expr::UnaryOp { expr, op } => { 1270 Expr::UnaryOp { expr, op } => {
1263 let inner_ty = self.infer_expr(*expr, &Expectation::none()); 1271 let inner_ty = self.infer_expr(*expr, &Expectation::none());
1264 match op { 1272 match op {
@@ -1499,6 +1507,24 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1499 _ => None, 1507 _ => None,
1500 } 1508 }
1501 } 1509 }
1510
1511 fn resolve_boxed_box(&self) -> Option<AdtDef> {
1512 let boxed_box_path = Path {
1513 kind: PathKind::Abs,
1514 segments: vec![
1515 PathSegment { name: name::STD, args_and_bindings: None },
1516 PathSegment { name: name::BOXED_MOD, args_and_bindings: None },
1517 PathSegment { name: name::BOX_TYPE, args_and_bindings: None },
1518 ],
1519 };
1520
1521 match self.resolver.resolve_path_segments(self.db, &boxed_box_path).into_fully_resolved() {
1522 PerNs { types: Some(Def(ModuleDef::Struct(struct_))), .. } => {
1523 Some(AdtDef::Struct(struct_))
1524 }
1525 _ => None,
1526 }
1527 }
1502} 1528}
1503 1529
1504/// The ID of a type variable. 1530/// The ID of a type variable.