Clean up todos
Also add some span_bugs where it is unreachable
This commit is contained in:
parent
217ff6b7ea
commit
4bceb294f4
9 changed files with 63 additions and 78 deletions
|
@ -11,7 +11,6 @@
|
||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![warn(unused_lifetimes)]
|
#![warn(unused_lifetimes)]
|
||||||
#![warn(unreachable_pub)]
|
#![warn(unreachable_pub)]
|
||||||
#![feature(box_patterns)]
|
|
||||||
|
|
||||||
extern crate snap;
|
extern crate snap;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -629,18 +629,11 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
|
||||||
|
|
||||||
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
|
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
|
||||||
..
|
..
|
||||||
/*
|
|
||||||
src,
|
|
||||||
dst,
|
|
||||||
count,
|
|
||||||
*/
|
|
||||||
}) => {
|
}) => {
|
||||||
unreachable!()
|
span_bug!(
|
||||||
/*
|
span,
|
||||||
self.consume_operand(location, (src, span), flow_state);
|
"Unexpected CopyNonOverlapping, should only appear after lower_intrinsics",
|
||||||
self.consume_operand(location, (dst, span), flow_state);
|
)
|
||||||
self.consume_operand(location, (count, span), flow_state);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
StatementKind::Nop
|
StatementKind::Nop
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
|
|
|
@ -1521,40 +1521,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
|
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
|
||||||
ref src,
|
..
|
||||||
ref dst,
|
}) => span_bug!(
|
||||||
ref count,
|
stmt.source_info.span,
|
||||||
}) => {
|
"Unexpected StatementKind::CopyNonOverlapping, should only appear after lowering_intrinsics",
|
||||||
let op_src_ty = self.normalize(src.ty(body, self.tcx()), location);
|
),
|
||||||
let op_dst_ty = self.normalize(dst.ty(body, self.tcx()), location);
|
|
||||||
// since CopyNonOverlapping is parametrized by 1 type,
|
|
||||||
// we only need to check that they are equal and not keep an extra parameter.
|
|
||||||
if let Err(terr) = self.eq_types(
|
|
||||||
op_src_ty,
|
|
||||||
op_dst_ty,
|
|
||||||
location.to_locations(),
|
|
||||||
ConstraintCategory::Internal,
|
|
||||||
) {
|
|
||||||
span_mirbug!(
|
|
||||||
self,
|
|
||||||
stmt,
|
|
||||||
"bad arg ({:?} != {:?}): {:?}",
|
|
||||||
op_src_ty,
|
|
||||||
op_dst_ty,
|
|
||||||
terr
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let op_cnt_ty = self.normalize(count.ty(body, self.tcx()), location);
|
|
||||||
if let Err(terr) = self.eq_types(
|
|
||||||
op_cnt_ty,
|
|
||||||
tcx.types.usize,
|
|
||||||
location.to_locations(),
|
|
||||||
ConstraintCategory::Internal,
|
|
||||||
) {
|
|
||||||
span_mirbug!(self, stmt, "bad arg ({:?} != usize): {:?}", op_cnt_ty, terr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
StatementKind::FakeRead(..)
|
StatementKind::FakeRead(..)
|
||||||
| StatementKind::StorageLive(..)
|
| StatementKind::StorageLive(..)
|
||||||
| StatementKind::StorageDead(..)
|
| StatementKind::StorageDead(..)
|
||||||
|
|
|
@ -305,9 +305,8 @@ impl<'tcx> dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
|
||||||
| mir::StatementKind::Retag { .. }
|
| mir::StatementKind::Retag { .. }
|
||||||
| mir::StatementKind::AscribeUserType(..)
|
| mir::StatementKind::AscribeUserType(..)
|
||||||
| mir::StatementKind::Coverage(..)
|
| mir::StatementKind::Coverage(..)
|
||||||
|
| mir::StatementKind::CopyNonOverlapping(..)
|
||||||
| mir::StatementKind::Nop => {}
|
| mir::StatementKind::Nop => {}
|
||||||
|
|
||||||
mir::StatementKind::CopyNonOverlapping(..) => todo!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -149,9 +149,8 @@ impl<'mir, 'tcx> dataflow::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'mir,
|
||||||
| StatementKind::FakeRead(..)
|
| StatementKind::FakeRead(..)
|
||||||
| StatementKind::Nop
|
| StatementKind::Nop
|
||||||
| StatementKind::Retag(..)
|
| StatementKind::Retag(..)
|
||||||
|
| StatementKind::CopyNonOverlapping(..)
|
||||||
| StatementKind::StorageLive(..) => {}
|
| StatementKind::StorageLive(..) => {}
|
||||||
|
|
||||||
StatementKind::CopyNonOverlapping(..) => todo!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -318,9 +318,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
||||||
StatementKind::Retag { .. }
|
StatementKind::Retag { .. }
|
||||||
| StatementKind::AscribeUserType(..)
|
| StatementKind::AscribeUserType(..)
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
|
| StatementKind::CopyNonOverlapping(..)
|
||||||
| StatementKind::Nop => {}
|
| StatementKind::Nop => {}
|
||||||
|
|
||||||
StatementKind::CopyNonOverlapping(..) => todo!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -323,26 +323,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
let result = Scalar::from_uint(truncated_bits, layout.size);
|
let result = Scalar::from_uint(truncated_bits, layout.size);
|
||||||
self.write_scalar(result, dest)?;
|
self.write_scalar(result, dest)?;
|
||||||
}
|
}
|
||||||
sym::copy_nonoverlapping => {
|
|
||||||
self.copy_nonoverlapping(args[0], args[1], args[2])?;
|
|
||||||
}
|
|
||||||
sym::copy => {
|
sym::copy => {
|
||||||
let elem_ty = instance.substs.type_at(0);
|
self.copy(&args[0], &args[1], &args[2], /*nonoverlapping*/ false)?;
|
||||||
let elem_layout = self.layout_of(elem_ty)?;
|
|
||||||
let count = self.read_scalar(&args[2])?.to_machine_usize(self)?;
|
|
||||||
let elem_align = elem_layout.align.abi;
|
|
||||||
|
|
||||||
let size = elem_layout.size.checked_mul(count, self).ok_or_else(|| {
|
|
||||||
err_ub_format!("overflow computing total size of `{}`", intrinsic_name)
|
|
||||||
})?;
|
|
||||||
let src = self.read_scalar(&args[0])?.check_init()?;
|
|
||||||
let src = self.memory.check_ptr_access(src, size, elem_align)?;
|
|
||||||
let dest = self.read_scalar(&args[1])?.check_init()?;
|
|
||||||
let dest = self.memory.check_ptr_access(dest, size, elem_align)?;
|
|
||||||
|
|
||||||
if let (Some(src), Some(dest)) = (src, dest) {
|
|
||||||
self.memory.copy(src, dest, size, false)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sym::offset => {
|
sym::offset => {
|
||||||
let ptr = self.read_scalar(&args[0])?.check_init()?;
|
let ptr = self.read_scalar(&args[0])?.check_init()?;
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
|
|
||||||
let src = self.eval_operand(src, None)?;
|
let src = self.eval_operand(src, None)?;
|
||||||
let dst = self.eval_operand(dst, None)?;
|
let dst = self.eval_operand(dst, None)?;
|
||||||
self.copy_nonoverlapping(src, dst, count)?;
|
self.copy(&src, &dst, &count, /* nonoverlapping */ true)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Statements we do not track.
|
// Statements we do not track.
|
||||||
|
@ -150,11 +150,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn copy_nonoverlapping(
|
pub(crate) fn copy(
|
||||||
&mut self,
|
&mut self,
|
||||||
src: OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
|
src: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
|
||||||
dst: OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
|
dst: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
|
||||||
count: OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
|
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
|
||||||
|
nonoverlapping: bool,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
|
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
|
||||||
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
|
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
|
||||||
|
@ -170,7 +171,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let (Some(src), Some(dst)) = (src, dst) {
|
if let (Some(src), Some(dst)) = (src, dst) {
|
||||||
self.memory.copy(src, dst, size, /*nonoverlapping*/ true)?;
|
self.memory.copy(src, dst, size, nonoverlapping)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -294,7 +294,49 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
|
||||||
|
ref src,
|
||||||
|
ref dst,
|
||||||
|
ref count,
|
||||||
|
}) => {
|
||||||
|
let src_ty = src.ty(&self.body.local_decls, self.tcx);
|
||||||
|
let op_src_ty = if let Some(src_deref) = src_ty.builtin_deref(true) {
|
||||||
|
src_deref.ty
|
||||||
|
} else {
|
||||||
|
self.fail(
|
||||||
|
location,
|
||||||
|
format!("Expected src to be ptr in copy_nonoverlapping, got: {}", src_ty),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let dst_ty = dst.ty(&self.body.local_decls, self.tcx);
|
||||||
|
let op_dst_ty = if let Some(dst_deref) = dst_ty.builtin_deref(true) {
|
||||||
|
dst_deref.ty
|
||||||
|
} else {
|
||||||
|
self.fail(
|
||||||
|
location,
|
||||||
|
format!("Expected dst to be ptr in copy_nonoverlapping, got: {}", dst_ty),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
// since CopyNonOverlapping is parametrized by 1 type,
|
||||||
|
// we only need to check that they are equal and not keep an extra parameter.
|
||||||
|
if op_src_ty != op_dst_ty {
|
||||||
|
self.fail(location, format!("bad arg ({:?} != {:?})", op_src_ty, op_dst_ty));
|
||||||
|
}
|
||||||
|
|
||||||
|
let op_cnt_ty = count.ty(&self.body.local_decls, self.tcx);
|
||||||
|
if op_cnt_ty != self.tcx.types.usize {
|
||||||
|
self.fail(location, format!("bad arg ({:?} != usize)", op_cnt_ty))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StatementKind::SetDiscriminant { .. }
|
||||||
|
| StatementKind::StorageLive(..)
|
||||||
|
| StatementKind::StorageDead(..)
|
||||||
|
| StatementKind::LlvmInlineAsm(..)
|
||||||
|
| StatementKind::Retag(_, _)
|
||||||
|
| StatementKind::Coverage(_)
|
||||||
|
| StatementKind::Nop => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.super_statement(statement, location);
|
self.super_statement(statement, location);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue