Skip to content

Commit 8845b97

Browse files
committed
Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin
Replace Rvalue::NullaryOp by a variant in mir::Operand. Based on rust-lang/rust#148151 This PR fully removes the MIR `Rvalue::NullaryOp`. After rust-lang/rust#148151, it was only useful for runtime checks like `ub_checks`, `contract_checks` and `overflow_checks`. These are "runtime" checks, boolean constants that may only be `true` in codegen. It depends on a rustc flag passed to codegen, so we need to represent those flags cross-crate. This PR replaces those runtime checks by special variants in MIR `ConstValue`. This allows code that expects constants to manipulate those as such, even if we may not always be able to evaluate them to actual scalars.
2 parents fabe332 + f57b09d commit 8845b97

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

clippy_utils/src/mir/possible_borrower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'_, '_, 'tcx> {
110110
immutable_borrowers.push(p.local);
111111
}
112112
},
113-
mir::Operand::Constant(..) => (),
113+
mir::Operand::Constant(..) | mir::Operand::RuntimeChecks(..) => (),
114114
}
115115
}
116116

@@ -151,7 +151,7 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
151151

152152
let mut visit_op = |op: &mir::Operand<'_>| match op {
153153
mir::Operand::Copy(p) | mir::Operand::Move(p) => visit(p.local),
154-
mir::Operand::Constant(..) => (),
154+
mir::Operand::Constant(..) | mir::Operand::RuntimeChecks(..) => (),
155155
};
156156

157157
match rvalue {

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_infer::infer::TyCtxtInferExt;
1313
use rustc_infer::traits::Obligation;
1414
use rustc_lint::LateContext;
1515
use rustc_middle::mir::{
16-
Body, CastKind, NonDivergingIntrinsic, NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind,
16+
Body, CastKind, NonDivergingIntrinsic, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind,
1717
Terminator, TerminatorKind,
1818
};
1919
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause};
@@ -194,7 +194,7 @@ fn check_rvalue<'tcx>(
194194
))
195195
}
196196
},
197-
Rvalue::NullaryOp(NullOp::RuntimeChecks(_)) | Rvalue::ShallowInitBox(_, _) => Ok(()),
197+
Rvalue::ShallowInitBox(_, _) => Ok(()),
198198
Rvalue::UnaryOp(_, operand) => {
199199
let ty = operand.ty(body, cx.tcx);
200200
if ty.is_integral() || ty.is_bool() {
@@ -277,6 +277,7 @@ fn check_operand<'tcx>(
277277
Some(_) => Err((span, "cannot access `static` items in const fn".into())),
278278
None => Ok(()),
279279
},
280+
Operand::RuntimeChecks(..) => Ok(()),
280281
}
281282
}
282283

0 commit comments

Comments
 (0)