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
}

0 commit comments

Comments
 (0)