Skip to content

Commit ecfe3cb

Browse files
committed
add ty::Variant type
1 parent e269e6b commit ecfe3cb

File tree

35 files changed

+76
-0
lines changed

35 files changed

+76
-0
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ fn push_debuginfo_type_name<'tcx>(
373373
t
374374
);
375375
}
376+
377+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
376378
}
377379

378380
/// MSVC names enums differently than other platforms so that the debugging visualization

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn const_to_valtree_inner<'tcx>(
129129
| ty::Closure(..)
130130
| ty::Generator(..)
131131
| ty::GeneratorWitness(..) => None,
132+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
132133
}
133134
}
134135

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ crate fn eval_nullary_intrinsic<'tcx>(
100100
| ty::Never
101101
| ty::Tuple(_)
102102
| ty::Error(_) => ConstValue::from_machine_usize(0u64, &tcx),
103+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
103104
},
104105
other => bug!("`{}` is not a zero arg intrinsic", other),
105106
})

compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
6565
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),
6666

6767
ty::GeneratorWitness(_) => bug!("type_name: unexpected `GeneratorWitness`"),
68+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
6869
}
6970
}
7071

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
612612
| ty::Opaque(..)
613613
| ty::Projection(..)
614614
| ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty),
615+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
615616
}
616617
}
617618

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
406406
t
407407
}
408408
}
409+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
409410
}
410411
}
411412

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
218218
| ty::Opaque(..) => t.super_fold_with(self),
219219

220220
ty::Placeholder(..) | ty::Bound(..) => bug!("unexpected type {:?}", t),
221+
222+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
221223
}
222224
}
223225

compiler/rustc_infer/src/infer/outlives/components.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ fn compute_components(
187187
// themselves can be readily identified.
188188
compute_components_recursive(tcx, ty.into(), out, visited);
189189
}
190+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
190191
}
191192
}
192193

compiler/rustc_lint/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
11301130
| ty::GeneratorWitness(..)
11311131
| ty::Placeholder(..)
11321132
| ty::FnDef(..) => bug!("unexpected type in foreign function: {:?}", ty),
1133+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
11331134
}
11341135
}
11351136

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,7 @@ impl<'tcx> TyCtxt<'tcx> {
19321932
fmt,
19331933
self.0,
19341934
Adt,
1935+
Variant,
19351936
Array,
19361937
Slice,
19371938
RawPtr,

compiler/rustc_middle/src/ty/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ impl<'tcx> ty::TyS<'tcx> {
247247
ty::Tuple(ref tys) if tys.is_empty() => format!("`{}`", self).into(),
248248

249249
ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
250+
ty::Variant(ty, _) => ty.sort_string(tcx),
250251
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
251252
ty::Array(t, n) => {
252253
if t.is_simple_ty() {
@@ -318,6 +319,10 @@ impl<'tcx> ty::TyS<'tcx> {
318319
| ty::Never => "type".into(),
319320
ty::Tuple(ref tys) if tys.is_empty() => "unit type".into(),
320321
ty::Adt(def, _) => def.descr().into(),
322+
ty::Variant(ty, _) => match ty.kind() {
323+
ty::Adt(def, _) => format!("{} variant", def.descr()).into(),
324+
_ => bug!("unexpected type: {:?}", ty.kind()),
325+
},
321326
ty::Foreign(_) => "extern type".into(),
322327
ty::Array(..) => "array".into(),
323328
ty::Slice(_) => "slice".into(),

compiler/rustc_middle/src/ty/fast_reject.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub fn simplify_type(
104104
ty::Opaque(def_id, _) => Some(OpaqueSimplifiedType(def_id)),
105105
ty::Foreign(def_id) => Some(ForeignSimplifiedType(def_id)),
106106
ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) | ty::Error(_) => None,
107+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
107108
}
108109
}
109110

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ impl FlagComputation {
213213
computation.add_tys(fn_sig.inputs());
214214
computation.add_ty(fn_sig.output());
215215
}),
216+
217+
&ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
216218
}
217219
}
218220

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
14031403
ty::Bound(..) | ty::Param(_) | ty::Error(_) => {
14041404
return Err(LayoutError::Unknown(ty));
14051405
}
1406+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
14061407
})
14071408
}
14081409
}
@@ -2388,6 +2389,7 @@ where
23882389
| ty::Param(_)
23892390
| ty::Infer(_)
23902391
| ty::Error(_) => bug!("TyAndLayout::field: unexpected type `{}`", this.ty),
2392+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
23912393
}
23922394
}
23932395

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ fn characteristic_def_id_of_type_cached<'a>(
315315
| ty::GeneratorWitness(..)
316316
| ty::Never
317317
| ty::Float(_) => None,
318+
319+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
318320
}
319321
}
320322
pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,14 @@ pub trait PrettyPrinter<'tcx>:
605605
ty::Adt(def, substs) => {
606606
p!(print_def_path(def.did, substs));
607607
}
608+
609+
ty::Variant(ty, idx) => match ty.kind() {
610+
ty::Adt(def, substs) => {
611+
p!(print_def_path(def.did, substs));
612+
p!(write("::{}", def.variants.get(idx).unwrap().ident.name));
613+
}
614+
_ => bug!("unexpected type: {:?}", ty.kind()),
615+
},
608616
ty::Dynamic(data, r) => {
609617
let print_r = self.region_should_not_be_omitted(r);
610618
if print_r {

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
903903
| ty::Placeholder(..)
904904
| ty::Never
905905
| ty::Foreign(..) => return self,
906+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
906907
};
907908

908909
if *self.kind() == kind { self } else { folder.tcx().mk_ty(kind) }
@@ -951,6 +952,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
951952
| ty::Param(..)
952953
| ty::Never
953954
| ty::Foreign(..) => ControlFlow::CONTINUE,
955+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
954956
}
955957
}
956958

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ pub enum TyKind<'tcx> {
195195
/// A type variable used during type checking.
196196
Infer(InferTy),
197197

