diff options
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 5 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/simple.rs | 24 |
2 files changed, 28 insertions, 1 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 9bf3b51b0..d7351d212 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -491,7 +491,10 @@ impl<'a> InferenceContext<'a> { | |||
491 | Expr::Box { expr } => { | 491 | Expr::Box { expr } => { |
492 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); | 492 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); |
493 | if let Some(box_) = self.resolve_boxed_box() { | 493 | if let Some(box_) = self.resolve_boxed_box() { |
494 | Ty::apply_one(TypeCtor::Adt(box_), inner_ty) | 494 | let mut sb = Substs::build_for_type_ctor(self.db, TypeCtor::Adt(box_)); |
495 | sb = sb.push(inner_ty); | ||
496 | sb = sb.fill(repeat_with(|| self.table.new_type_var())); | ||
497 | Ty::apply(TypeCtor::Adt(box_), sb.build()) | ||
495 | } else { | 498 | } else { |
496 | Ty::Unknown | 499 | Ty::Unknown |
497 | } | 500 | } |
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index 8d431b920..16682f76f 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs | |||
@@ -29,6 +29,30 @@ mod boxed { | |||
29 | } | 29 | } |
30 | 30 | ||
31 | #[test] | 31 | #[test] |
32 | fn infer_box_with_allocator() { | ||
33 | check_types( | ||
34 | r#" | ||
35 | //- /main.rs crate:main deps:std | ||
36 | fn test() { | ||
37 | let x = box 1; | ||
38 | let t = (x, box x, box &1, box [1]); | ||
39 | t; | ||
40 | } //^ (Box<i32, {unknown}>, Box<Box<i32, {unknown}>, {unknown}>, Box<&i32, {unknown}>, Box<[i32; _], {unknown}>) | ||
41 | |||
42 | //- /std.rs crate:std | ||
43 | #[prelude_import] use prelude::*; | ||
44 | mod boxed { | ||
45 | #[lang = "owned_box"] | ||
46 | pub struct Box<T: ?Sized, A: Allocator> { | ||
47 | inner: *mut T, | ||
48 | allocator: A, | ||
49 | } | ||
50 | } | ||
51 | "#, | ||
52 | ); | ||
53 | } | ||
54 | |||
55 | #[test] | ||
32 | fn infer_adt_self() { | 56 | fn infer_adt_self() { |
33 | check_types( | 57 | check_types( |
34 | r#" | 58 | r#" |