From be0691b02bd739310f6d6518dc10f01b9a692598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= Date: Fri, 22 Jan 2021 11:17:45 +0100 Subject: Handle box with allocator In 1.49.0, the definition of Box was modified to support an optional Allocator[1]. Adapt the parsing of the `box` keyword to supply the expected number of parameters to the constructor. [1] https://github.com/rust-lang/rust/commit/f288cd2e179f600fa00c2a407206a12f6c5a91e0 --- crates/hir_ty/src/infer/expr.rs | 5 ++++- crates/hir_ty/src/tests/simple.rs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'crates') 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> { Expr::Box { expr } => { let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); if let Some(box_) = self.resolve_boxed_box() { - Ty::apply_one(TypeCtor::Adt(box_), inner_ty) + let mut sb = Substs::build_for_type_ctor(self.db, TypeCtor::Adt(box_)); + sb = sb.push(inner_ty); + sb = sb.fill(repeat_with(|| self.table.new_type_var())); + Ty::apply(TypeCtor::Adt(box_), sb.build()) } else { Ty::Unknown } 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 @@ -28,6 +28,30 @@ mod boxed { ); } +#[test] +fn infer_box_with_allocator() { + check_types( + r#" +//- /main.rs crate:main deps:std +fn test() { + let x = box 1; + let t = (x, box x, box &1, box [1]); + t; +} //^ (Box, Box, {unknown}>, Box<&i32, {unknown}>, Box<[i32; _], {unknown}>) + +//- /std.rs crate:std +#[prelude_import] use prelude::*; +mod boxed { + #[lang = "owned_box"] + pub struct Box { + inner: *mut T, + allocator: A, + } +} +"#, + ); +} + #[test] fn infer_adt_self() { check_types( -- cgit v1.2.3