rustc: Remove the TyCtxt field from ParameterEnvironment.
This commit is contained in:
parent
0053b442f8
commit
8a704f6dc7
20 changed files with 82 additions and 84 deletions
|
|
@ -92,7 +92,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
|||
// For region variables.
|
||||
region_vars: RegionVarBindings<'a, 'tcx>,
|
||||
|
||||
pub parameter_environment: ty::ParameterEnvironment<'a, 'tcx>,
|
||||
pub parameter_environment: ty::ParameterEnvironment<'gcx>,
|
||||
|
||||
// the set of predicates on which errors have been reported, to
|
||||
// avoid reporting the same error twice.
|
||||
|
|
@ -387,7 +387,7 @@ impl fmt::Display for FixupError {
|
|||
impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tables: &'a RefCell<ty::Tables<'tcx>>,
|
||||
param_env: Option<ty::ParameterEnvironment<'a, 'tcx>>,
|
||||
param_env: Option<ty::ParameterEnvironment<'tcx>>,
|
||||
projection_mode: ProjectionMode)
|
||||
-> Self {
|
||||
InferCtxt {
|
||||
|
|
@ -1440,7 +1440,7 @@ pub fn drain_fulfillment_cx<T>(&self,
|
|||
// cases.
|
||||
!traits::type_known_to_meet_builtin_bound(self, ty, ty::BoundCopy, span)
|
||||
} else {
|
||||
ty.moves_by_default(&self.parameter_environment, span)
|
||||
ty.moves_by_default(self.tcx, &self.parameter_environment, span)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1484,7 +1484,7 @@ pub fn drain_fulfillment_cx<T>(&self,
|
|||
self.tables.borrow().upvar_capture_map.get(&upvar_id).cloned()
|
||||
}
|
||||
|
||||
pub fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> {
|
||||
pub fn param_env(&self) -> &ty::ParameterEnvironment<'tcx> {
|
||||
&self.parameter_environment
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub use self::ObligationCauseCode::*;
|
|||
use hir::def_id::DefId;
|
||||
use middle::free_region::FreeRegionMap;
|
||||
use ty::subst;
|
||||
use ty::{self, Ty, TypeFoldable};
|
||||
use ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
use infer::InferCtxt;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
|
@ -378,9 +378,10 @@ pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx, 'tcx
|
|||
|
||||
// FIXME: this is gonna need to be removed ...
|
||||
/// Normalizes the parameter environment, reporting errors if they occur.
|
||||
pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvironment<'a,'tcx>,
|
||||
cause: ObligationCause<'tcx>)
|
||||
-> ty::ParameterEnvironment<'a,'tcx>
|
||||
pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
unnormalized_env: ty::ParameterEnvironment<'tcx>,
|
||||
cause: ObligationCause<'tcx>)
|
||||
-> ty::ParameterEnvironment<'tcx>
|
||||
{
|
||||
// I'm not wild about reporting errors here; I'd prefer to
|
||||
// have the errors get reported at a defined place (e.g.,
|
||||
|
|
@ -397,7 +398,6 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi
|
|||
// and errors will get reported then; so after typeck we
|
||||
// can be sure that no errors should occur.
|
||||
|
||||
let tcx = unnormalized_env.tcx;
|
||||
let span = cause.span;
|
||||
let body_id = cause.body_id;
|
||||
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
|||
self.infcx.tcx
|
||||
}
|
||||
|
||||
pub fn param_env(&self) -> &'cx ty::ParameterEnvironment<'cx, 'tcx> {
|
||||
pub fn param_env(&self) -> &'cx ty::ParameterEnvironment<'tcx> {
|
||||
self.infcx.param_env()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -790,7 +790,7 @@ impl<'a, 'tcx> Layout {
|
|||
ty::TyRef(_, ty::TypeAndMut { ty: pointee, .. }) |
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
|
||||
let non_zero = !ty.is_unsafe_ptr();
|
||||
if pointee.is_sized(&infcx.parameter_environment, DUMMY_SP) {
|
||||
if pointee.is_sized(tcx, &infcx.parameter_environment, DUMMY_SP) {
|
||||
Scalar { value: Pointer, non_zero: non_zero }
|
||||
} else {
|
||||
let unsized_part = tcx.struct_tail(pointee);
|
||||
|
|
@ -883,7 +883,7 @@ impl<'a, 'tcx> Layout {
|
|||
// the unsized field. Several other pieces of code assume that the unsized
|
||||
// field is definitely the last one.
|
||||
if def.dtor_kind().has_drop_flag() &&
|
||||
ty.is_sized(&infcx.parameter_environment, DUMMY_SP) {
|
||||
ty.is_sized(tcx, &infcx.parameter_environment, DUMMY_SP) {
|
||||
st.extend(dl, Some(Ok(&Scalar {
|
||||
value: Int(I8),
|
||||
non_zero: false
|
||||
|
|
|
|||
|
|
@ -1209,9 +1209,7 @@ impl<'tcx> TraitRef<'tcx> {
|
|||
/// future I hope to refine the representation of types so as to make
|
||||
/// more distinctions clearer.
|
||||
#[derive(Clone)]
|
||||
pub struct ParameterEnvironment<'a, 'tcx:'a> {
|
||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
||||
pub struct ParameterEnvironment<'tcx> {
|
||||
/// See `construct_free_substs` for details.
|
||||
pub free_substs: Substs<'tcx>,
|
||||
|
||||
|
|
@ -1243,13 +1241,12 @@ pub struct ParameterEnvironment<'a, 'tcx:'a> {
|
|||
pub free_id_outlive: CodeExtent,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
|
||||
impl<'a, 'tcx> ParameterEnvironment<'tcx> {
|
||||
pub fn with_caller_bounds(&self,
|
||||
caller_bounds: Vec<ty::Predicate<'tcx>>)
|
||||
-> ParameterEnvironment<'a,'tcx>
|
||||
-> ParameterEnvironment<'tcx>
|
||||
{
|
||||
ParameterEnvironment {
|
||||
tcx: self.tcx,
|
||||
free_substs: self.free_substs.clone(),
|
||||
implicit_region_bound: self.implicit_region_bound,
|
||||
caller_bounds: caller_bounds,
|
||||
|
|
@ -1260,7 +1257,8 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Construct a parameter environment given an item, impl item, or trait item
|
||||
pub fn for_item(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: NodeId) -> ParameterEnvironment<'a, 'tcx> {
|
||||
pub fn for_item(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: NodeId)
|
||||
-> ParameterEnvironment<'tcx> {
|
||||
match tcx.map.find(id) {
|
||||
Some(ast_map::NodeImplItem(ref impl_item)) => {
|
||||
match impl_item.node {
|
||||
|
|
@ -2546,14 +2544,14 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
///
|
||||
/// (Note that this implies that if `ty` has a destructor attached,
|
||||
/// then `type_needs_drop` will definitely return `true` for `ty`.)
|
||||
pub fn type_needs_drop_given_env<'b>(self,
|
||||
ty: Ty<'tcx>,
|
||||
param_env: &ty::ParameterEnvironment<'b,'tcx>) -> bool {
|
||||
pub fn type_needs_drop_given_env(self,
|
||||
ty: Ty<'tcx>,
|
||||
param_env: &ty::ParameterEnvironment<'tcx>) -> bool {
|
||||
// Issue #22536: We first query type_moves_by_default. It sees a
|
||||
// normalized version of the type, and therefore will definitely
|
||||
// know whether the type implements Copy (and thus needs no
|
||||
// cleanup/drop/zeroing) ...
|
||||
let implements_copy = !ty.moves_by_default(param_env, DUMMY_SP);
|
||||
let implements_copy = !ty.moves_by_default(self, param_env, DUMMY_SP);
|
||||
|
||||
if implements_copy { return false; }
|
||||
|
||||
|
|
@ -2803,13 +2801,12 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
|
||||
/// Construct a parameter environment suitable for static contexts or other contexts where there
|
||||
/// are no free type/lifetime parameters in scope.
|
||||
pub fn empty_parameter_environment(self) -> ParameterEnvironment<'a,'tcx> {
|
||||
pub fn empty_parameter_environment(self) -> ParameterEnvironment<'tcx> {
|
||||
|
||||
// for an empty parameter environment, there ARE no free
|
||||
// regions, so it shouldn't matter what we use for the free id
|
||||
let free_id_outlive = self.region_maps.node_extent(ast::DUMMY_NODE_ID);
|
||||
ty::ParameterEnvironment { tcx: self,
|
||||
free_substs: Substs::empty(),
|
||||
ty::ParameterEnvironment { free_substs: Substs::empty(),
|
||||
caller_bounds: Vec::new(),
|
||||
implicit_region_bound: ty::ReEmpty,
|
||||
selection_cache: traits::SelectionCache::new(),
|
||||
|
|
@ -2856,7 +2853,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
generics: &ty::Generics<'tcx>,
|
||||
generic_predicates: &ty::GenericPredicates<'tcx>,
|
||||
free_id_outlive: CodeExtent)
|
||||
-> ParameterEnvironment<'a, 'tcx>
|
||||
-> ParameterEnvironment<'tcx>
|
||||
{
|
||||
//
|
||||
// Construct the free substs.
|
||||
|
|
@ -2886,7 +2883,6 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
//
|
||||
|
||||
let unnormalized_env = ty::ParameterEnvironment {
|
||||
tcx: self,
|
||||
free_substs: free_substs,
|
||||
implicit_region_bound: ty::ReScope(free_id_outlive),
|
||||
caller_bounds: predicates,
|
||||
|
|
@ -2896,7 +2892,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
};
|
||||
|
||||
let cause = traits::ObligationCause::misc(span, free_id_outlive.node_id(&self.region_maps));
|
||||
traits::normalize_param_env_or_error(unnormalized_env, cause)
|
||||
traits::normalize_param_env_or_error(self, unnormalized_env, cause)
|
||||
}
|
||||
|
||||
pub fn is_method_call(self, expr_id: NodeId) -> bool {
|
||||
|
|
|
|||
|
|
@ -758,10 +758,9 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeFoldable<'tcx> for ty::ParameterEnvironment<'a, 'tcx> where 'tcx: 'a {
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ParameterEnvironment<'tcx> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::ParameterEnvironment {
|
||||
tcx: self.tcx,
|
||||
free_substs: self.free_substs.fold_with(folder),
|
||||
implicit_region_bound: self.implicit_region_bound.fold_with(folder),
|
||||
caller_bounds: self.caller_bounds.fold_with(folder),
|
||||
|
|
|
|||
|
|
@ -129,11 +129,10 @@ pub enum Representability {
|
|||
SelfRecursive,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
|
||||
pub fn can_type_implement_copy(&self, self_type: Ty<'tcx>, span: Span)
|
||||
-> Result<(),CopyImplementationError> {
|
||||
let tcx = self.tcx;
|
||||
|
||||
impl<'tcx> ParameterEnvironment<'tcx> {
|
||||
pub fn can_type_implement_copy<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
self_type: Ty<'tcx>, span: Span)
|
||||
-> Result<(),CopyImplementationError> {
|
||||
// FIXME: (@jroesch) float this code up
|
||||
let infcx = InferCtxt::new(tcx, &tcx.tables, Some(self.clone()),
|
||||
ProjectionMode::Topmost);
|
||||
|
|
@ -509,12 +508,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> ty::TyS<'tcx> {
|
||||
fn impls_bound(&'tcx self, param_env: &ParameterEnvironment<'a, 'tcx>,
|
||||
bound: ty::BuiltinBound,
|
||||
span: Span)
|
||||
-> bool
|
||||
fn impls_bound(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
param_env: &ParameterEnvironment<'tcx>,
|
||||
bound: ty::BuiltinBound, span: Span) -> bool
|
||||
{
|
||||
let tcx = param_env.tcx;
|
||||
let infcx = InferCtxt::new(tcx, &tcx.tables, Some(param_env.clone()),
|
||||
ProjectionMode::Topmost);
|
||||
|
||||
|
|
@ -528,7 +525,8 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
|||
}
|
||||
|
||||
// FIXME (@jroesch): I made this public to use it, not sure if should be private
|
||||
pub fn moves_by_default(&'tcx self, param_env: &ParameterEnvironment<'a, 'tcx>,
|
||||
pub fn moves_by_default(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
param_env: &ParameterEnvironment<'tcx>,
|
||||
span: Span) -> bool {
|
||||
if self.flags.get().intersects(TypeFlags::MOVENESS_CACHED) {
|
||||
return self.flags.get().intersects(TypeFlags::MOVES_BY_DEFAULT);
|
||||
|
|
@ -550,7 +548,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
|||
TyArray(..) | TySlice(_) | TyTrait(..) | TyTuple(..) |
|
||||
TyClosure(..) | TyEnum(..) | TyStruct(..) |
|
||||
TyProjection(..) | TyParam(..) | TyInfer(..) | TyError => None
|
||||
}.unwrap_or_else(|| !self.impls_bound(param_env, ty::BoundCopy, span));
|
||||
}.unwrap_or_else(|| !self.impls_bound(tcx, param_env, ty::BoundCopy, span));
|
||||
|
||||
if !self.has_param_types() && !self.has_self_ty() {
|
||||
self.flags.set(self.flags.get() | if result {
|
||||
|
|
@ -564,17 +562,19 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_sized(&'tcx self, param_env: &ParameterEnvironment<'a, 'tcx>,
|
||||
pub fn is_sized(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
param_env: &ParameterEnvironment<'tcx>,
|
||||
span: Span) -> bool
|
||||
{
|
||||
if self.flags.get().intersects(TypeFlags::SIZEDNESS_CACHED) {
|
||||
return self.flags.get().intersects(TypeFlags::IS_SIZED);
|
||||
}
|
||||
|
||||
self.is_sized_uncached(param_env, span)
|
||||
self.is_sized_uncached(tcx, param_env, span)
|
||||
}
|
||||
|
||||
fn is_sized_uncached(&'tcx self, param_env: &ParameterEnvironment<'a, 'tcx>,
|
||||
fn is_sized_uncached(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
param_env: &ParameterEnvironment<'tcx>,
|
||||
span: Span) -> bool {
|
||||
assert!(!self.needs_infer());
|
||||
|
||||
|
|
@ -588,7 +588,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
|||
|
||||
TyEnum(..) | TyStruct(..) | TyProjection(..) | TyParam(..) |
|
||||
TyInfer(..) | TyError => None
|
||||
}.unwrap_or_else(|| self.impls_bound(param_env, ty::BoundSized, span));
|
||||
}.unwrap_or_else(|| self.impls_bound(tcx, param_env, ty::BoundSized, span));
|
||||
|
||||
if !self.has_param_types() && !self.has_self_ty() {
|
||||
self.flags.set(self.flags.get() | if result {
|
||||
|
|
|
|||
|
|
@ -557,7 +557,7 @@ impl<'tcx> fmt::Debug for ty::ClosureUpvar<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> fmt::Debug for ty::ParameterEnvironment<'a, 'tcx> {
|
||||
impl<'tcx> fmt::Debug for ty::ParameterEnvironment<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "ParameterEnvironment(\
|
||||
free_substs={:?}, \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue