};
use rustc::mir::{
read_only, AggregateKind, BasicBlock, BinOp, Body, BodyAndCache, ClearCrossCrate, Constant,
- Local, LocalDecl, LocalKind, Location, Operand, Place, PlaceBase, ReadOnlyBodyAndCache, Rvalue,
+ Local, LocalDecl, LocalKind, Location, Operand, Place, ReadOnlyBodyAndCache, Rvalue,
SourceInfo, SourceScope, SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind,
UnOp, RETURN_PLACE,
};
use rustc::ty::layout::{
HasDataLayout, HasTyCtxt, LayoutError, LayoutOf, Size, TargetDataLayout, TyLayout,
};
-use rustc::ty::subst::InternalSubsts;
+use rustc::ty::subst::{InternalSubsts, Subst};
use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def::DefKind;
LocalState, LocalValue, Memory, MemoryKind, OpTy, Operand as InterpOperand, PlaceTy, Pointer,
ScalarMaybeUndef, StackPopCleanup,
};
-use crate::rustc::ty::subst::Subst;
use crate::transform::{MirPass, MirSource};
/// The maximum number of bytes that we'll allocate space for a return value.
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
// the last known `SourceInfo` here and just keep revisiting it.
source_info: Option<SourceInfo>,
+ lint_root: Option<HirId>,
}
impl<'mir, 'tcx> LayoutOf for ConstPropagator<'mir, 'tcx> {
local_decls: body.local_decls.clone(),
ret: ret.map(Into::into),
source_info: None,
+ lint_root: None,
}
}
F: FnOnce(&mut Self) -> InterpResult<'tcx, T>,
{
self.ecx.tcx.span = source_info.span;
- // FIXME(eddyb) move this to the `Panic(_)` error case, so that
- // `f(self)` is always called, and that the only difference when the
- // scope's `local_data` is missing, is that the lint isn't emitted.
- let lint_root = self.lint_root(source_info)?;
let r = match f(self) {
Ok(val) => Some(val),
Err(error) => {
diagnostic.report_as_lint(
self.ecx.tcx,
"this expression will panic at runtime",
- lint_root,
+ self.lint_root?,
None,
);
}
r
}
- fn eval_constant(
- &mut self,
- c: &Constant<'tcx>,
- source_info: SourceInfo,
- ) -> Option<Const<'tcx>> {
+ fn eval_constant(&mut self, c: &Constant<'tcx>) -> Option<Const<'tcx>> {
self.ecx.tcx.span = c.span;
+
+ // FIXME we need to revisit this for #67176
+ if c.needs_subst() {
+ return None;
+ }
+
match self.ecx.eval_const_to_op(c.literal, None) {
Ok(op) => Some(op),
Err(error) => {
let err = error_to_const_error(&self.ecx, error);
- match self.lint_root(source_info) {
+ match self.lint_root {
Some(lint_root) if c.literal.needs_subst() => {
// Out of backwards compatibility we cannot report hard errors in unused
// generic functions using associated constants of the generic parameters.
fn eval_operand(&mut self, op: &Operand<'tcx>, source_info: SourceInfo) -> Option<Const<'tcx>> {
match *op {
- Operand::Constant(ref c) => self.eval_constant(c, source_info),
+ Operand::Constant(ref c) => self.eval_constant(c),
Operand::Move(ref place) | Operand::Copy(ref place) => {
self.eval_place(place, source_info)
}
return None;
}
+ // FIXME we need to revisit this for #67176
+ if rvalue.needs_subst() {
+ return None;
+ }
+
let overflow_check = self.tcx.sess.overflow_checks();
// Perform any special handling for specific Rvalue types.
ScalarMaybeUndef::Scalar(r),
)) => l.is_bits() && r.is_bits(),
interpret::Operand::Indirect(_) if mir_opt_level >= 2 => {
- intern_const_alloc_recursive(&mut self.ecx, None, op.assert_mem_place())
+ let mplace = op.assert_mem_place(&self.ecx);
+ intern_const_alloc_recursive(&mut self.ecx, None, mplace, false)
.expect("failed to intern alloc");
true
}
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
trace!("visit_constant: {:?}", constant);
self.super_constant(constant, location);
- self.eval_constant(constant, self.source_info.unwrap());
+ self.eval_constant(constant);
}
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
trace!("visit_statement: {:?}", statement);
let source_info = statement.source_info;
self.source_info = Some(source_info);
+ self.lint_root = self.lint_root(source_info);
if let StatementKind::Assign(box (ref place, ref mut rval)) = statement.kind {
let place_ty: Ty<'tcx> = place.ty(&self.local_decls, self.tcx).ty;
if let Ok(place_layout) = self.tcx.layout_of(self.param_env.and(place_ty)) {
let source_info = terminator.source_info;
self.source_info = Some(source_info);
self.super_terminator(terminator, location);
+ self.lint_root = self.lint_root(source_info);
match &mut terminator.kind {
TerminatorKind::Assert { expected, ref msg, ref mut cond, .. } => {
if let Some(value) = self.eval_operand(&cond, source_info) {
// doesn't use the invalid value
match cond {
Operand::Move(ref place) | Operand::Copy(ref place) => {
- if let PlaceBase::Local(local) = place.base {
- self.remove_const(local);
- }
+ self.remove_const(place.local);
}
Operand::Constant(_) => {}
}