198+
/// Type of a variant of an enum
199+
Variant(Ty<'tcx>, VariantIdx),
200+
198201
/// A placeholder for a type which could not be computed; this is
199202
/// propagated to avoid useless error messages.
200203
Error(DelaySpanBugEmitted),
@@ -2059,6 +2062,8 @@ impl<'tcx> TyS<'tcx> {
20592062
| ty::Infer(FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
20602063
bug!("`discriminant_ty` applied to unexpected type: {:?}", self)
20612064
}
2065+
2066+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
20622067
}
20632068
}
20642069

@@ -2107,6 +2112,8 @@ impl<'tcx> TyS<'tcx> {
21072112
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
21082113
bug!("`ptr_metadata_ty` applied to unexpected type: {:?}", tail)
21092114
}
2115+
2116+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
21102117
}
21112118
}
21122119

@@ -2185,6 +2192,8 @@ impl<'tcx> TyS<'tcx> {
21852192
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
21862193
bug!("`is_trivially_sized` applied to unexpected type: {:?}", self)
21872194
}
2195+
2196+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
21882197
}
21892198
}
21902199
}

compiler/rustc_middle/src/ty/util.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ impl<'tcx> ty::TyS<'tcx> {
712712
| ty::Param(_)
713713
| ty::Placeholder(_)
714714
| ty::Projection(_) => false,
715+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
715716
}
716717
}
717718

@@ -752,6 +753,7 @@ impl<'tcx> ty::TyS<'tcx> {
752753
| ty::Param(_)
753754
| ty::Placeholder(_)
754755
| ty::Projection(_) => false,
756+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
755757
}
756758
}
757759

@@ -874,6 +876,8 @@ impl<'tcx> ty::TyS<'tcx> {
874876
Projection(_) | Opaque(..) | Param(_) | Bound(..) | Placeholder(_) | Infer(_) => false,
875877

876878
Foreign(_) | GeneratorWitness(..) | Error(_) => false,
879+
880+
Variant(..) => unimplemented!("TODO(zhamlin)"),
877881
}
878882
}
879883

@@ -1022,6 +1026,7 @@ pub fn needs_drop_components(
10221026
| ty::Infer(_)
10231027
| ty::Closure(..)
10241028
| ty::Generator(..) => Ok(smallvec![ty]),
1029+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
10251030
}
10261031
}
10271032

