From 8c078a01641518a6b093922d4b1d27d1a98bad08 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Wed, 11 Sep 2019 23:53:41 +0800 Subject: Infer box expression --- crates/ra_hir/src/ty/infer.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'crates/ra_hir/src/ty/infer.rs') 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> { let inner_ty = self.infer_expr(*expr, &expectation); Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty) } + Expr::Box { expr } => { + let inner_ty = self.infer_expr(*expr, &Expectation::none()); + if let Some(box_) = self.resolve_boxed_box() { + Ty::apply_one(TypeCtor::Adt(box_), inner_ty) + } else { + Ty::Unknown + } + } Expr::UnaryOp { expr, op } => { let inner_ty = self.infer_expr(*expr, &Expectation::none()); match op { @@ -1499,6 +1507,24 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { _ => None, } } + + fn resolve_boxed_box(&self) -> Option { + let boxed_box_path = Path { + kind: PathKind::Abs, + segments: vec![ + PathSegment { name: name::STD, args_and_bindings: None }, + PathSegment { name: name::BOXED_MOD, args_and_bindings: None }, + PathSegment { name: name::BOX_TYPE, args_and_bindings: None }, + ], + }; + + match self.resolver.resolve_path_segments(self.db, &boxed_box_path).into_fully_resolved() { + PerNs { types: Some(Def(ModuleDef::Struct(struct_))), .. } => { + Some(AdtDef::Struct(struct_)) + } + _ => None, + } + } } /// The ID of a type variable. -- cgit v1.2.3