Skip to content

Commit be95b56

Browse files
committed
Add a mir validation check to prevent OpaqueCast after analysis passes finish
1 parent c392072 commit be95b56

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: compiler/rustc_const_eval/src/transform/validate.rs

+8
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
633633
location: Location,
634634
) {
635635
match elem {
636+
ProjectionElem::OpaqueCast(ty)
637+
if self.mir_phase >= MirPhase::Runtime(RuntimePhase::Initial) =>
638+
{
639+
self.fail(
640+
location,
641+
format!("explicit opaque type cast to `{ty}` after `RevealAll`"),
642+
)
643+
}
636644
ProjectionElem::Index(index) => {
637645
let index_ty = self.body.local_decls[index].ty;
638646
if index_ty != self.tcx.types.usize {

Diff for: compiler/rustc_middle/src/mir/syntax.rs

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ pub enum RuntimePhase {
139139
/// * [`TerminatorKind::Yield`]
140140
/// * [`TerminatorKind::GeneratorDrop`]
141141
/// * [`Rvalue::Aggregate`] for any `AggregateKind` except `Array`
142+
/// * [`PlaceElem::OpaqueCast`]
142143
///
143144
/// And the following variants are allowed:
144145
/// * [`StatementKind::Retag`]

0 commit comments

Comments
 (0)