Skip to content

Commit c770397

Browse files
committed
rustc: remove an assortment of Box<T> special-cases.
1 parent 77e189c commit c770397

File tree

8 files changed

+17
-46
lines changed

8 files changed

+17
-46
lines changed

src/librustc_const_eval/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>,
853853
ty::TyAdt(adt, substs) => {
854854
if adt.is_box() {
855855
// Use T as the sub pattern type of Box<T>.
856-
vec![substs[0].as_type().unwrap()]
856+
vec![ty.boxed_ty()]
857857
} else {
858858
adt.variants[ctor.variant_index_for_adt(adt)].fields.iter().map(|field| {
859859
let is_visible = adt.is_enum()

src/librustc_mir/monomorphize/collector.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,6 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
823823
&ty::TyRawPtr(ty::TypeAndMut { ty: b, .. })) => {
824824
ptr_vtable(a, b)
825825
}
826-
(&ty::TyAdt(def_a, _), &ty::TyAdt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
827-
ptr_vtable(source_ty.boxed_ty(), target_ty.boxed_ty())
828-
}
829826

830827
(&ty::TyAdt(source_adt_def, source_substs),
831828
&ty::TyAdt(target_adt_def, target_substs)) => {

src/librustc_trans/base.rs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,6 @@ pub fn unsize_thin_ptr<'a, 'tcx>(
236236
let ptr_ty = bcx.ccx.layout_of(b).llvm_type(bcx.ccx).ptr_to();
237237
(bcx.pointercast(src, ptr_ty), unsized_info(bcx.ccx, a, b, None))
238238
}
239-
(&ty::TyAdt(def_a, _), &ty::TyAdt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
240-
let (a, b) = (src_ty.boxed_ty(), dst_ty.boxed_ty());
241-
assert!(bcx.ccx.shared().type_is_sized(a));
242-
let ptr_ty = bcx.ccx.layout_of(b).llvm_type(bcx.ccx).ptr_to();
243-
(bcx.pointercast(src, ptr_ty), unsized_info(bcx.ccx, a, b, None))
244-
}
245239
(&ty::TyAdt(def_a, _), &ty::TyAdt(def_b, _)) => {
246240
assert_eq!(def_a, def_b);
247241

@@ -278,31 +272,25 @@ pub fn coerce_unsized_into<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
278272
dst: PlaceRef<'tcx>) {
279273
let src_ty = src.layout.ty;
280274
let dst_ty = dst.layout.ty;
281-
let coerce_ptr = || {
282-
let (base, info) = match src.load(bcx).val {
283-
OperandValue::Pair(base, info) => {
284-
// fat-ptr to fat-ptr unsize preserves the vtable
285-
// i.e. &'a fmt::Debug+Send => &'a fmt::Debug
286-
// So we need to pointercast the base to ensure
287-
// the types match up.
288-
let thin_ptr = dst.layout.field(bcx.ccx, abi::FAT_PTR_ADDR);
289-
(bcx.pointercast(base, thin_ptr.llvm_type(bcx.ccx)), info)
290-
}
291-
OperandValue::Immediate(base) => {
292-
unsize_thin_ptr(bcx, base, src_ty, dst_ty)
293-
}
294-
OperandValue::Ref(..) => bug!()
295-
};
296-
OperandValue::Pair(base, info).store(bcx, dst);
297-
};
298275
match (&src_ty.sty, &dst_ty.sty) {
299276
(&ty::TyRef(..), &ty::TyRef(..)) |
300277
(&ty::TyRef(..), &ty::TyRawPtr(..)) |
301278
(&ty::TyRawPtr(..), &ty::TyRawPtr(..)) => {
302-
coerce_ptr()
303-
}
304-
(&ty::TyAdt(def_a, _), &ty::TyAdt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
305-
coerce_ptr()
279+
let (base, info) = match src.load(bcx).val {
280+
OperandValue::Pair(base, info) => {
281+
// fat-ptr to fat-ptr unsize preserves the vtable
282+
// i.e. &'a fmt::Debug+Send => &'a fmt::Debug
283+
// So we need to pointercast the base to ensure
284+
// the types match up.
285+
let thin_ptr = dst.layout.field(bcx.ccx, abi::FAT_PTR_ADDR);
286+
(bcx.pointercast(base, thin_ptr.llvm_type(bcx.ccx)), info)
287+
}
288+
OperandValue::Immediate(base) => {
289+
unsize_thin_ptr(bcx, base, src_ty, dst_ty)
290+
}
291+
OperandValue::Ref(..) => bug!()
292+
};
293+
OperandValue::Pair(base, info).store(bcx, dst);
306294
}
307295

308296
(&ty::TyAdt(def_a, _), &ty::TyAdt(def_b, _)) => {

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,6 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
558558
Err(metadata) => return metadata,
559559
}
560560
}
561-
ty::TyAdt(def, _) if def.is_box() => {
562-
match ptr_metadata(t.boxed_ty()) {
563-
Ok(res) => res,
564-
Err(metadata) => return metadata,
565-
}
566-
}
567561
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
568562
let fn_metadata = subroutine_type_metadata(cx,
569563
unique_type_id,

src/librustc_trans/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
431431
// Only "class" methods are generally understood by LLVM,
432432
// so avoid methods on other types (e.g. `<*mut T>::null`).
433433
match impl_self_ty.sty {
434-
ty::TyAdt(def, ..) if !def.is_box() => {
434+
ty::TyAdt(..) => {
435435
Some(type_metadata(cx, impl_self_ty, syntax_pos::DUMMY_SP))
436436
}
437437
_ => None

src/librustc_typeck/check/regionck.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,6 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
713713
self.type_must_outlive(infer::RelateObjectBound(cast_expr.span), from_ty, r);
714714
}
715715

716-
/*From:*/ (&ty::TyAdt(from_def, _),
717-
/*To: */ &ty::TyAdt(to_def, _)) if from_def.is_box() && to_def.is_box() => {
718-
self.walk_cast(cast_expr, from_ty.boxed_ty(), to_ty.boxed_ty());
719-
}
720-
721716
_ => { }
722717
}
723718
}

src/test/compile-fail/regions-close-object-into-object-5.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
3030
//~| ERROR the parameter type `T` may not live long enough
3131
//~| ERROR the parameter type `T` may not live long enough
3232
//~| ERROR the parameter type `T` may not live long enough
33-
//~| ERROR the parameter type `T` may not live long enough
3433
}
3534

3635
fn main() {}

src/test/compile-fail/regions-close-over-type-parameter-1.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ trait SomeTrait { fn get(&self) -> isize; }
1919
fn make_object1<A:SomeTrait>(v: A) -> Box<SomeTrait+'static> {
2020
box v as Box<SomeTrait+'static>
2121
//~^ ERROR the parameter type `A` may not live long enough
22-
//~| ERROR the parameter type `A` may not live long enough
2322
}
2423

2524
fn make_object2<'a,A:SomeTrait+'a>(v: A) -> Box<SomeTrait+'a> {
@@ -29,7 +28,6 @@ fn make_object2<'a,A:SomeTrait+'a>(v: A) -> Box<SomeTrait+'a> {
2928
fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box<SomeTrait+'b> {
3029
box v as Box<SomeTrait+'b>
3130
//~^ ERROR the parameter type `A` may not live long enough
32-
//~| ERROR the parameter type `A` may not live long enough
3331
}
3432

3533
fn main() { }

0 commit comments

Comments
 (0)