mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Merge #7386
7386: Handle box with allocator r=flodiebold a=tweksteen
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] f288cd2e17
Fixes: #6956
Co-authored-by: Thiébaud Weksteen <tweek@google.com>
This commit is contained in:
commit
c050e972a3
2 changed files with 28 additions and 1 deletions
|
@ -491,7 +491,10 @@ impl<'a> InferenceContext<'a> {
|
||||||
Expr::Box { expr } => {
|
Expr::Box { expr } => {
|
||||||
let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
|
let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
|
||||||
if let Some(box_) = self.resolve_boxed_box() {
|
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 {
|
} else {
|
||||||
Ty::Unknown
|
Ty::Unknown
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<i32, {unknown}>, Box<Box<i32, {unknown}>, {unknown}>, Box<&i32, {unknown}>, Box<[i32; _], {unknown}>)
|
||||||
|
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[prelude_import] use prelude::*;
|
||||||
|
mod boxed {
|
||||||
|
#[lang = "owned_box"]
|
||||||
|
pub struct Box<T: ?Sized, A: Allocator> {
|
||||||
|
inner: *mut T,
|
||||||
|
allocator: A,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn infer_adt_self() {
|
fn infer_adt_self() {
|
||||||
check_types(
|
check_types(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue