Skip to content

Commit b756929

Browse files
Add TyKind::TyAlias support in rustc_const_eval
1 parent 5aa4e3c commit b756929

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
152152
// FIXME(oli-obk): we can probably encode closures just like structs
153153
| ty::Closure(..)
154154
| ty::Generator(..)
155+
// FIXME: we could look behind type aliases.
156+
| ty::TyAlias(..)
155157
| ty::GeneratorWitness(..) => Err(ValTreeCreationError::NonSupportedType),
156158
}
157159
}
@@ -320,7 +322,8 @@ pub fn valtree_to_const_value<'tcx>(
320322
| ty::RawPtr(_)
321323
| ty::Str
322324
| ty::Slice(_)
323-
| ty::Dynamic(..) => bug!("no ValTree should have been created for type {:?}", ty.kind()),
325+
| ty::Dynamic(..)
326+
| ty::TyAlias(..) => bug!("no ValTree should have been created for type {:?}", ty.kind()),
324327
}
325328
}
326329

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ use rustc_middle::mir::{
1010
interpret::{ConstValue, GlobalId, InterpResult, PointerArithmetic, Scalar},
1111
BinOp, NonDivergingIntrinsic,
1212
};
13-
use rustc_middle::ty;
1413
use rustc_middle::ty::layout::LayoutOf as _;
1514
use rustc_middle::ty::subst::SubstsRef;
16-
use rustc_middle::ty::{Ty, TyCtxt};
15+
use rustc_middle::ty::{self, Ty, TyCtxt};
1716
use rustc_span::symbol::{sym, Symbol};
1817
use rustc_target::abi::{Abi, Align, Primitive, Size};
1918

@@ -102,6 +101,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
102101
| ty::Never
103102
| ty::Tuple(_)
104103
| ty::Error(_) => ConstValue::from_machine_usize(0u64, &tcx),
104+
ty::TyAlias(..) => bug!("unexpected TyAlias in eval_nullary_intrinsic"),
105105
},
106106
other => bug!("`{}` is not a zero arg intrinsic", other),
107107
})

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
6464
| ty::Closure(def_id, substs)
6565
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
6666
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),
67+
ty::TyAlias(def_id, substs) => {
68+
let binder_ty = self.tcx.bound_type_of(def_id);
69+
let ty = binder_ty.subst(self.tcx, substs);
70+
self.print_type(ty)
71+
}
6772

6873
ty::GeneratorWitness(_) => bug!("type_name: unexpected `GeneratorWitness`"),
6974
}

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
603603
| ty::Param(..)
604604
| ty::Opaque(..)
605605
| ty::Projection(..)
606-
| ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty),
606+
| ty::GeneratorWitness(..)
607+
| ty::TyAlias(..) => bug!("Encountered invalid type {:?}", ty),
607608
}
608609
}
609610

0 commit comments

Comments
 (0)