compiler/rustc_middle/src/ty/walk.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ fn push_inner<'tcx>(
198198
stack.push(sig.skip_binder().output().into());
199199
stack.extend(sig.skip_binder().inputs().iter().copied().rev().map(|ty| ty.into()));
200200
}
201+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
201202
},
202203
GenericArgKind::Lifetime(_) => {}
203204
GenericArgKind::Const(parent_ct) => {

compiler/rustc_privacy/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ where
277277
ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) => {
278278
bug!("unexpected type: {:?}", ty)
279279
}
280+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
280281
}
281282

282283
if self.def_id_visitor.shallow() {

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> {
467467
}
468468

469469
ty::GeneratorWitness(_) => bug!("symbol_names: unexpected `GeneratorWitness`"),
470+
471+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
470472
}
471473

472474
// Only cache types that do not refer to an enclosing

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,5 +651,7 @@ fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool {
651651
ty::Generator(..) | ty::GeneratorWitness(..) => {
652652
bug!("ty_is_local invoked on unexpected type: {:?}", ty)
653653
}
654+
655+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
654656
}
655657
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
13771377
ty::Foreign(..) => Some(19),
13781378
ty::GeneratorWitness(..) => Some(20),
13791379
ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) | ty::Error(_) => None,
1380+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
13801381
}
13811382
}
13821383

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
14021402
| ty::Placeholder(..)
14031403
| ty::Infer(..)
14041404
| ty::Error(_) => false,
1405+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
14051406
}
14061407
}
14071408
super::ImplSource::Pointee(..) => {
@@ -1447,6 +1448,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
14471448
| ty::Placeholder(..)
14481449
| ty::Infer(..)
14491450
| ty::Error(_) => false,
1451+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
14501452
}
14511453
}
14521454
super::ImplSource::Param(..) => {

compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,6 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
135135
| ty::Infer(_)
136136
| ty::Bound(..)
137137
| ty::Generator(..) => false,
138+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
138139
}
139140
}

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10211021
}
10221022
debug!("not returning");
10231023
}
1024+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
10241025
}
10251026
debug!(?stack, "assemble_const_drop_candidates - in loop");
10261027
}

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18351835
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
18361836
bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
18371837
}
1838+
1839+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
18381840
}
18391841
}
18401842

@@ -1912,6 +1914,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19121914
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
19131915
bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
19141916
}
1917+
1918+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
19151919
}
19161920
}
19171921

@@ -1993,6 +1997,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19931997
// the auto trait bounds in question.
19941998
t.rebind(vec![self.tcx().type_of(def_id).subst(self.tcx(), substs)])
19951999
}
2000+
2001+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
19962002
}
19972003
}
19982004

compiler/rustc_trait_selection/src/traits/structural_match.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
210210
// as this may still emit relevant errors.
211211
return ControlFlow::CONTINUE;
212212
}
213+
214+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
213215
};
214216

215217
if !self.seen.insert(adt_def.did) {

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
687687
self.compute(ty.into());
688688
}
689689
}
690+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
690691
}
691692
}
692693
}

compiler/rustc_traits/src/chalk/lowering.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
330330
}
331331
ty::Infer(_infer) => unimplemented!(),
332332
ty::Error(_) => chalk_ir::TyKind::Error,
333+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
333334
}
334335
.intern(interner)
335336
}

compiler/rustc_traits/src/dropck_outlives.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ fn dtorck_constraint_for_ty<'tcx>(
299299
// be fully resolved.
300300
return Err(NoSolution);
301301
}
302+
303+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
302304
}
303305

304306
Ok(())

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ fn sized_constraint_for_ty<'tcx>(
6868
Placeholder(..) | Bound(..) | Infer(..) => {
6969
bug!("unexpected type `{:?}` in sized_constraint_for_ty", ty)
7070
}
71+
72+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
7173
};
7274
debug!("sized_constraint_for_ty({:?}) = {:?}", ty, result);
7375
result

compiler/rustc_typeck/src/check/cast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
144144
.delay_span_bug(span, &format!("`{:?}` should be sized but is not?", t));
145145
return Err(ErrorReported);
146146
}
147+
ty::Variant(..) => unimplemented!("TODO(zhamlin)"),
147148
})
148149
}
149150
}

0 commit comments

Comments
 (0)