use ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
use ty::fold::TypeFoldable;
use ty::relate::RelateResult;
-use traits::{self, ObligationCause, PredicateObligations, Reveal};
+use traits::{self, ObligationCause, PredicateObligations};
use rustc_data_structures::unify as ut;
use std::cell::{Cell, RefCell, Ref, RefMut};
use std::collections::BTreeMap;
{
debug!("fully_normalize_associated_types_in(t={:?})", value);
- let param_env = ty::ParamEnv::empty(Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
let value = self.erase_regions(value);
if !value.has_projections() {
}
self.infer_ctxt().enter(|infcx| {
- value.trans_normalize(&infcx, env.reveal_all())
+ value.trans_normalize(&infcx, env.with_reveal_all())
})
}
}
use middle::privacy::AccessLevels;
use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
use session::{config, early_error, Session};
-use traits::Reveal;
use ty::{self, TyCtxt, Ty};
use ty::layout::{LayoutError, LayoutOf, TyLayout};
use util::nodemap::FxHashMap;
let mut cx = LateContext {
tcx,
tables: &ty::TypeckTables::empty(None),
- param_env: ty::ParamEnv::empty(Reveal::UserFacing),
+ param_env: ty::ParamEnv::empty(),
access_levels,
lint_sess: LintSession::new(&tcx.sess.lint_store),
last_ast_node_with_lint_attrs: ast::CRATE_NODE_ID,
use hir::def_id::{DefId, LOCAL_CRATE};
use syntax_pos::DUMMY_SP;
-use traits::{self, Normalized, SelectionContext, Obligation, ObligationCause, Reveal};
+use traits::{self, Normalized, SelectionContext, Obligation, ObligationCause};
use traits::IntercrateMode;
use traits::select::IntercrateAmbiguityCause;
use ty::{self, Ty, TyCtxt};
// types into scope; instead, we replace the generic types with
// fresh type variables, and hence we do our evaluations in an
// empty environment.
- let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
+ let param_env = ty::ParamEnv::empty();
let a_impl_header = with_fresh_ty_vars(selcx, param_env, a_def_id);
let b_impl_header = with_fresh_ty_vars(selcx, param_env, b_def_id);
TraitNotObjectSafe,
ConstEvalFailure,
PredicateObligation,
- Reveal,
SelectionContext,
SelectionError,
ObjectSafetyViolation,
// FIXME: I'm just not taking associated types at all here.
// Eventually I'll need to implement param-env-aware
// `Γ₁ ⊦ φ₁ => Γ₂ ⊦ φ₂` logic.
- let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
+ let param_env = ty::ParamEnv::empty();
if let Ok(_) = self.can_sub(param_env, error, implication) {
debug!("error_implies: {:?} -> {:?} -> {:?}", cond, error, implication);
return true
predicates);
let result = tcx.infer_ctxt().enter(|infcx| {
- let param_env = ty::ParamEnv::empty(Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
let mut selcx = SelectionContext::new(&infcx);
let mut fulfill_cx = FulfillmentContext::new();
let cause = ObligationCause::dummy();
// value in order to work, so we can clear out the param env and get better
// caching. (If the current param env is inconsistent, we don't care what happens).
debug!("evaluate_trait_predicate_recursively({:?}) - in global", obligation);
- obligation.param_env = ty::ParamEnv::empty(obligation.param_env.reveal);
+ obligation.param_env = obligation.param_env.without_caller_bounds();
}
let stack = self.push_stack(previous_stack, &obligation);
use hir::def_id::DefId;
use infer::{InferCtxt, InferOk};
use ty::subst::{Subst, Substs};
-use traits::{self, Reveal, ObligationCause};
+use traits::{self, ObligationCause};
use traits::select::IntercrateAmbiguityCause;
use ty::{self, TyCtxt, TypeFoldable};
use syntax_pos::DUMMY_SP;
match ancestors.defs(tcx, item.name, item.kind, trait_def_id).next() {
Some(node_item) => {
let substs = tcx.infer_ctxt().enter(|infcx| {
- let param_env = ty::ParamEnv::empty(Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
let substs = substs.rebase_onto(tcx, trait_def_id, impl_data.substs);
let substs = translate_substs(&infcx, param_env, impl_data.impl_def_id,
substs, node_item.node);
obligations
} where T: TypeFoldable<'tcx>
}
-
-
_ => {
if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
let ty = substs.type_at(0);
- if ty.needs_drop(tcx, ty::ParamEnv::empty(traits::Reveal::All)) {
+ if ty.needs_drop(tcx, ty::ParamEnv::reveal_all()) {
debug!(" => nontrivial drop glue");
ty::InstanceDef::DropGlue(def_id, Some(ty))
} else {
/// Computes the layout of a type. Note that this implicitly
/// executes in "reveal all" mode.
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
- let param_env = self.param_env.reveal_all();
+ let param_env = self.param_env.with_reveal_all();
let ty = self.tcx.normalize_associated_type_in_env(&ty, param_env);
let details = self.tcx.layout_raw(param_env.and(ty))?;
let layout = TyLayout {
/// Computes the layout of a type. Note that this implicitly
/// executes in "reveal all" mode.
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
- let param_env = self.param_env.reveal_all();
- let ty = self.tcx.normalize_associated_type_in_env(&ty, param_env.reveal_all());
- let details = self.tcx.layout_raw(param_env.reveal_all().and(ty))?;
+ let param_env = self.param_env.with_reveal_all();
+ let ty = self.tcx.normalize_associated_type_in_env(&ty, param_env);
+ let details = self.tcx.layout_raw(param_env.and(ty))?;
let layout = TyLayout {
ty,
details
}
} else {
ParamEnvAnd {
- param_env: ParamEnv::empty(self.reveal),
+ param_env: self.without_caller_bounds(),
value,
}
}
tcx: TyCtxt<'a, 'gcx, 'tcx>,
expr_did: DefId,
) -> Option<Discr<'tcx>> {
- let param_env = ParamEnv::empty(traits::Reveal::UserFacing);
+ let param_env = ParamEnv::empty();
let repr_type = self.repr.discr_type();
let bit_size = layout::Integer::from_attr(tcx, repr_type).size().bits();
let substs = Substs::identity_for_item(tcx.global_tcx(), expr_did);
use hir::def_id::DefId;
use middle::const_val::ConstVal;
-use traits::Reveal;
use ty::subst::{Kind, UnpackedKind, Substs};
use ty::{self, Ty, TyCtxt, TypeFoldable};
use ty::error::{ExpectedFound, TypeError};
ConstVal::Value(Value::ByVal(prim)) => Ok(prim.to_u64().unwrap()),
ConstVal::Unevaluated(def_id, substs) => {
// FIXME(eddyb) get the right param_env.
- let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
+ let param_env = ty::ParamEnv::empty();
match tcx.lift_to_global(&substs) {
Some(substs) => {
let instance = ty::Instance::resolve(
impl<'tcx> ty::ParamEnv<'tcx> {
/// Construct a trait environment suitable for contexts where
- /// there are no where clauses in scope.
- pub fn empty(reveal: Reveal) -> Self {
- Self::new(ty::Slice::empty(), reveal, ty::UniverseIndex::ROOT)
+ /// there are no where clauses in scope. Hidden types (like `impl
+ /// Trait`) are left hidden, so this is suitable for ordinary
+ /// type-checking.
+ pub fn empty() -> Self {
+ Self::new(ty::Slice::empty(), Reveal::UserFacing, ty::UniverseIndex::ROOT)
+ }
+
+ /// Construct a trait environment with no where clauses in scope
+ /// where the values of all `impl Trait` and other hidden types
+ /// are revealed. This is suitable for monomorphized, post-typeck
+ /// environments like trans or doing optimizations.
+ ///
+ /// NB. If you want to have predicates in scope, use `ParamEnv::new`,
+ /// or invoke `param_env.with_reveal_all()`.
+ pub fn reveal_all() -> Self {
+ Self::new(ty::Slice::empty(), Reveal::All, ty::UniverseIndex::ROOT)
}
/// Construct a trait environment with the given set of predicates.
/// the desired behavior during trans and certain other special
/// contexts; normally though we want to use `Reveal::UserFacing`,
/// which is the default.
- pub fn reveal_all(self) -> Self {
+ pub fn with_reveal_all(self) -> Self {
ty::ParamEnv { reveal: Reveal::All, ..self }
}
+ /// Returns this same environment but with no caller bounds.
+ pub fn without_caller_bounds(self) -> Self {
+ ty::ParamEnv { caller_bounds: ty::Slice::empty(), ..self }
+ }
+
pub fn can_type_implement_copy<'a>(self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
self_type: Ty<'tcx>, span: Span)
use rustc_resolve::MakeGlobMap;
use rustc::middle::region;
use rustc::ty::subst::Subst;
-use rustc::traits::{ObligationCause, Reveal};
+use rustc::traits::ObligationCause;
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc::ty::maps::OnDiskCache;
use rustc::infer::{self, InferOk, InferResult};
|tcx| {
tcx.infer_ctxt().enter(|infcx| {
let mut region_scope_tree = region::ScopeTree::default();
- let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
+ let param_env = ty::ParamEnv::empty();
body(Env {
infcx: &infcx,
region_scope_tree: &mut region_scope_tree,
use rustc::cfg;
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty};
-use rustc::traits::{self, Reveal};
+use rustc::traits;
use rustc::hir::map as hir_map;
use util::nodemap::NodeSet;
use lint::{LateContext, LintContext, LintArray};
if def.has_dtor(cx.tcx) {
return;
}
- let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
+ let param_env = ty::ParamEnv::empty();
if !ty.moves_by_default(cx.tcx, param_env, item.span) {
return;
}
pub fn const_eval(&self, gid: GlobalId<'tcx>) -> EvalResult<'tcx, &'tcx ty::Const<'tcx>> {
let param_env = if self.tcx.is_static(gid.instance.def_id()).is_some() {
- use rustc::traits;
- ty::ParamEnv::empty(traits::Reveal::All)
+ ty::ParamEnv::reveal_all()
} else {
self.param_env
};
use rustc::middle::const_val::ConstVal;
use rustc::mir::interpret::{Value, PrimVal, AllocId, Pointer};
use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem};
-use rustc::traits;
use rustc::ty::subst::{Substs, Kind};
use rustc::ty::{self, TypeFoldable, Ty, TyCtxt};
use rustc::ty::adjustment::CustomCoerceUnsized;
instance,
promoted: None,
};
- let param_env = ty::ParamEnv::empty(traits::Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
match tcx.const_eval(param_env.and(cid)) {
Ok(val) => collect_const(tcx, val, instance.substs, &mut neighbors),
{
if let ty::TyFnDef(def_id, substs) = ty.sty {
let instance = ty::Instance::resolve(tcx,
- ty::ParamEnv::empty(traits::Reveal::All),
+ ty::ParamEnv::reveal_all(),
def_id,
substs).unwrap();
visit_instance_use(tcx, instance, is_direct_call, output);
let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| {
let type_has_metadata = |ty: Ty<'tcx>| -> bool {
use syntax_pos::DUMMY_SP;
- if ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::empty(traits::Reveal::All)) {
+ if ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all()) {
return false;
}
let tail = tcx.struct_tail(ty);
let methods = methods.iter().cloned().filter_map(|method| method)
.map(|(def_id, substs)| ty::Instance::resolve(
tcx,
- ty::ParamEnv::empty(traits::Reveal::All),
+ ty::ParamEnv::reveal_all(),
def_id,
substs).unwrap())
.filter(|&instance| should_monomorphize_locally(tcx, &instance))
let start_instance = Instance::resolve(
self.tcx,
- ty::ParamEnv::empty(traits::Reveal::All),
+ ty::ParamEnv::reveal_all(),
start_def_id,
self.tcx.mk_substs(iter::once(Kind::from(main_ret_ty)))
).unwrap();
}
let instance = ty::Instance::resolve(tcx,
- ty::ParamEnv::empty(traits::Reveal::All),
+ ty::ParamEnv::reveal_all(),
method.def_id,
callee_substs).unwrap();
output,
param_substs: instance.substs,
}.visit_mir(&mir);
- let param_env = ty::ParamEnv::empty(traits::Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
for (i, promoted) in mir.promoted.iter().enumerate() {
use rustc_data_structures::indexed_vec::Idx;
let cid = GlobalId {
let val = match constant.val {
ConstVal::Unevaluated(def_id, substs) => {
- let param_env = ty::ParamEnv::empty(traits::Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
let substs = tcx.trans_apply_param_substs(param_substs,
&substs);
let instance = ty::Instance::resolve(tcx,
{
let def_id = tcx.require_lang_item(DropInPlaceFnLangItem);
let substs = tcx.intern_substs(&[ty.into()]);
- Instance::resolve(tcx, ty::ParamEnv::empty(traits::Reveal::All), def_id, substs).unwrap()
+ Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap()
}
pub fn custom_coerce_unsize_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
substs: tcx.mk_substs_trait(source_ty, &[target_ty])
});
- match tcx.trans_fulfill_obligation( (ty::ParamEnv::empty(traits::Reveal::All), trait_ref)) {
+ match tcx.trans_fulfill_obligation( (ty::ParamEnv::reveal_all(), trait_ref)) {
traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => {
tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap()
}
use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::middle::const_val::ConstVal;
-use rustc::traits::{self, Reveal};
+use rustc::traits;
use rustc::ty::{self, TyCtxt, Ty, TypeFoldable};
use rustc::ty::cast::CastTy;
use rustc::ty::maps::Providers;
}
let ty = mir.return_ty();
tcx.infer_ctxt().enter(|infcx| {
- let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
+ let param_env = ty::ParamEnv::empty();
let cause = traits::ObligationCause::new(mir.span, id, traits::SharedStatic);
let mut fulfillment_cx = traits::FulfillmentContext::new();
fulfillment_cx.register_bound(&infcx,
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::maps::Providers;
use rustc::ty::subst::Substs;
-use rustc::traits::Reveal;
use rustc::util::nodemap::{ItemLocalSet, NodeSet};
use rustc::hir;
use rustc_data_structures::sync::Lrc;
in_static: false,
promotable: false,
mut_rvalue_borrows: NodeSet(),
- param_env: ty::ParamEnv::empty(Reveal::UserFacing),
+ param_env: ty::ParamEnv::empty(),
identity_substs: Substs::empty(),
result: ItemLocalSet(),
};
use rustc::hir::def_id::DefId;
use rustc::ty::{self, TypeFoldable};
use rustc::ty::layout::LayoutOf;
-use rustc::traits;
use rustc::ty::subst::Substs;
use rustc_back::PanicStrategy;
cx,
ty::Instance::resolve(
cx.tcx,
- ty::ParamEnv::empty(traits::Reveal::All),
+ ty::ParamEnv::reveal_all(),
def_id,
substs
).unwrap()
use type_::Type;
use type_of::LayoutLlvmExt;
use value::Value;
-use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::layout::{HasDataLayout, LayoutOf};
use rustc::hir;
pub use context::CodegenCx;
pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
- ty.needs_drop(tcx, ty::ParamEnv::empty(traits::Reveal::All))
+ ty.needs_drop(tcx, ty::ParamEnv::reveal_all())
}
pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
- ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::empty(traits::Reveal::All))
+ ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all())
}
pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
- ty.is_freeze(tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
+ ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
}
/*
use rustc::dep_graph::DepGraphSafe;
use rustc::hir;
use rustc::hir::def_id::DefId;
-use rustc::traits;
use debuginfo;
use callee;
use base;
pub fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
use syntax_pos::DUMMY_SP;
- if ty.is_sized(self.tcx.at(DUMMY_SP), ty::ParamEnv::empty(traits::Reveal::All)) {
+ if ty.is_sized(self.tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all()) {
return false;
}
type TyLayout = TyLayout<'tcx>;
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
- self.tcx.layout_of(ty::ParamEnv::empty(traits::Reveal::All).and(ty))
+ self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
.unwrap_or_else(|e| match e {
LayoutError::SizeOverflow(_) => self.sess().fatal(&e.to_string()),
_ => bug!("failed to get layout for `{}`: {}", ty, e)
use rustc::middle::lang_items;
use rustc::ty::{self, TypeFoldable};
use rustc::ty::layout::{self, LayoutOf};
-use rustc::traits;
use rustc::mir;
use abi::{Abi, FnType, ArgType, PassMode};
use base;
let (instance, mut llfn) = match callee.layout.ty.sty {
ty::TyFnDef(def_id, substs) => {
(Some(ty::Instance::resolve(bx.cx.tcx,
- ty::ParamEnv::empty(traits::Reveal::All),
+ ty::ParamEnv::reveal_all(),
def_id,
substs).unwrap()),
None)
use rustc::middle::const_val::{ConstVal, ConstEvalErr};
use rustc_mir::interpret::{read_target_uint, const_val_field};
use rustc::hir::def_id::DefId;
-use rustc::traits;
use rustc::mir;
use rustc_data_structures::indexed_vec::Idx;
use rustc::mir::interpret::{Allocation, GlobalId, MemoryPointer, PrimVal, Value as MiriValue};
instance,
promoted: None
};
- let param_env = ty::ParamEnv::empty(traits::Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
cx.tcx.const_eval(param_env.and(cid))?;
let alloc_id = cx
match constant.val {
ConstVal::Unevaluated(def_id, ref substs) => {
let tcx = bx.tcx();
- let param_env = ty::ParamEnv::empty(traits::Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
let instance = ty::Instance::resolve(tcx, param_env, def_id, substs).unwrap();
let cid = GlobalId {
instance,
) -> Result<MiriValue, ConstEvalErr<'tcx>> {
match constant.literal {
mir::Literal::Promoted { index } => {
- let param_env = ty::ParamEnv::empty(traits::Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
let cid = mir::interpret::GlobalId {
instance: self.instance,
promoted: Some(index),
let values: Result<Vec<ValueRef>, _> = (0..fields).map(|field| {
let field = const_val_field(
bx.tcx(),
- ty::ParamEnv::empty(traits::Reveal::All),
+ ty::ParamEnv::reveal_all(),
self.instance,
None,
mir::Field::new(field as usize),
ty::TraitContainer(_) => tcx.mk_self_type()
};
let self_arg_ty = *tcx.fn_sig(method.def_id).input(0).skip_binder();
- let param_env = ty::ParamEnv::empty(Reveal::All);
+ let param_env = ty::ParamEnv::reveal_all();
tcx.infer_ctxt().enter(|infcx| {
let self_arg_ty = tcx.liberate_late_bound_regions(
debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref);
tcx.infer_ctxt().enter(|infcx| {
- let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
+ let param_env = ty::ParamEnv::empty();
let inh = Inherited::new(infcx, impl_c.def_id);
let infcx = &inh.infcx;
use rustc::middle::region;
use rustc::ty::subst::{Subst, Substs, UnpackedKind};
use rustc::ty::{self, Ty, TyCtxt};
-use rustc::traits::{self, Reveal, ObligationCause};
+use rustc::traits::{self, ObligationCause};
use util::common::ErrorReported;
use util::nodemap::FxHashSet;
// it did the wrong thing, so I chose to preserve existing
// behavior, since it ought to be simply more
// conservative. -nmatsakis
- let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty(Reveal::UserFacing));
+ let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty());
infcx.resolve_regions_and_report_errors(drop_impl_did, ®ion_scope_tree, &outlives_env);
Ok(())
}
hir::ExprRepeat(ref element, count) => {
let count_def_id = tcx.hir.body_owner_def_id(count);
- let param_env = ty::ParamEnv::empty(traits::Reveal::UserFacing);
+ let param_env = ty::ParamEnv::empty();
let substs = Substs::identity_for_item(tcx.global_tcx(), count_def_id);
let instance = ty::Instance::resolve(
tcx.global_tcx(),
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::maps::Providers;
-use rustc::traits::{FulfillmentContext, ObligationCause, ObligationCauseCode, Reveal};
+use rustc::traits::{FulfillmentContext, ObligationCause, ObligationCauseCode};
use session::{CompileIncomplete, config};
use util::common::time;
actual: Ty<'tcx>)
-> bool {
tcx.infer_ctxt().enter(|ref infcx| {
- let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
+ let param_env = ty::ParamEnv::empty();
let mut fulfill_cx = FulfillmentContext::new();
match infcx.at(&cause, param_env).eq(expected, actual) {
Ok(InferOk { obligations, .. }) => {