refactor ParamEnv::empty(Reveal) into two distinct methods
- `ParamEnv::empty()` -- does not reveal all, good for typeck - `ParamEnv::reveal_all()` -- does, good for trans - `param_env.with_reveal_all()` -- converts an existing parameter environment
This commit is contained in:
parent
1d377d10a1
commit
6d0f9319df
29 changed files with 77 additions and 72 deletions
|
|
@ -28,7 +28,7 @@ use ty::{self, Ty, TyCtxt};
|
|||
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;
|
||||
|
|
@ -563,7 +563,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
{
|
||||
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() {
|
||||
|
|
@ -593,7 +593,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
}
|
||||
|
||||
self.infer_ctxt().enter(|infcx| {
|
||||
value.trans_normalize(&infcx, env.reveal_all())
|
||||
value.trans_normalize(&infcx, env.with_reveal_all())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ use lint::levels::{LintLevelSets, LintLevelsBuilder};
|
|||
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;
|
||||
|
|
@ -1055,7 +1054,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
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};
|
||||
|
|
@ -125,7 +125,7 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
|||
// 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);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ use super::{
|
|||
TraitNotObjectSafe,
|
||||
ConstEvalFailure,
|
||||
PredicateObligation,
|
||||
Reveal,
|
||||
SelectionContext,
|
||||
SelectionError,
|
||||
ObjectSafetyViolation,
|
||||
|
|
@ -140,7 +139,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// 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
|
||||
|
|
|
|||
|
|
@ -695,7 +695,7 @@ fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -777,7 +777,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
|||
// 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);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
|||
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;
|
||||
|
|
@ -132,7 +132,7 @@ pub fn find_associated_item<'a, 'tcx>(
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -425,5 +425,3 @@ BraceStructTypeFoldableImpl! {
|
|||
obligations
|
||||
} where T: TypeFoldable<'tcx>
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ impl<'a, 'b, 'tcx> Instance<'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 {
|
||||
|
|
|
|||
|
|
@ -2058,7 +2058,7 @@ impl<'a, 'tcx> LayoutOf<Ty<'tcx>> for LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
|
|||
/// 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 {
|
||||
|
|
@ -2084,9 +2084,9 @@ impl<'a, 'tcx> LayoutOf<Ty<'tcx>> for LayoutCx<'tcx, ty::maps::TyCtxtAt<'a, 'tcx
|
|||
/// 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
|
||||
|
|
|
|||
|
|
@ -1420,7 +1420,7 @@ impl<'tcx> ParamEnv<'tcx> {
|
|||
}
|
||||
} else {
|
||||
ParamEnvAnd {
|
||||
param_env: ParamEnv::empty(self.reveal),
|
||||
param_env: self.without_caller_bounds(),
|
||||
value,
|
||||
}
|
||||
}
|
||||
|
|
@ -1829,7 +1829,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
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};
|
||||
|
|
@ -473,7 +472,7 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
|||
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(
|
||||
|
|
|
|||
|
|
@ -183,9 +183,22 @@ pub enum Representability {
|
|||
|
||||
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.
|
||||
|
|
@ -202,10 +215,15 @@ impl<'tcx> ty::ParamEnv<'tcx> {
|
|||
/// 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue