impl<'tcx> Body<'tcx> {
pub fn new(
+ tcx: TyCtxt<'tcx>,
source: MirSource<'tcx>,
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
predecessor_cache: PredecessorCache::new(),
is_cyclic: GraphIsCyclicCache::new(),
};
- body.is_polymorphic = body.has_param_types_or_consts();
+ body.is_polymorphic = body.definitely_has_param_types_or_consts(tcx);
body
}
/// is only useful for testing but cannot be `#[cfg(test)]` because it is used in a different
/// crate.
pub fn new_cfg_only(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>) -> Self {
- let mut body = Body {
+ Body {
phase: MirPhase::Build,
source: MirSource::item(DefId::local(CRATE_DEF_INDEX)),
basic_blocks,
is_polymorphic: false,
predecessor_cache: PredecessorCache::new(),
is_cyclic: GraphIsCyclicCache::new(),
- };
- body.is_polymorphic = body.has_param_types_or_consts();
- body
+ }
}
#[inline]
/// Returns an iterator over all function arguments.
#[inline]
pub fn args_iter(&self) -> impl Iterator<Item = Local> + ExactSizeIterator {
- let arg_count = self.arg_count;
- (1..arg_count + 1).map(Local::new)
+ (1..self.arg_count + 1).map(Local::new)
}
/// Returns an iterator over all user-defined variables and compiler-generated temporaries (all
pub fn vars_and_temps_iter(
&self,
) -> impl DoubleEndedIterator<Item = Local> + ExactSizeIterator {
- let arg_count = self.arg_count;
- let local_count = self.local_decls.len();
- (arg_count + 1..local_count).map(Local::new)
+ (self.arg_count + 1..self.local_decls.len()).map(Local::new)
+ }
+
+ #[inline]
+ pub fn drain_vars_and_temps<'a>(&'a mut self) -> impl Iterator<Item = LocalDecl<'tcx>> + 'a {
+ self.local_decls.drain(self.arg_count + 1..)
}
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)
}
- Coverage(box ref coverage) => {
- if let Some(rgn) = &coverage.code_region {
- write!(fmt, "Coverage::{:?} for {:?}", coverage.kind, rgn)
- } else {
- write!(fmt, "Coverage::{:?}", coverage.kind)
- }
+ Coverage(box self::Coverage { ref kind, code_region: Some(ref rgn) }) => {
+ write!(fmt, "Coverage::{:?} for {:?}", kind, rgn)
}
+ Coverage(box ref coverage) => write!(fmt, "Coverage::{:?}", coverage.kind),
CopyNonOverlapping(box crate::mir::CopyNonOverlapping {
ref src,
ref dst,
span: Span,
) -> Self {
let ty = tcx.type_of(def_id).subst(tcx, substs);
- Operand::Constant(box Constant {
+ Operand::Constant(Box::new(Constant {
span,
user_ty: None,
literal: ConstantKind::Ty(ty::Const::zero_sized(tcx, ty)),
- })
+ }))
}
pub fn is_move(&self) -> bool {
};
scalar_size == type_size
});
- Operand::Constant(box Constant {
+ Operand::Constant(Box::new(Constant {
span,
user_ty: None,
literal: ConstantKind::Val(ConstValue::Scalar(val), ty),
- })
+ }))
}
pub fn to_copy(&self) -> Self {