Skip to content

Commit

Permalink
const prop: don't special case return place
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Apr 20, 2020
1 parent 9e6f38a commit 415fd0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
fn get_const(&self, local: Local) -> Option<OpTy<'tcx>> {
let op = self.ecx.access_local(self.ecx.frame(), local, None).ok();

if local == RETURN_PLACE {
// Try to read the return place as an immediate so that if it is representable as a
// scalar, we can handle it as such, but otherwise, just return the value as is.
return match op.map(|ret| self.ecx.try_read_immediate(ret)) {
Some(Ok(Ok(imm))) => Some(imm.into()),
_ => op,
};
// Try to read the local as an immediate so that if it is representable as a scalar, we can
// handle it as such, but otherwise, just return the value as is.
match op.map(|ret| self.ecx.try_read_immediate(ret)) {
Some(Ok(Ok(imm))) => Some(imm.into()),
_ => op,
}

op
}

fn remove_const(&mut self, local: Local) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/incremental/hashes/enum_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,29 +274,29 @@ pub enum Clike2 {
// Change constructor path (C-like) --------------------------------------
#[cfg(cfail1)]
pub fn change_constructor_path_c_like() {
let _ = Clike::B;
let _x = Clike::B;
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of")]
#[rustc_clean(cfg="cfail3")]
pub fn change_constructor_path_c_like() {
let _ = Clike2::B;
let _x = Clike2::B;
}



// Change constructor variant (C-like) --------------------------------------
#[cfg(cfail1)]
pub fn change_constructor_variant_c_like() {
let _ = Clike::A;
let _x = Clike::A;
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")]
#[rustc_clean(cfg="cfail3")]
pub fn change_constructor_variant_c_like() {
let _ = Clike::C;
let _x = Clike::C;
}


Expand Down

0 comments on commit 415fd0c

Please sign in to comment.