Skip to content

Commit

Permalink
Remove rule that place loads may not happen with variant index set
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobDegen committed Apr 9, 2022
1 parent a5d2c04 commit 9745a17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
7 changes: 2 additions & 5 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
self.super_projection_elem(local, proj_base, elem, context, location);
}

fn visit_place(&mut self, place: &Place<'tcx>, _: PlaceContext, location: Location) {
fn visit_place(&mut self, place: &Place<'tcx>, _: PlaceContext, _: Location) {
// Set off any `bug!`s in the type computation code
let ty = place.ty(&self.body.local_decls, self.tcx);
if ty.variant_index.is_some() {
self.fail(location, "Top level places may not have their variant index set!");
}
let _ = place.ty(&self.body.local_decls, self.tcx);
}

fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,7 @@ pub struct CopyNonOverlapping<'tcx> {
/// pointee type is unsized, the pointer additionally stored the value of the metadata.
///
/// Computing a place may cause UB. One possibility is that the pointer used for a `Deref` may not
/// be suitably aligned. Another possibility is that the place is not in bouns, meaning it does not
/// be suitably aligned. Another possibility is that the place is not in bounds, meaning it does not
/// point to an actual allocation.
///
/// However, if this is actually UB and when the UB kicks in is undecided. This is being discussed
Expand Down Expand Up @@ -2315,10 +2315,9 @@ pub struct SourceScopeLocalData {
/// This is what is implemented in miri today. Are these the semantics we want for MIR? Is this
/// something we can even decide without knowing more about Rust's memory model?
///
/// Loading a place that has its variant index set is not well-formed. However, note that this rule
/// only applies to places appearing in MIR bodies. Many functions, such as [`Place::ty`], still
/// accept such a place. If you write a function for which it might be ambiguous whether such a
/// thing is accepted, make sure to document your choice clearly.
/// **Needs clarifiation:** Is loading a place that has its variant index set well-formed? Miri
/// currently implements it, but it seems like this may be something to check against in the
/// validator.
#[derive(Clone, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
pub enum Operand<'tcx> {
/// Creates a value by loading the given place. The type of the place must be `Copy`
Expand Down

0 comments on commit 9745a17

Please sign in to comment.