Skip to content

Commit

Permalink
experiment: do not use value-based interior mut reasoning for promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 2, 2024
1 parent ac1ed22 commit c7d99c8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions compiler/rustc_mir_transform/src/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,24 @@ impl<'tcx> Validator<'_, 'tcx> {
if has_mut_interior {
return Err(Unpromotable);
}
// Let's just see what happens if we reject anything `!Freeze`...
// (Except ZST which definitely can't have interior mut)
let ty = place.ty(self.body, self.tcx).ty;
let has_interior_mut = match ty.kind() {
// Empty arrays have no interior mutability no matter their element type.
ty::Array(_elem, count)
if count
.try_eval_target_usize(self.tcx, self.param_env)
.is_some_and(|v| v == 0) =>
{
false
}
// Fallback to checking `Freeze`.
_ => !ty.is_freeze(self.tcx, self.param_env),
};
if has_interior_mut {
return Err(Unpromotable);
}
}

// FIXME: consider changing this to only promote &mut [] for default borrows,
Expand Down

0 comments on commit c7d99c8

Please sign in to comment.