Skip to content

Commit ffba0ce

Browse files
committed
Merge ty::TyBox into ty::TyAdt
1 parent 55f9712 commit ffba0ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+315
-345
lines changed

src/liballoc/boxed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub struct ExchangeHeapSingleton {
103103
///
104104
/// See the [module-level documentation](../../std/boxed/index.html) for more.
105105
#[lang = "owned_box"]
106+
#[fundamental]
106107
#[stable(feature = "rust1", since = "1.0.0")]
107108
pub struct Box<T: ?Sized>(Unique<T>);
108109

src/librustc/infer/freshen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
156156
ty::TyUint(..) |
157157
ty::TyFloat(..) |
158158
ty::TyAdt(..) |
159-
ty::TyBox(..) |
160159
ty::TyStr |
161160
ty::TyError |
162161
ty::TyArray(..) |

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
961961
-> cmt<'tcx>
962962
{
963963
let ptr = match base_cmt.ty.sty {
964-
ty::TyBox(..) => Unique,
964+
ty::TyAdt(def, ..) if def.is_box() => Unique,
965965
ty::TyRawPtr(ref mt) => UnsafePtr(mt.mutbl),
966966
ty::TyRef(r, mt) => {
967967
let bk = ty::BorrowKind::from_mutbl(mt.mutbl);

src/librustc/traits/coherence.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn orphan_check_trait_ref<'tcx>(tcx: TyCtxt,
199199

200200
fn uncovered_tys<'tcx>(tcx: TyCtxt, ty: Ty<'tcx>, infer_is_local: InferIsLocal)
201201
-> Vec<Ty<'tcx>> {
202-
if ty_is_local_constructor(tcx, ty, infer_is_local) {
202+
if ty_is_local_constructor(ty, infer_is_local) {
203203
vec![]
204204
} else if fundamental_ty(tcx, ty) {
205205
ty.walk_shallow()
@@ -219,13 +219,13 @@ fn is_type_parameter(ty: Ty) -> bool {
219219
}
220220

221221
fn ty_is_local(tcx: TyCtxt, ty: Ty, infer_is_local: InferIsLocal) -> bool {
222-
ty_is_local_constructor(tcx, ty, infer_is_local) ||
222+
ty_is_local_constructor(ty, infer_is_local) ||
223223
fundamental_ty(tcx, ty) && ty.walk_shallow().any(|t| ty_is_local(tcx, t, infer_is_local))
224224
}
225225

226226
fn fundamental_ty(tcx: TyCtxt, ty: Ty) -> bool {
227227
match ty.sty {
228-
ty::TyBox(..) | ty::TyRef(..) => true,
228+
ty::TyRef(..) => true,
229229
ty::TyAdt(def, _) => def.is_fundamental(),
230230
ty::TyDynamic(ref data, ..) => {
231231
data.principal().map_or(false, |p| tcx.has_attr(p.def_id(), "fundamental"))
@@ -234,7 +234,7 @@ fn fundamental_ty(tcx: TyCtxt, ty: Ty) -> bool {
234234
}
235235
}
236236

237-
fn ty_is_local_constructor(tcx: TyCtxt, ty: Ty, infer_is_local: InferIsLocal)-> bool {
237+
fn ty_is_local_constructor(ty: Ty, infer_is_local: InferIsLocal)-> bool {
238238
debug!("ty_is_local_constructor({:?})", ty);
239239

240240
match ty.sty {
@@ -265,11 +265,6 @@ fn ty_is_local_constructor(tcx: TyCtxt, ty: Ty, infer_is_local: InferIsLocal)->
265265
def.did.is_local()
266266
}
267267

268-
ty::TyBox(_) => { // Box<T>
269-
let krate = tcx.lang_items.owned_box().map(|d| d.krate);
270-
krate == Some(LOCAL_CRATE)
271-
}
272-
273268
ty::TyDynamic(ref tt, ..) => {
274269
tt.principal().map_or(false, |p| p.def_id().is_local())
275270
}

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
154154
ty::TyStr => Some(2),
155155
ty::TyInt(..) | ty::TyUint(..) | ty::TyInfer(ty::IntVar(..)) => Some(3),
156156
ty::TyFloat(..) | ty::TyInfer(ty::FloatVar(..)) => Some(4),
157-
ty::TyBox(..) | ty::TyRef(..) | ty::TyRawPtr(..) => Some(5),
157+
ty::TyRef(..) | ty::TyRawPtr(..) => Some(5),
158158
ty::TyArray(..) | ty::TySlice(..) => Some(6),
159159
ty::TyFnDef(..) | ty::TyFnPtr(..) => Some(7),
160160
ty::TyDynamic(..) => Some(8),

src/librustc/traits/select.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17351735
ty::TyInfer(ty::IntVar(_)) | ty::TyInfer(ty::FloatVar(_)) |
17361736
ty::TyUint(_) | ty::TyInt(_) | ty::TyBool | ty::TyFloat(_) |
17371737
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyRawPtr(..) |
1738-
ty::TyChar | ty::TyBox(_) | ty::TyRef(..) |
1738+
ty::TyChar | ty::TyRef(..) |
17391739
ty::TyArray(..) | ty::TyClosure(..) | ty::TyNever |
17401740
ty::TyError => {
17411741
// safe for everything
@@ -1788,7 +1788,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17881788
Where(ty::Binder(Vec::new()))
17891789
}
17901790

1791-
ty::TyBox(_) | ty::TyDynamic(..) | ty::TyStr | ty::TySlice(..) |
1791+
ty::TyDynamic(..) | ty::TyStr | ty::TySlice(..) |
17921792
ty::TyClosure(..) |
17931793
ty::TyRef(_, ty::TypeAndMut { ty: _, mutbl: hir::MutMutable }) => {
17941794
Never
@@ -1865,10 +1865,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
18651865
t);
18661866
}
18671867

1868-
ty::TyBox(referent_ty) => { // Box<T>
1869-
vec![referent_ty]
1870-
}
1871-
18721868
ty::TyRawPtr(ty::TypeAndMut { ty: element_ty, ..}) |
18731869
ty::TyRef(_, ty::TypeAndMut { ty: element_ty, ..}) => {
18741870
vec![element_ty]

src/librustc/ty/contents.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
191191
TC::None
192192
}
193193

194-
ty::TyBox(typ) => {
195-
tc_ty(tcx, typ, cache).owned_pointer()
196-
}
197-
198194
ty::TyDynamic(..) => {
199195
TC::All - TC::InteriorParam
200196
}
@@ -227,6 +223,10 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
227223
|ty| tc_ty(tcx, *ty, cache))
228224
}
229225

226+
ty::TyAdt(def, _) if def.is_box() => {
227+
tc_ty(tcx, ty.boxed_ty(), cache).owned_pointer()
228+
}
229+
230230
ty::TyAdt(def, substs) => {
231231
let mut res =
232232
TypeContents::union(&def.variants, |v| {

src/librustc/ty/context.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
1919
use hir::map as hir_map;
2020
use hir::map::DisambiguatedDefPathData;
2121
use middle::free_region::FreeRegionMap;
22+
use middle::lang_items;
2223
use middle::region::RegionMaps;
2324
use middle::resolve_lifetime;
2425
use middle::stability;
@@ -1088,7 +1089,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
10881089
pub fn print_debug_stats(self) {
10891090
sty_debug_print!(
10901091
self,
1091-
TyAdt, TyBox, TyArray, TySlice, TyRawPtr, TyRef, TyFnDef, TyFnPtr,
1092+
TyAdt, TyArray, TySlice, TyRawPtr, TyRef, TyFnDef, TyFnPtr,
10921093
TyDynamic, TyClosure, TyTuple, TyParam, TyInfer, TyProjection, TyAnon);
10931094

10941095
println!("Substs interner: #{}", self.interners.substs.borrow().len());
@@ -1336,7 +1337,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13361337
}
13371338

13381339
pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> {
1339-
self.mk_ty(TyBox(ty))
1340+
let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem);
1341+
let adt_def = self.lookup_adt_def(def_id);
1342+
let substs = self.mk_substs(iter::once(Kind::from(ty)));
1343+
self.mk_ty(TyAdt(adt_def, substs))
13401344
}
13411345

13421346
pub fn mk_ptr(self, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {

src/librustc/ty/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
181181
ty::TyTuple(ref tys) if tys.is_empty() => self.to_string(),
182182

183183
ty::TyAdt(def, _) => format!("{} `{}`", def.descr(), tcx.item_path_str(def.did)),
184-
ty::TyBox(_) => "box".to_string(),
185184
ty::TyArray(_, n) => format!("array of {} elements", n),
186185
ty::TySlice(_) => "slice".to_string(),
187186
ty::TyRawPtr(_) => "*-ptr".to_string(),

src/librustc/ty/fast_reject.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use hir::def_id::DefId;
1212
use ty::{self, Ty, TyCtxt};
1313
use syntax::ast;
14-
use middle::lang_items::OwnedBoxLangItem;
1514

1615
use self::SimplifiedType::*;
1716

@@ -69,10 +68,6 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
6968
// view of possibly unifying
7069
simplify_type(tcx, mt.ty, can_simplify_params)
7170
}
72-
ty::TyBox(_) => {
73-
// treat like we would treat `Box`
74-
Some(AdtSimplifiedType(tcx.require_lang_item(OwnedBoxLangItem)))
75-
}
7671
ty::TyClosure(def_id, _) => {
7772
Some(ClosureSimplifiedType(def_id))
7873
}

src/librustc/ty/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl FlagComputation {
138138
self.add_region(r);
139139
}
140140

141-
&ty::TyBox(tt) | &ty::TyArray(tt, _) | &ty::TySlice(tt) => {
141+
&ty::TyArray(tt, _) | &ty::TySlice(tt) => {
142142
self.add_ty(tt)
143143
}
144144

src/librustc/ty/item_path.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ pub fn characteristic_def_id_of_type(ty: Ty) -> Option<DefId> {
314314
ty::TyDynamic(data, ..) => data.principal().map(|p| p.def_id()),
315315

316316
ty::TyArray(subty, _) |
317-
ty::TySlice(subty) |
318-
ty::TyBox(subty) => characteristic_def_id_of_type(subty),
317+
ty::TySlice(subty) => characteristic_def_id_of_type(subty),
319318

320319
ty::TyRawPtr(mt) |
321320
ty::TyRef(_, mt) => characteristic_def_id_of_type(mt.ty),

src/librustc/ty/layout.rs

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,23 @@ impl<'a, 'gcx, 'tcx> Layout {
10531053
let dl = &tcx.data_layout;
10541054
assert!(!ty.has_infer_types());
10551055

1056+
let ptr_layout = |pointee: Ty<'gcx>| {
1057+
let non_zero = !ty.is_unsafe_ptr();
1058+
let pointee = normalize_associated_type(infcx, pointee);
1059+
if pointee.is_sized(tcx, &infcx.parameter_environment, DUMMY_SP) {
1060+
Ok(Scalar { value: Pointer, non_zero: non_zero })
1061+
} else {
1062+
let unsized_part = tcx.struct_tail(pointee);
1063+
let meta = match unsized_part.sty {
1064+
ty::TySlice(_) | ty::TyStr => {
1065+
Int(dl.ptr_sized_integer())
1066+
}
1067+
ty::TyDynamic(..) => Pointer,
1068+
_ => return Err(LayoutError::Unknown(unsized_part))
1069+
};
1070+
Ok(FatPointer { metadata: meta, non_zero: non_zero })
1071+
}
1072+
};
10561073

10571074
let layout = match ty.sty {
10581075
// Basic scalars.
@@ -1082,24 +1099,12 @@ impl<'a, 'gcx, 'tcx> Layout {
10821099
},
10831100

10841101
// Potentially-fat pointers.
1085-
ty::TyBox(pointee) |
10861102
ty::TyRef(_, ty::TypeAndMut { ty: pointee, .. }) |
10871103
ty::TyRawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
1088-
let non_zero = !ty.is_unsafe_ptr();
1089-
let pointee = normalize_associated_type(infcx, pointee);
1090-
if pointee.is_sized(tcx, &infcx.parameter_environment, DUMMY_SP) {
1091-
Scalar { value: Pointer, non_zero: non_zero }
1092-
} else {
1093-
let unsized_part = tcx.struct_tail(pointee);
1094-
let meta = match unsized_part.sty {
1095-
ty::TySlice(_) | ty::TyStr => {
1096-
Int(dl.ptr_sized_integer())
1097-
}
1098-
ty::TyDynamic(..) => Pointer,
1099-
_ => return Err(LayoutError::Unknown(unsized_part))
1100-
};
1101-
FatPointer { metadata: meta, non_zero: non_zero }
1102-
}
1104+
ptr_layout(pointee)?
1105+
}
1106+
ty::TyAdt(def, _) if def.is_box() => {
1107+
ptr_layout(ty.boxed_ty())?
11031108
}
11041109

11051110
// Arrays and slices.
@@ -1560,26 +1565,32 @@ impl<'a, 'gcx, 'tcx> SizeSkeleton<'gcx> {
15601565
Err(err) => err
15611566
};
15621567

1568+
let ptr_skeleton = |pointee: Ty<'gcx>| {
1569+
let non_zero = !ty.is_unsafe_ptr();
1570+
let tail = tcx.struct_tail(pointee);
1571+
match tail.sty {
1572+
ty::TyParam(_) | ty::TyProjection(_) => {
1573+
assert!(tail.has_param_types() || tail.has_self_ty());
1574+
Ok(SizeSkeleton::Pointer {
1575+
non_zero: non_zero,
1576+
tail: tcx.erase_regions(&tail)
1577+
})
1578+
}
1579+
_ => {
1580+
bug!("SizeSkeleton::compute({}): layout errored ({}), yet \
1581+
tail `{}` is not a type parameter or a projection",
1582+
ty, err, tail)
1583+
}
1584+
}
1585+
};
1586+
15631587
match ty.sty {
1564-
ty::TyBox(pointee) |
15651588
ty::TyRef(_, ty::TypeAndMut { ty: pointee, .. }) |
15661589
ty::TyRawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
1567-
let non_zero = !ty.is_unsafe_ptr();
1568-
let tail = tcx.struct_tail(pointee);
1569-
match tail.sty {
1570-
ty::TyParam(_) | ty::TyProjection(_) => {
1571-
assert!(tail.has_param_types() || tail.has_self_ty());
1572-
Ok(SizeSkeleton::Pointer {
1573-
non_zero: non_zero,
1574-
tail: tcx.erase_regions(&tail)
1575-
})
1576-
}
1577-
_ => {
1578-
bug!("SizeSkeleton::compute({}): layout errored ({}), yet \
1579-
tail `{}` is not a type parameter or a projection",
1580-
ty, err, tail)
1581-
}
1582-
}
1590+
ptr_skeleton(pointee)
1591+
}
1592+
ty::TyAdt(def, _) if def.is_box() => {
1593+
ptr_skeleton(ty.boxed_ty())
15831594
}
15841595

15851596
ty::TyAdt(def, substs) => {

src/librustc/ty/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ bitflags! {
13021302
const IS_SIMD = 1 << 4,
13031303
const IS_FUNDAMENTAL = 1 << 5,
13041304
const IS_UNION = 1 << 6,
1305+
const IS_BOX = 1 << 7,
13051306
}
13061307
}
13071308

@@ -1376,6 +1377,9 @@ impl<'a, 'gcx, 'tcx> AdtDef {
13761377
if Some(did) == tcx.lang_items.phantom_data() {
13771378
flags = flags | AdtFlags::IS_PHANTOM_DATA;
13781379
}
1380+
if Some(did) == tcx.lang_items.owned_box() {
1381+
flags = flags | AdtFlags::IS_BOX;
1382+
}
13791383
match kind {
13801384
AdtKind::Enum => flags = flags | AdtFlags::IS_ENUM,
13811385
AdtKind::Union => flags = flags | AdtFlags::IS_UNION,
@@ -1468,6 +1472,12 @@ impl<'a, 'gcx, 'tcx> AdtDef {
14681472
self.flags.get().intersects(AdtFlags::IS_PHANTOM_DATA)
14691473
}
14701474

1475+
/// Returns true if this is Box<T>.
1476+
#[inline]
1477+
pub fn is_box(&self) -> bool {
1478+
self.flags.get().intersects(AdtFlags::IS_BOX)
1479+
}
1480+
14711481
/// Returns whether this type has a destructor.
14721482
pub fn has_dtor(&self) -> bool {
14731483
self.dtor_kind().is_present()
@@ -1641,7 +1651,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
16411651
-> Vec<Ty<'tcx>> {
16421652
let result = match ty.sty {
16431653
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
1644-
TyBox(..) | TyRawPtr(..) | TyRef(..) | TyFnDef(..) | TyFnPtr(_) |
1654+
TyRawPtr(..) | TyRef(..) | TyFnDef(..) | TyFnPtr(_) |
16451655
TyArray(..) | TyClosure(..) | TyNever => {
16461656
vec![]
16471657
}

src/librustc/ty/outlives.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
167167
ty::TyFloat(..) | // OutlivesScalar
168168
ty::TyNever | // ...
169169
ty::TyAdt(..) | // OutlivesNominalType
170-
ty::TyBox(..) | // OutlivesNominalType (ish)
171170
ty::TyAnon(..) | // OutlivesNominalType (ish)
172171
ty::TyStr | // OutlivesScalar (ish)
173172
ty::TyArray(..) | // ...

src/librustc/ty/relate.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,6 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
418418
Ok(tcx.mk_closure_from_closure_substs(a_id, substs))
419419
}
420420

421-
(&ty::TyBox(a_inner), &ty::TyBox(b_inner)) =>
422-
{
423-
let typ = relation.relate(&a_inner, &b_inner)?;
424-
Ok(tcx.mk_box(typ))
425-
}
426-
427421
(&ty::TyRawPtr(ref a_mt), &ty::TyRawPtr(ref b_mt)) =>
428422
{
429423
let mt = relation.relate(a_mt, b_mt)?;

src/librustc/ty/structural_impls.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<Ty<'tcx>> {
468468
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
469469
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
470470
let sty = match self.sty {
471-
ty::TyBox(typ) => ty::TyBox(typ.fold_with(folder)),
472471
ty::TyRawPtr(tm) => ty::TyRawPtr(tm.fold_with(folder)),
473472
ty::TyArray(typ, sz) => ty::TyArray(typ.fold_with(folder), sz),
474473
ty::TySlice(typ) => ty::TySlice(typ.fold_with(folder)),
@@ -506,7 +505,6 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
506505

507506
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
508507
match self.sty {
509-
ty::TyBox(typ) => typ.visit_with(visitor),
510508
ty::TyRawPtr(ref tm) => tm.visit_with(visitor),
511509
ty::TyArray(typ, _sz) => typ.visit_with(visitor),
512510
ty::TySlice(typ) => typ.visit_with(visitor),

0 commit comments

Comments
 (0)