mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
hir_ty: use default type generic for box expressions
This commit is contained in:
parent
23d7dbfa5e
commit
2cdd1ff1b5
2 changed files with 61 additions and 0 deletions
|
@ -488,6 +488,12 @@ impl<'a> InferenceContext<'a> {
|
||||||
if let Some(box_) = self.resolve_boxed_box() {
|
if let Some(box_) = self.resolve_boxed_box() {
|
||||||
let mut sb = Substs::builder(generics(self.db.upcast(), box_.into()).len());
|
let mut sb = Substs::builder(generics(self.db.upcast(), box_.into()).len());
|
||||||
sb = sb.push(inner_ty);
|
sb = sb.push(inner_ty);
|
||||||
|
match self.db.generic_defaults(box_.into()).as_ref() {
|
||||||
|
[_, alloc_ty, ..] if !alloc_ty.value.is_unknown() => {
|
||||||
|
sb = sb.push(alloc_ty.value.clone());
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
sb = sb.fill(repeat_with(|| self.table.new_type_var()));
|
sb = sb.fill(repeat_with(|| self.table.new_type_var()));
|
||||||
Ty::Adt(box_, sb.build())
|
Ty::Adt(box_, sb.build())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2491,3 +2491,58 @@ fn inner_use_enum_rename() {
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn box_into_vec() {
|
||||||
|
check_infer(
|
||||||
|
r#"
|
||||||
|
#[lang = "sized"]
|
||||||
|
pub trait Sized {}
|
||||||
|
|
||||||
|
#[lang = "unsize"]
|
||||||
|
pub trait Unsize<T: ?Sized> {}
|
||||||
|
|
||||||
|
#[lang = "coerce_unsized"]
|
||||||
|
pub trait CoerceUnsized<T> {}
|
||||||
|
|
||||||
|
pub unsafe trait Allocator {}
|
||||||
|
|
||||||
|
pub struct Global;
|
||||||
|
unsafe impl Allocator for Global {}
|
||||||
|
|
||||||
|
#[lang = "owned_box"]
|
||||||
|
#[fundamental]
|
||||||
|
pub struct Box<T: ?Sized, A: Allocator = Global>;
|
||||||
|
|
||||||
|
impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
|
||||||
|
|
||||||
|
pub struct Vec<T, A: Allocator = Global> {}
|
||||||
|
|
||||||
|
#[lang = "slice"]
|
||||||
|
impl<T> [T] {}
|
||||||
|
|
||||||
|
#[lang = "slice_alloc"]
|
||||||
|
impl<T> [T] {
|
||||||
|
pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test() {
|
||||||
|
let vec = <[_]>::into_vec(box [1i32]);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
569..573 'self': Box<[T], A>
|
||||||
|
602..634 '{ ... }': Vec<T, A>
|
||||||
|
612..628 'unimpl...ted!()': Vec<T, A>
|
||||||
|
648..694 '{ ...2]); }': ()
|
||||||
|
658..661 'vec': Vec<i32, Global>
|
||||||
|
664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
|
||||||
|
664..691 '<[_]>:...1i32])': Vec<i32, Global>
|
||||||
|
680..690 'box [1i32]': Box<[i32; _], Global>
|
||||||
|
684..690 '[1i32]': [i32; _]
|
||||||
|
685..689 '1i32': i32
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue