Skip to content

Commit cbd912b

Browse files
committed
Add union types
1 parent 35d52a0 commit cbd912b

File tree

29 files changed

+124
-69
lines changed

29 files changed

+124
-69
lines changed

src/librustc/infer/freshen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
168168
ty::TyFnPtr(_) |
169169
ty::TyTrait(..) |
170170
ty::TyStruct(..) |
171+
ty::TyUnion(..) |
171172
ty::TyClosure(..) |
172173
ty::TyNever |
173174
ty::TyTuple(..) |

src/librustc/traits/coherence.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ fn ty_is_local_constructor(tcx: TyCtxt, ty: Ty, infer_is_local: InferIsLocal)->
261261
}
262262

263263
ty::TyEnum(def, _) |
264-
ty::TyStruct(def, _) => {
264+
ty::TyStruct(def, _) |
265+
ty::TyUnion(def, _) => {
265266
def.did.is_local()
266267
}
267268

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
166166
ty::TyParam(..) => Some(14),
167167
ty::TyAnon(..) => Some(15),
168168
ty::TyNever => Some(16),
169+
ty::TyUnion(..) => Some(17),
169170
ty::TyInfer(..) | ty::TyError => None
170171
}
171172
}

src/librustc/traits/select.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17801780
Where(ty::Binder(tys.last().into_iter().cloned().collect()))
17811781
}
17821782

1783-
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
1783+
ty::TyStruct(def, substs) | ty::TyUnion(def, substs) |
1784+
ty::TyEnum(def, substs) => {
17841785
let sized_crit = def.sized_constraint(self.tcx());
17851786
// (*) binder moved here
17861787
Where(ty::Binder(match sized_crit.sty {
@@ -1836,7 +1837,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
18361837
Where(ty::Binder(tys.to_vec()))
18371838
}
18381839

1839-
ty::TyStruct(..) | ty::TyEnum(..) |
1840+
ty::TyStruct(..) | ty::TyUnion(..) | ty::TyEnum(..) |
18401841
ty::TyProjection(..) | ty::TyParam(..) | ty::TyAnon(..) => {
18411842
// Fallback to whatever user-defined impls exist in this case.
18421843
None
@@ -1933,7 +1934,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
19331934
substs.types().collect()
19341935
}
19351936

1936-
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
1937+
ty::TyStruct(def, substs) | ty::TyUnion(def, substs) | ty::TyEnum(def, substs) => {
19371938
def.all_fields()
19381939
.map(|f| f.ty(self.tcx(), substs))
19391940
.collect()

src/librustc/ty/contents.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
224224
|ty| tc_ty(tcx, *ty, cache))
225225
}
226226

227-
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
227+
ty::TyStruct(def, substs) | ty::TyUnion(def, substs) |
228+
ty::TyEnum(def, substs) => {
228229
let mut res =
229230
TypeContents::union(&def.variants, |v| {
230231
TypeContents::union(&v.fields, |f| {

src/librustc/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,8 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
10321032
pub fn print_debug_stats(self) {
10331033
sty_debug_print!(
10341034
self,
1035-
TyEnum, TyBox, TyArray, TySlice, TyRawPtr, TyRef, TyFnDef, TyFnPtr,
1036-
TyTrait, TyStruct, TyClosure, TyTuple, TyParam, TyInfer, TyProjection, TyAnon);
1035+
TyEnum, TyBox, TyArray, TySlice, TyRawPtr, TyRef, TyFnDef, TyFnPtr, TyTrait,
1036+
TyStruct, TyUnion, TyClosure, TyTuple, TyParam, TyInfer, TyProjection, TyAnon);
10371037

10381038
println!("Substs interner: #{}", self.interners.substs.borrow().len());
10391039
println!("BareFnTy interner: #{}", self.interners.bare_fn.borrow().len());

src/librustc/ty/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
247247
ty::TyStruct(def, _) => {
248248
format!("struct `{}`", tcx.item_path_str(def.did))
249249
}
250+
ty::TyUnion(def, _) => {
251+
format!("union `{}`", tcx.item_path_str(def.did))
252+
}
250253
ty::TyClosure(..) => "closure".to_string(),
251254
ty::TyTuple(_) => "tuple".to_string(),
252255
ty::TyInfer(ty::TyVar(_)) => "inferred type".to_string(),

src/librustc/ty/fast_reject.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
6666
ty::TyStruct(def, _) => {
6767
Some(StructSimplifiedType(def.did))
6868
}
69+
ty::TyUnion(..) => {
70+
unimplemented_unions!();
71+
}
6972
ty::TyRef(_, mt) => {
7073
// since we introduce auto-refs during method lookup, we
7174
// just treat &T and T as equivalent from the point of

src/librustc/ty/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl FlagComputation {
102102
}
103103
}
104104

105-
&ty::TyEnum(_, substs) | &ty::TyStruct(_, substs) => {
105+
&ty::TyEnum(_, substs) | &ty::TyStruct(_, substs) | &ty::TyUnion(_, substs) => {
106106
self.add_substs(substs);
107107
}
108108

src/librustc/ty/item_path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
320320
pub fn characteristic_def_id_of_type(ty: Ty) -> Option<DefId> {
321321
match ty.sty {
322322
ty::TyStruct(adt_def, _) |
323+
ty::TyUnion(adt_def, _) |
323324
ty::TyEnum(adt_def, _) => Some(adt_def.did),
324325

325326
ty::TyTrait(ref data) => Some(data.principal.def_id()),

0 commit comments

Comments
 (0)