Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_public/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@ pub enum Rvalue {
///
/// [`Rvalue::Reborrow`]: rustc_middle::mir::Rvalue::Reborrow
Reborrow(Ty, Mutability, Place),

/// Wraps a value in an `unsafe<>` binder type (feature `unsafe_binders`).
WrapUnsafeBinder(Operand, Ty),
}

impl Rvalue {
Expand Down Expand Up @@ -650,6 +653,7 @@ impl Rvalue {
AggregateKind::RawPtr(ty, mutability) => Ok(Ty::new_ptr(ty, mutability)),
},
Rvalue::CopyForDeref(place) => place.ty(locals),
Rvalue::WrapUnsafeBinder(_, ty) => Ok(*ty),
}
}
}
Expand Down Expand Up @@ -835,6 +839,9 @@ pub enum ProjectionElem {
/// Like an explicit cast from an opaque type to a concrete type, but without
/// requiring an intermediate variable.
OpaqueCast(Ty),

/// Unwraps an `unsafe<>` binder place to its inner type (feature `unsafe_binders`).
UnwrapUnsafeBinder(Ty),
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
Expand Down Expand Up @@ -1069,6 +1076,7 @@ impl ProjectionElem {
}
ProjectionElem::Downcast(_) => Ok(ty),
ProjectionElem::OpaqueCast(ty) => Ok(*ty),
ProjectionElem::UnwrapUnsafeBinder(ty) => Ok(*ty),
}
}

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_public/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ fn pretty_rvalue<W: Write>(writer: &mut W, rval: &Rvalue) -> io::Result<()> {
if matches!(retag, crate::mir::WithRetag::No) { "no_retag " } else { "" },
pretty_operand(op)
),
Rvalue::WrapUnsafeBinder(op, ty) => {
write!(writer, "wrap_unsafe_binder({}, {})", pretty_operand(op), ty)
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_public/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ macro_rules! make_mir_visitor {
Rvalue::UnaryOp(_, op) | Rvalue::Use(op, _) => {
self.visit_operand(op, location);
}
Rvalue::WrapUnsafeBinder(op, ty) => {
self.visit_operand(op, location);
self.visit_ty(ty, location);
}
}
}

Expand Down Expand Up @@ -468,6 +472,7 @@ macro_rules! visit_place_fns {
ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {}
ProjectionElem::Downcast(_idx) => {}
ProjectionElem::OpaqueCast(ty) => self.visit_ty(ty, location),
ProjectionElem::UnwrapUnsafeBinder(ty) => self.visit_ty(ty, location),
}
}
};
Expand Down Expand Up @@ -508,6 +513,7 @@ macro_rules! visit_place_fns {
ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {}
ProjectionElem::Downcast(_idx) => {}
ProjectionElem::OpaqueCast(ty) => self.visit_ty(ty, location),
ProjectionElem::UnwrapUnsafeBinder(ty) => self.visit_ty(ty, location),
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_public/src/unstable/convert/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ impl RustcInternal for ProjectionElem {
ProjectionElem::OpaqueCast(ty) => {
rustc_middle::mir::PlaceElem::OpaqueCast(ty.internal(tables, tcx))
}
ProjectionElem::UnwrapUnsafeBinder(ty) => {
rustc_middle::mir::PlaceElem::UnwrapUnsafeBinder(ty.internal(tables, tcx))
}
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_public/src/unstable/convert/stable/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
crate::mir::Rvalue::Aggregate(agg_kind.stable(tables, cx), operands)
}
CopyForDeref(place) => crate::mir::Rvalue::CopyForDeref(place.stable(tables, cx)),
WrapUnsafeBinder(..) => todo!("FIXME(unsafe_binders):"),
WrapUnsafeBinder(op, ty) => crate::mir::Rvalue::WrapUnsafeBinder(
op.stable(tables, cx),
ty.stable(tables, cx),
),
}
}
}
Expand Down Expand Up @@ -446,7 +449,9 @@ impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
// found at https://github.com/rust-lang/rust/pull/117517#issuecomment-1811683486
Downcast(_, idx) => crate::mir::ProjectionElem::Downcast(idx.stable(tables, cx)),
OpaqueCast(ty) => crate::mir::ProjectionElem::OpaqueCast(ty.stable(tables, cx)),
UnwrapUnsafeBinder(..) => todo!("FIXME(unsafe_binders):"),
UnwrapUnsafeBinder(ty) => {
crate::mir::ProjectionElem::UnwrapUnsafeBinder(ty.stable(tables, cx))
}
}
}
}
Expand Down