mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 14:10:03 +03:00
Merge pull request #54 from oli-obk/clippy
Clippy and `assume` intrinsic implementation
This commit is contained in:
@@ -43,6 +43,7 @@ pub enum EvalError<'tcx> {
|
||||
CalledClosureAsFunction,
|
||||
VtableForArgumentlessMethod,
|
||||
ModifiedConstantMemory,
|
||||
AssumptionNotHeld,
|
||||
}
|
||||
|
||||
pub type EvalResult<'tcx, T> = Result<T, EvalError<'tcx>>;
|
||||
@@ -97,6 +98,8 @@ fn description(&self) -> &str {
|
||||
"tried to call a vtable function without arguments",
|
||||
EvalError::ModifiedConstantMemory =>
|
||||
"tried to modify constant memory",
|
||||
EvalError::AssumptionNotHeld =>
|
||||
"`assume` argument was false"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ pub fn step(&mut self) -> EvalResult<'tcx, bool> {
|
||||
let mir = self.mir();
|
||||
let basic_block = &mir.basic_blocks()[block];
|
||||
|
||||
if let Some(ref stmt) = basic_block.statements.get(stmt_id) {
|
||||
if let Some(stmt) = basic_block.statements.get(stmt_id) {
|
||||
let mut new = Ok(0);
|
||||
ConstantExtractor {
|
||||
span: stmt.source_info.span,
|
||||
|
||||
@@ -284,8 +284,11 @@ fn call_intrinsic(
|
||||
"sub_with_overflow" => self.intrinsic_with_overflow(mir::BinOp::Sub, &args[0], &args[1], dest, dest_layout)?,
|
||||
"mul_with_overflow" => self.intrinsic_with_overflow(mir::BinOp::Mul, &args[0], &args[1], dest, dest_layout)?,
|
||||
|
||||
// FIXME: turn into an assertion to catch wrong `assume` that would cause UB in llvm
|
||||
"assume" => {}
|
||||
"assume" => {
|
||||
if !self.memory.read_bool(args_ptrs[0])? {
|
||||
return Err(EvalError::AssumptionNotHeld);
|
||||
}
|
||||
}
|
||||
|
||||
"copy_nonoverlapping" => {
|
||||
let elem_ty = substs.type_at(0);
|
||||
|
||||
@@ -20,8 +20,8 @@ pub fn get_vtable(&mut self, trait_ref: ty::PolyTraitRef<'tcx>) -> EvalResult<'t
|
||||
|
||||
debug!("get_vtable(trait_ref={:?})", trait_ref);
|
||||
|
||||
let methods: Vec<_> = traits::supertraits(tcx, trait_ref.clone()).flat_map(|trait_ref| {
|
||||
match self.fulfill_obligation(trait_ref.clone()) {
|
||||
let methods: Vec<_> = traits::supertraits(tcx, trait_ref).flat_map(|trait_ref| {
|
||||
match self.fulfill_obligation(trait_ref) {
|
||||
// Should default trait error here?
|
||||
traits::VtableDefaultImpl(_) |
|
||||
traits::VtableBuiltin(_) => {
|
||||
@@ -164,7 +164,7 @@ fn get_vtable_methods(&mut self, impl_id: DefId, substs: &'tcx Substs<'tcx>) ->
|
||||
// method could then never be called, so we do not want to
|
||||
// try and trans it, in that case. Issue #23435.
|
||||
if mth.is_provided {
|
||||
let predicates = mth.method.predicates.predicates.subst(self.tcx, &mth.substs);
|
||||
let predicates = mth.method.predicates.predicates.subst(self.tcx, mth.substs);
|
||||
if !self.normalize_and_test_predicates(predicates) {
|
||||
debug!("get_vtable_methods: predicates do not hold");
|
||||
return None;
|
||||
|
||||
+1
-1
@@ -314,7 +314,7 @@ pub fn get_closure(&self, id: AllocId) -> EvalResult<'tcx, (DefId, ClosureSubsts
|
||||
Some(&FunctionDefinition {
|
||||
def_id,
|
||||
kind: FunctionKind::Closure { ref substs, ref ty }
|
||||
}) => Ok((def_id, substs.clone(), ty.clone())),
|
||||
}) => Ok((def_id, *substs, ty.clone())),
|
||||
Some(&FunctionDefinition {
|
||||
kind: FunctionKind::Function { .. }, ..
|
||||
}) => Err(EvalError::CalledClosureAsFunction),
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#![feature(core_intrinsics)]
|
||||
|
||||
fn main() {
|
||||
let x = 5;
|
||||
unsafe {
|
||||
std::intrinsics::assume(x < 10);
|
||||
std::intrinsics::assume(x > 1);
|
||||
std::intrinsics::assume(x > 42); //~ ERROR: `assume` argument was false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user