Get rid of "is not const" naming
This commit is contained in:
parent
ec5206588f
commit
d3d56732a7
@ -365,11 +365,11 @@ impl Qualif for NeedsDrop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not constant at all - non-`const fn` calls, asm!,
|
// Not promotable at all - non-`const fn` calls, asm!,
|
||||||
// pointer comparisons, ptr-to-int casts, etc.
|
// pointer comparisons, ptr-to-int casts, etc.
|
||||||
struct IsNotConst;
|
struct IsNotPromotable;
|
||||||
|
|
||||||
impl Qualif for IsNotConst {
|
impl Qualif for IsNotPromotable {
|
||||||
const IDX: usize = 2;
|
const IDX: usize = 2;
|
||||||
|
|
||||||
fn in_static(cx: &ConstCx<'_, 'tcx>, static_: &Static<'tcx>) -> bool {
|
fn in_static(cx: &ConstCx<'_, 'tcx>, static_: &Static<'tcx>) -> bool {
|
||||||
@ -548,14 +548,14 @@ macro_rules! static_assert_seq_qualifs {
|
|||||||
static_assert!(SEQ_QUALIFS: QUALIF_COUNT == $i);
|
static_assert!(SEQ_QUALIFS: QUALIF_COUNT == $i);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
static_assert_seq_qualifs!(0 => HasMutInterior, NeedsDrop, IsNotConst, IsNotImplicitlyPromotable);
|
static_assert_seq_qualifs!(0 => HasMutInterior, NeedsDrop, IsNotPromotable, IsNotImplicitlyPromotable);
|
||||||
|
|
||||||
impl ConstCx<'_, 'tcx> {
|
impl ConstCx<'_, 'tcx> {
|
||||||
fn qualifs_in_any_value_of_ty(&self, ty: Ty<'tcx>) -> PerQualif<bool> {
|
fn qualifs_in_any_value_of_ty(&self, ty: Ty<'tcx>) -> PerQualif<bool> {
|
||||||
let mut qualifs = PerQualif::default();
|
let mut qualifs = PerQualif::default();
|
||||||
qualifs[HasMutInterior] = HasMutInterior::in_any_value_of_ty(self, ty).unwrap_or(false);
|
qualifs[HasMutInterior] = HasMutInterior::in_any_value_of_ty(self, ty).unwrap_or(false);
|
||||||
qualifs[NeedsDrop] = NeedsDrop::in_any_value_of_ty(self, ty).unwrap_or(false);
|
qualifs[NeedsDrop] = NeedsDrop::in_any_value_of_ty(self, ty).unwrap_or(false);
|
||||||
qualifs[IsNotConst] = IsNotConst::in_any_value_of_ty(self, ty).unwrap_or(false);
|
qualifs[IsNotPromotable] = IsNotPromotable::in_any_value_of_ty(self, ty).unwrap_or(false);
|
||||||
qualifs[IsNotImplicitlyPromotable] = IsNotImplicitlyPromotable::in_any_value_of_ty(self, ty).unwrap_or(false);
|
qualifs[IsNotImplicitlyPromotable] = IsNotImplicitlyPromotable::in_any_value_of_ty(self, ty).unwrap_or(false);
|
||||||
qualifs
|
qualifs
|
||||||
}
|
}
|
||||||
@ -564,7 +564,7 @@ impl ConstCx<'_, 'tcx> {
|
|||||||
let mut qualifs = PerQualif::default();
|
let mut qualifs = PerQualif::default();
|
||||||
qualifs[HasMutInterior] = HasMutInterior::in_local(self, local);
|
qualifs[HasMutInterior] = HasMutInterior::in_local(self, local);
|
||||||
qualifs[NeedsDrop] = NeedsDrop::in_local(self, local);
|
qualifs[NeedsDrop] = NeedsDrop::in_local(self, local);
|
||||||
qualifs[IsNotConst] = IsNotConst::in_local(self, local);
|
qualifs[IsNotPromotable] = IsNotPromotable::in_local(self, local);
|
||||||
qualifs[IsNotImplicitlyPromotable] = IsNotImplicitlyPromotable::in_local(self, local);
|
qualifs[IsNotImplicitlyPromotable] = IsNotImplicitlyPromotable::in_local(self, local);
|
||||||
qualifs
|
qualifs
|
||||||
}
|
}
|
||||||
@ -573,7 +573,7 @@ impl ConstCx<'_, 'tcx> {
|
|||||||
let mut qualifs = PerQualif::default();
|
let mut qualifs = PerQualif::default();
|
||||||
qualifs[HasMutInterior] = HasMutInterior::in_value(self, source);
|
qualifs[HasMutInterior] = HasMutInterior::in_value(self, source);
|
||||||
qualifs[NeedsDrop] = NeedsDrop::in_value(self, source);
|
qualifs[NeedsDrop] = NeedsDrop::in_value(self, source);
|
||||||
qualifs[IsNotConst] = IsNotConst::in_value(self, source);
|
qualifs[IsNotPromotable] = IsNotPromotable::in_value(self, source);
|
||||||
qualifs[IsNotImplicitlyPromotable] = IsNotImplicitlyPromotable::in_value(self, source);
|
qualifs[IsNotImplicitlyPromotable] = IsNotImplicitlyPromotable::in_value(self, source);
|
||||||
qualifs
|
qualifs
|
||||||
}
|
}
|
||||||
@ -638,12 +638,12 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !temps[local].is_promotable() {
|
if !temps[local].is_promotable() {
|
||||||
cx.per_local[IsNotConst].insert(local);
|
cx.per_local[IsNotPromotable].insert(local);
|
||||||
}
|
}
|
||||||
if let LocalKind::Var = mir.local_kind(local) {
|
if let LocalKind::Var = mir.local_kind(local) {
|
||||||
// Sanity check to prevent implicit and explicit promotion of
|
// Sanity check to prevent implicit and explicit promotion of
|
||||||
// named locals
|
// named locals
|
||||||
assert!(cx.per_local[IsNotConst].contains(local));
|
assert!(cx.per_local[IsNotPromotable].contains(local));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,11 +691,11 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
|
|||||||
// the borrowed place is disallowed from being borrowed,
|
// the borrowed place is disallowed from being borrowed,
|
||||||
// due to either a mutable borrow (with some exceptions),
|
// due to either a mutable borrow (with some exceptions),
|
||||||
// or an shared borrow of a value with interior mutability.
|
// or an shared borrow of a value with interior mutability.
|
||||||
// Then `HasMutInterior` is replaced with `IsNotConst`,
|
// Then `HasMutInterior` is replaced with `IsNotPromotable`,
|
||||||
// to avoid duplicate errors (e.g. from reborrowing).
|
// to avoid duplicate errors (e.g. from reborrowing).
|
||||||
if qualifs[HasMutInterior] {
|
if qualifs[HasMutInterior] {
|
||||||
qualifs[HasMutInterior] = false;
|
qualifs[HasMutInterior] = false;
|
||||||
qualifs[IsNotConst] = true;
|
qualifs[IsNotPromotable] = true;
|
||||||
|
|
||||||
if self.mode != Mode::Fn {
|
if self.mode != Mode::Fn {
|
||||||
if let BorrowKind::Mut { .. } = kind {
|
if let BorrowKind::Mut { .. } = kind {
|
||||||
@ -810,7 +810,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the `IsNotConst` qualification is preserved.
|
// Ensure the `IsNotPromotable` qualification is preserved.
|
||||||
// NOTE(eddyb) this is actually unnecessary right now, as
|
// NOTE(eddyb) this is actually unnecessary right now, as
|
||||||
// we never replace the local's qualif, but we might in
|
// we never replace the local's qualif, but we might in
|
||||||
// the future, and so it serves to catch changes that unset
|
// the future, and so it serves to catch changes that unset
|
||||||
@ -818,7 +818,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
|
|||||||
// be replaced with calling `insert` to re-set the bit).
|
// be replaced with calling `insert` to re-set the bit).
|
||||||
if kind == LocalKind::Temp {
|
if kind == LocalKind::Temp {
|
||||||
if !self.temp_promotion_state[index].is_promotable() {
|
if !self.temp_promotion_state[index].is_promotable() {
|
||||||
assert!(self.cx.per_local[IsNotConst].contains(index));
|
assert!(self.cx.per_local[IsNotPromotable].contains(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -904,7 +904,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
|
|||||||
|
|
||||||
// Account for errors in consts by using the
|
// Account for errors in consts by using the
|
||||||
// conservative type qualification instead.
|
// conservative type qualification instead.
|
||||||
if qualifs[IsNotConst] {
|
if qualifs[IsNotPromotable] {
|
||||||
qualifs = self.qualifs_in_any_value_of_ty(mir.return_ty());
|
qualifs = self.qualifs_in_any_value_of_ty(mir.return_ty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1319,7 +1319,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
|||||||
// which happens even without the user requesting it.
|
// which happens even without the user requesting it.
|
||||||
// We can error out with a hard error if the argument is not
|
// We can error out with a hard error if the argument is not
|
||||||
// constant here.
|
// constant here.
|
||||||
if !IsNotConst::in_operand(self, arg) {
|
if !IsNotPromotable::in_operand(self, arg) {
|
||||||
debug!("visit_terminator_kind: candidate={:?}", candidate);
|
debug!("visit_terminator_kind: candidate={:?}", candidate);
|
||||||
self.promotion_candidates.push(candidate);
|
self.promotion_candidates.push(candidate);
|
||||||
} else {
|
} else {
|
||||||
@ -1437,7 +1437,7 @@ fn mir_const_qualif<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||||||
|
|
||||||
if mir.return_ty().references_error() {
|
if mir.return_ty().references_error() {
|
||||||
tcx.sess.delay_span_bug(mir.span, "mir_const_qualif: Mir had errors");
|
tcx.sess.delay_span_bug(mir.span, "mir_const_qualif: Mir had errors");
|
||||||
return (1 << IsNotConst::IDX, Lrc::new(BitSet::new_empty(0)));
|
return (1 << IsNotPromotable::IDX, Lrc::new(BitSet::new_empty(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Checker::new(tcx, def_id, mir, Mode::Const).check_const()
|
Checker::new(tcx, def_id, mir, Mode::Const).check_const()
|
||||||
|
Loading…
Reference in New Issue
Block a user