Add a mir validation check to prevent OpaqueCast after analysis passes finish
This commit is contained in:
parent
2d4201f7c6
commit
0031cf7c7e
2 changed files with 9 additions and 0 deletions
|
@ -633,6 +633,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||||
location: Location,
|
location: Location,
|
||||||
) {
|
) {
|
||||||
match elem {
|
match elem {
|
||||||
|
ProjectionElem::OpaqueCast(ty)
|
||||||
|
if self.mir_phase >= MirPhase::Runtime(RuntimePhase::Initial) =>
|
||||||
|
{
|
||||||
|
self.fail(
|
||||||
|
location,
|
||||||
|
format!("explicit opaque type cast to `{ty}` after `RevealAll`"),
|
||||||
|
)
|
||||||
|
}
|
||||||
ProjectionElem::Index(index) => {
|
ProjectionElem::Index(index) => {
|
||||||
let index_ty = self.body.local_decls[index].ty;
|
let index_ty = self.body.local_decls[index].ty;
|
||||||
if index_ty != self.tcx.types.usize {
|
if index_ty != self.tcx.types.usize {
|
||||||
|
|
|
@ -139,6 +139,7 @@ pub enum RuntimePhase {
|
||||||
/// * [`TerminatorKind::Yield`]
|
/// * [`TerminatorKind::Yield`]
|
||||||
/// * [`TerminatorKind::GeneratorDrop`]
|
/// * [`TerminatorKind::GeneratorDrop`]
|
||||||
/// * [`Rvalue::Aggregate`] for any `AggregateKind` except `Array`
|
/// * [`Rvalue::Aggregate`] for any `AggregateKind` except `Array`
|
||||||
|
/// * [`PlaceElem::OpaqueCast`]
|
||||||
///
|
///
|
||||||
/// And the following variants are allowed:
|
/// And the following variants are allowed:
|
||||||
/// * [`StatementKind::Retag`]
|
/// * [`StatementKind::Retag`]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue