}
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
-for ::middle::const_val::ConstVal<'gcx> {
+for ::mir::interpret::ConstVal<'gcx> {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
- use middle::const_val::ConstVal::*;
+ use mir::interpret::ConstVal::*;
mem::discriminant(self).hash_stable(hcx, hasher);
val
});
-impl_stable_hash_for!(struct ::middle::const_val::ConstEvalErr<'tcx> {
+impl_stable_hash_for!(struct ::mir::interpret::ConstEvalErr<'tcx> {
span,
stacktrace,
error
});
-impl_stable_hash_for!(struct ::middle::const_val::FrameInfo {
+impl_stable_hash_for!(struct ::mir::interpret::FrameInfo {
span,
lint_root,
location
pub mod allocator;
pub mod borrowck;
pub mod expr_use_visitor;
- pub mod const_val;
pub mod cstore;
pub mod dataflow;
pub mod dead;
+++ /dev/null
-// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use hir::def_id::DefId;
-use ty;
-use ty::subst::Substs;
-use ty::query::TyCtxtAt;
-use mir::interpret::ConstValue;
-use errors::DiagnosticBuilder;
-
-use syntax_pos::Span;
-use syntax::ast;
-
-use rustc_data_structures::sync::Lrc;
-
-pub type EvalResult<'tcx> = Result<&'tcx ty::Const<'tcx>, Lrc<ConstEvalErr<'tcx>>>;
-
-#[derive(Copy, Clone, Debug, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)]
-pub enum ConstVal<'tcx> {
- Unevaluated(DefId, &'tcx Substs<'tcx>),
- Value(ConstValue<'tcx>),
-}
-
-#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
-pub struct ConstEvalErr<'tcx> {
- pub span: Span,
- pub error: ::mir::interpret::EvalError<'tcx>,
- pub stacktrace: Vec<FrameInfo>,
-}
-
-#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
-pub struct FrameInfo {
- pub span: Span,
- pub location: String,
- pub lint_root: Option<ast::NodeId>,
-}
-
-impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
- pub fn struct_error(&self,
- tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
- message: &str)
- -> Option<DiagnosticBuilder<'tcx>>
- {
- self.struct_generic(tcx, message, None)
- }
-
- pub fn report_as_error(&self,
- tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
- message: &str
- ) {
- let err = self.struct_generic(tcx, message, None);
- if let Some(mut err) = err {
- err.emit();
- }
- }
-
- pub fn report_as_lint(&self,
- tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
- message: &str,
- lint_root: ast::NodeId,
- ) {
- let lint = self.struct_generic(
- tcx,
- message,
- Some(lint_root),
- );
- if let Some(mut lint) = lint {
- lint.emit();
- }
- }
-
- fn struct_generic(
- &self,
- tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
- message: &str,
- lint_root: Option<ast::NodeId>,
- ) -> Option<DiagnosticBuilder<'tcx>> {
- match self.error.kind {
- ::mir::interpret::EvalErrorKind::TypeckError |
- ::mir::interpret::EvalErrorKind::TooGeneric |
- ::mir::interpret::EvalErrorKind::CheckMatchError |
- ::mir::interpret::EvalErrorKind::Layout(_) => return None,
- ::mir::interpret::EvalErrorKind::ReferencedConstant(ref inner) => {
- inner.struct_generic(tcx, "referenced constant", lint_root)?.emit();
- },
- _ => {},
- }
- trace!("reporting const eval failure at {:?}", self.span);
- let mut err = if let Some(lint_root) = lint_root {
- let node_id = self.stacktrace
- .iter()
- .rev()
- .filter_map(|frame| frame.lint_root)
- .next()
- .unwrap_or(lint_root);
- tcx.struct_span_lint_node(
- ::rustc::lint::builtin::CONST_ERR,
- node_id,
- tcx.span,
- message,
- )
- } else {
- struct_error(tcx, message)
- };
- err.span_label(self.span, self.error.to_string());
- for FrameInfo { span, location, .. } in &self.stacktrace {
- err.span_label(*span, format!("inside call to `{}`", location));
- }
- Some(err)
- }
-}
-
-pub fn struct_error<'a, 'gcx, 'tcx>(
- tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
- msg: &str,
-) -> DiagnosticBuilder<'tcx> {
- struct_span_err!(tcx.sess, tcx.span, E0080, "{}", msg)
-}
use std::{fmt, env};
use mir;
-use middle::const_val::ConstEvalErr;
use ty::{FnSig, Ty, layout};
use ty::layout::{Size, Align};
use rustc_data_structures::sync::Lrc;
use backtrace::Backtrace;
+
+use hir::def_id::DefId;
+use ty;
+use ty::subst::Substs;
+use ty::query::TyCtxtAt;
+use mir::interpret::ConstValue;
+use errors::DiagnosticBuilder;
+
+use syntax_pos::Span;
+use syntax::ast;
+
+pub type ConstEvalResult<'tcx> = Result<&'tcx ty::Const<'tcx>, Lrc<ConstEvalErr<'tcx>>>;
+
+#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
+pub struct ConstEvalErr<'tcx> {
+ pub span: Span,
+ pub error: ::mir::interpret::EvalError<'tcx>,
+ pub stacktrace: Vec<FrameInfo>,
+}
+
+#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
+pub struct FrameInfo {
+ pub span: Span,
+ pub location: String,
+ pub lint_root: Option<ast::NodeId>,
+}
+
+impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
+ pub fn struct_error(&self,
+ tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
+ message: &str)
+ -> Option<DiagnosticBuilder<'tcx>>
+ {
+ self.struct_generic(tcx, message, None)
+ }
+
+ pub fn report_as_error(&self,
+ tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
+ message: &str
+ ) {
+ let err = self.struct_generic(tcx, message, None);
+ if let Some(mut err) = err {
+ err.emit();
+ }
+ }
+
+ pub fn report_as_lint(&self,
+ tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
+ message: &str,
+ lint_root: ast::NodeId,
+ ) {
+ let lint = self.struct_generic(
+ tcx,
+ message,
+ Some(lint_root),
+ );
+ if let Some(mut lint) = lint {
+ lint.emit();
+ }
+ }
+
+ fn struct_generic(
+ &self,
+ tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
+ message: &str,
+ lint_root: Option<ast::NodeId>,
+ ) -> Option<DiagnosticBuilder<'tcx>> {
+ match self.error.kind {
+ ::mir::interpret::EvalErrorKind::TypeckError |
+ ::mir::interpret::EvalErrorKind::TooGeneric |
+ ::mir::interpret::EvalErrorKind::CheckMatchError |
+ ::mir::interpret::EvalErrorKind::Layout(_) => return None,
+ ::mir::interpret::EvalErrorKind::ReferencedConstant(ref inner) => {
+ inner.struct_generic(tcx, "referenced constant", lint_root)?.emit();
+ },
+ _ => {},
+ }
+ trace!("reporting const eval failure at {:?}", self.span);
+ let mut err = if let Some(lint_root) = lint_root {
+ let node_id = self.stacktrace
+ .iter()
+ .rev()
+ .filter_map(|frame| frame.lint_root)
+ .next()
+ .unwrap_or(lint_root);
+ tcx.struct_span_lint_node(
+ ::rustc::lint::builtin::CONST_ERR,
+ node_id,
+ tcx.span,
+ message,
+ )
+ } else {
+ struct_error(tcx, message)
+ };
+ err.span_label(self.span, self.error.to_string());
+ for FrameInfo { span, location, .. } in &self.stacktrace {
+ err.span_label(*span, format!("inside call to `{}`", location));
+ }
+ Some(err)
+ }
+}
+
+pub fn struct_error<'a, 'gcx, 'tcx>(
+ tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
+ msg: &str,
+) -> DiagnosticBuilder<'tcx> {
+ struct_span_err!(tcx.sess, tcx.span, E0080, "{}", msg)
+}
+
#[derive(Debug, Clone, RustcEncodable, RustcDecodable)]
pub struct EvalError<'tcx> {
pub kind: EvalErrorKind<'tcx, u64>,
mod error;
mod value;
-pub use self::error::{EvalError, EvalResult, EvalErrorKind, AssertMessage};
+pub use self::error::{
+ EvalError, EvalResult, EvalErrorKind, AssertMessage, ConstVal, ConstEvalErr, struct_error,
+ FrameInfo, ConstEvalResult,
+};
pub use self::value::{Scalar, Value, ConstValue};
use super::{EvalResult, Pointer, PointerArithmetic, Allocation};
+#[derive(Copy, Clone, Debug, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)]
+pub enum ConstVal<'tcx> {
+ Value(ConstValue<'tcx>),
+}
+
/// Represents a constant value in Rust. ByVal and ScalarPair are optimizations which
/// matches Value's optimizations for easy conversions between these two types
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)]
pub enum ConstValue<'tcx> {
+ /// Never returned from the `const_eval` query, but the HIR contains these frequently in order
+ /// to allow HIR creation to happen for everything before needing
+ Unevaluated(DefId, &'tcx Substs<'tcx>),
/// Used only for types with layout::abi::Scalar ABI and ZSTs which use Scalar::undef()
Scalar(Scalar),
/// Used only for types with layout::abi::ScalarPair
/// Write a `ConstVal` in a way closer to the original source code than the `Debug` output.
pub fn fmt_const_val<W: Write>(fmt: &mut W, const_val: &ty::Const) -> fmt::Result {
- use middle::const_val::ConstVal;
+ use mir::interpret::ConstVal;
match const_val.val {
ConstVal::Unevaluated(..) => write!(fmt, "{:?}", const_val),
ConstVal::Value(val) => {
use rustc_data_structures::obligation_forest::{ObligationProcessor, ProcessResult};
use std::marker::PhantomData;
use hir::def_id::DefId;
-use middle::const_val::ConstEvalErr;
+use mir::interpret::ConstEvalErr;
use mir::interpret::EvalErrorKind;
use super::CodeAmbiguity;
use hir::def_id::DefId;
use infer::outlives::env::OutlivesEnvironment;
use middle::region;
-use middle::const_val::ConstEvalErr;
+use mir::interpret::ConstEvalErr;
use ty::subst::Substs;
use ty::{self, AdtKind, Slice, Ty, TyCtxt, GenericParamDefKind, ToPredicate};
use ty::error::{ExpectedFound, TypeError};
use hir::def_id::DefId;
use infer::{InferCtxt, InferOk};
use infer::type_variable::TypeVariableOrigin;
-use middle::const_val::ConstVal;
+use mir::interpret::ConstVal;
use mir::interpret::{GlobalId};
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
use syntax::symbol::Symbol;
use infer::{InferCtxt, InferOk};
use infer::at::At;
-use middle::const_val::ConstVal;
-use mir::interpret::GlobalId;
+use mir::interpret::{GlobalId, ConstVal};
use traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
use traits::project::Normalized;
use ty::{self, Ty, TyCtxt};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use middle::const_val::ConstVal;
+use mir::interpret::ConstVal;
use ty::subst::Substs;
use ty::{self, Ty, TypeFlags, TypeFoldable};
//! These methods return true to indicate that the visitor has found what it is looking for
//! and does not need to visit anything else.
-use middle::const_val::ConstVal;
+use mir::interpret::ConstVal;
use hir::def_id::DefId;
use ty::{self, Binder, Ty, TyCtxt, TypeFlags};
})
} else {
info!("invalid enum discriminant: {:#?}", val);
- ::middle::const_val::struct_error(
+ ::mir::interpret::struct_error(
tcx.at(tcx.def_span(expr_did)),
"constant evaluation of enum discriminant resulted in non-integer",
).emit();
use middle::stability::{self, DeprecationEntry};
use middle::lang_items::{LanguageItems, LangItem};
use middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
-use middle::const_val::EvalResult;
+use mir::interpret::ConstEvalResult;
use mir::mono::{CodegenUnit, Stats};
use mir;
use mir::interpret::{GlobalId, Allocation, ConstValue};
/// Results of evaluating const items or constants embedded in
/// other items (such as enum variant explicit discriminants).
[] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
- -> EvalResult<'tcx>,
+ -> ConstEvalResult<'tcx>,
/// Converts a constant value to an constant allocation
[] fn const_value_to_allocation: const_value_to_allocation(
//! type equality, etc.
use hir::def_id::DefId;
-use middle::const_val::ConstVal;
+use mir::interpret::ConstVal;
use ty::subst::{Kind, UnpackedKind, Substs};
use ty::{self, Ty, TyCtxt, TypeFoldable};
use ty::error::{ExpectedFound, TypeError};
//! hand, though we've recently added some macros (e.g.,
//! `BraceStructLiftImpl!`) to help with the tedium.
-use middle::const_val::{ConstVal, ConstEvalErr};
+use mir::interpret::{ConstVal, ConstEvalErr};
use ty::{self, Lift, Ty, TyCtxt};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use rustc_data_structures::accumulate_vec::AccumulateVec;
use hir::def_id::DefId;
-use middle::const_val::ConstVal;
+use mir::interpret::ConstVal;
use middle::region;
use polonius_engine::Atom;
use rustc_data_structures::indexed_vec::Idx;
//! An iterator over the type substructure.
//! WARNING: this does not keep track of the region depth.
-use middle::const_val::ConstVal;
+use mir::interpret::ConstVal;
use ty::{self, Ty};
use rustc_data_structures::small_vec::SmallVec;
use rustc_data_structures::accumulate_vec::IntoIter as AccIntoIter;
// except according to those terms.
use hir::def_id::DefId;
-use middle::const_val::ConstVal;
+use mir::interpret::ConstVal;
use infer::InferCtxt;
use ty::subst::Substs;
use traits;
use hir::def_id::DefId;
use hir::map::definitions::DefPathData;
-use middle::const_val::ConstVal;
+use mir::interpret::ConstVal;
use middle::region::{self, BlockRemainder};
use ty::subst::{self, Subst};
use ty::{BrAnon, BrEnv, BrFresh, BrNamed};
fn fetch_wasm_section(tcx: TyCtxt, id: DefId) -> (String, Vec<u8>) {
use rustc::mir::interpret::GlobalId;
- use rustc::middle::const_val::ConstVal;
+ use rustc::mir::interpret::ConstVal;
info!("loading wasm section {:?}", id);
// except according to those terms.
use llvm::{self, ValueRef};
-use rustc::middle::const_val::{ConstVal, ConstEvalErr};
+use rustc::mir::interpret::{ConstVal, ConstEvalErr};
use rustc_mir::interpret::{read_target_uint, const_val_field};
use rustc::hir::def_id::DefId;
use rustc::mir;
// except according to those terms.
use llvm::{ValueRef, LLVMConstInBoundsGEP};
-use rustc::middle::const_val::ConstEvalErr;
+use rustc::mir::interpret::ConstEvalErr;
use rustc::mir;
use rustc::mir::interpret::ConstValue;
use rustc::ty;
use self::Usefulness::*;
use self::WitnessPreference::*;
-use rustc::middle::const_val::ConstVal;
+use rustc::mir::interpret::ConstVal;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::indexed_vec::Idx;
}
PatternError::FloatBug => {
// FIXME(#31407) this is only necessary because float parsing is buggy
- ::rustc::middle::const_val::struct_error(
+ ::rustc::mir::interpret::struct_error(
self.tcx.at(pat_span),
"could not evaluate float literal (see issue #31407)",
).emit();
}
PatternError::NonConstPath(span) => {
- ::rustc::middle::const_val::struct_error(
+ ::rustc::mir::interpret::struct_error(
self.tcx.at(span),
"runtime values cannot be referenced in patterns",
).emit();
use interpret::{const_val_field, const_variant_index, self};
-use rustc::middle::const_val::ConstVal;
+use rustc::mir::interpret::ConstVal;
use rustc::mir::{fmt_const_val, Field, BorrowKind, Mutability};
use rustc::mir::interpret::{Scalar, GlobalId, ConstValue, Value};
use rustc::ty::{self, TyCtxt, AdtDef, Ty, Region};
use rustc::hir;
-use rustc::middle::const_val::{ConstEvalErr};
+use rustc::mir::interpret::{ConstEvalErr};
use rustc::mir;
use rustc::ty::{self, TyCtxt, Ty, Instance};
use rustc::ty::layout::{self, LayoutOf, Primitive};
field: mir::Field,
value: ConstValue<'tcx>,
ty: Ty<'tcx>,
-) -> ::rustc::middle::const_val::EvalResult<'tcx> {
+) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
trace!("const_val_field: {:?}, {:?}, {:?}, {:?}", instance, field, value, ty);
let mut ecx = mk_eval_cx(tcx, instance, param_env).unwrap();
let result = (|| {
pub fn const_eval_provider<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
-) -> ::rustc::middle::const_val::EvalResult<'tcx> {
+) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
trace!("const eval: {:?}", key);
let cid = key.value;
let def_id = cid.instance.def.def_id();
use rustc::hir::def_id::DefId;
use rustc::hir::def::Def;
use rustc::hir::map::definitions::DefPathData;
-use rustc::middle::const_val::ConstVal;
+use rustc::mir::interpret::ConstVal;
use rustc::mir;
use rustc::ty::layout::{self, Size, Align, HasDataLayout, IntegerExt, LayoutOf, TyLayout};
use rustc::ty::subst::{Subst, Substs};
use rustc::ty::{self, Ty, TyCtxt, TypeAndMut};
use rustc::ty::query::TyCtxtAt;
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
-use rustc::middle::const_val::FrameInfo;
+use rustc::mir::interpret::FrameInfo;
use syntax::codemap::{self, Span};
use syntax::ast::Mutability;
use rustc::mir::interpret::{
use rustc::ty::query::TyCtxtAt;
use rustc::ty::layout::{self, Align, TargetDataLayout, Size};
use syntax::ast::Mutability;
-use rustc::middle::const_val::ConstVal;
+use rustc::mir::interpret::ConstVal;
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
use rustc::mir::interpret::{Pointer, AllocId, Allocation, AccessKind, Value,
use rustc::hir::map as hir_map;
use rustc::hir::def_id::DefId;
-use rustc::middle::const_val::ConstVal;
+use rustc::mir::interpret::ConstVal;
use rustc::mir::interpret::{AllocId, ConstValue};
use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem};
use rustc::ty::subst::Substs;
use rustc::mir::{NullOp, StatementKind, Statement, BasicBlock, LocalKind};
use rustc::mir::{TerminatorKind, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem};
use rustc::mir::visit::{Visitor, PlaceContext};
-use rustc::middle::const_val::{ConstVal, ConstEvalErr};
+use rustc::mir::interpret::{ConstVal, ConstEvalErr};
use rustc::ty::{TyCtxt, self, Instance};
use rustc::mir::interpret::{Value, Scalar, GlobalId, EvalResult};
use interpret::EvalContext;
use rustc_data_structures::fx::FxHashSet;
use rustc::hir;
use rustc::hir::def_id::DefId;
-use rustc::middle::const_val::ConstVal;
+use rustc::mir::interpret::ConstVal;
use rustc::traits::{self, TraitEngine};
use rustc::ty::{self, TyCtxt, Ty, TypeFoldable};
use rustc::ty::cast::CastTy;
use syntax::symbol::{Symbol, InternedString};
use syntax_pos::{self, DUMMY_SP, Pos, FileName};
-use rustc::middle::const_val::ConstVal;
+use rustc::mir::interpret::ConstVal;
use rustc::middle::privacy::AccessLevels;
use rustc::middle::resolve_lifetime as rl;
use rustc::ty::fold::TypeFolder;