diff options
| author | scalexm <alexandre@scalexm.fr> | 2018-11-17 18:56:14 +0100 |
|---|---|---|
| committer | scalexm <alexandre@scalexm.fr> | 2018-12-27 19:21:15 +0100 |
| commit | 50f8ae364ba5d8277ddc551637ff7d5470495813 (patch) | |
| tree | 5b8ce20ad18b8bdcf1b22410eeac62a9b74d8429 | |
| parent | 69007bd6606b19b56e64c77b0270353a09a3f373 (diff) | |
| download | rust-50f8ae364ba5d8277ddc551637ff7d5470495813.tar.gz rust-50f8ae364ba5d8277ddc551637ff7d5470495813.zip | |
Add a def-id in `ty::ParamEnv`
| -rw-r--r-- | src/librustc/ich/impls_ty.rs | 3 | ||||
| -rw-r--r-- | src/librustc/traits/auto_trait.rs | 7 | ||||
| -rw-r--r-- | src/librustc/traits/mod.rs | 20 | ||||
| -rw-r--r-- | src/librustc/ty/mod.rs | 26 | ||||
| -rw-r--r-- | src/librustc/ty/structural_impls.rs | 3 | ||||
| -rw-r--r-- | src/librustc_typeck/check/compare_method.rs | 7 |
6 files changed, 48 insertions, 18 deletions
diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 3c68da5d90b..86dcec686f9 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -885,7 +885,8 @@ for ty::steal::Steal<T> impl_stable_hash_for!(struct ty::ParamEnv<'tcx> { caller_bounds, - reveal + reveal, + def_id }); impl_stable_hash_for!(enum traits::Reveal { diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index edcdf7f7f9e..f96c4e9014b 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -388,12 +388,17 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { computed_preds.extend(user_computed_preds.iter().cloned()); let normalized_preds = elaborate_predicates(tcx, computed_preds.clone().into_iter().collect()); - new_env = ty::ParamEnv::new(tcx.mk_predicates(normalized_preds), param_env.reveal); + new_env = ty::ParamEnv::new( + tcx.mk_predicates(normalized_preds), + param_env.reveal, + None + ); } let final_user_env = ty::ParamEnv::new( tcx.mk_predicates(user_computed_preds.into_iter()), user_env.reveal, + None ); debug!( "evaluate_nested_obligations(ty_did={:?}, trait_did={:?}): succeeded with '{:?}' \ diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 448f8ed8ddc..696033d0465 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -804,8 +804,11 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates); - let elaborated_env = ty::ParamEnv::new(tcx.intern_predicates(&predicates), - unnormalized_env.reveal); + let elaborated_env = ty::ParamEnv::new( + tcx.intern_predicates(&predicates), + unnormalized_env.reveal, + unnormalized_env.def_id + ); // HACK: we are trying to normalize the param-env inside *itself*. The problem is that // normalization expects its param-env to be already normalized, which means we have @@ -852,8 +855,11 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // predicates here anyway. Keeping them here anyway because it seems safer. let outlives_env: Vec<_> = non_outlives_predicates.iter().chain(&outlives_predicates).cloned().collect(); - let outlives_env = ty::ParamEnv::new(tcx.intern_predicates(&outlives_env), - unnormalized_env.reveal); + let outlives_env = ty::ParamEnv::new( + tcx.intern_predicates(&outlives_env), + unnormalized_env.reveal, + None + ); let outlives_predicates = match do_normalize_predicates(tcx, region_context, cause, outlives_env, outlives_predicates) { @@ -869,7 +875,11 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut predicates = non_outlives_predicates; predicates.extend(outlives_predicates); debug!("normalize_param_env_or_error: final predicates={:?}", predicates); - ty::ParamEnv::new(tcx.intern_predicates(&predicates), unnormalized_env.reveal) + ty::ParamEnv::new( + tcx.intern_predicates(&predicates), + unnormalized_env.reveal, + unnormalized_env.def_id + ) } pub fn fully_normalize<'a, 'gcx, 'tcx, T>( diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 2256cd4364b..78ce76a0148 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1617,6 +1617,11 @@ pub struct ParamEnv<'tcx> { /// want `Reveal::All` -- note that this is always paired with an /// empty environment. To get that, use `ParamEnv::reveal()`. pub reveal: traits::Reveal, + + /// If this `ParamEnv` comes from a call to `tcx.param_env(def_id)`, + /// register that `def_id` (useful for transitioning to the chalk trait + /// solver). + pub def_id: Option<DefId>, } impl<'tcx> ParamEnv<'tcx> { @@ -1626,7 +1631,7 @@ impl<'tcx> ParamEnv<'tcx> { /// type-checking. #[inline] pub fn empty() -> Self { - Self::new(List::empty(), Reveal::UserFacing) + Self::new(List::empty(), Reveal::UserFacing, None) } /// Construct a trait environment with no where clauses in scope @@ -1638,15 +1643,17 @@ impl<'tcx> ParamEnv<'tcx> { /// or invoke `param_env.with_reveal_all()`. #[inline] pub fn reveal_all() -> Self { - Self::new(List::empty(), Reveal::All) + Self::new(List::empty(), Reveal::All, None) } /// Construct a trait environment with the given set of predicates. #[inline] - pub fn new(caller_bounds: &'tcx List<ty::Predicate<'tcx>>, - reveal: Reveal) - -> Self { - ty::ParamEnv { caller_bounds, reveal } + pub fn new( + caller_bounds: &'tcx List<ty::Predicate<'tcx>>, + reveal: Reveal, + def_id: Option<DefId> + ) -> Self { + ty::ParamEnv { caller_bounds, reveal, def_id } } /// Returns a new parameter environment with the same clauses, but @@ -3148,8 +3155,11 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // are any errors at that point, so after type checking you can be // sure that this will succeed without errors anyway. - let unnormalized_env = ty::ParamEnv::new(tcx.intern_predicates(&predicates), - traits::Reveal::UserFacing); + let unnormalized_env = ty::ParamEnv::new( + tcx.intern_predicates(&predicates), + traits::Reveal::UserFacing, + Some(def_id) + ); let body_id = tcx.hir().as_local_node_id(def_id).map_or(DUMMY_NODE_ID, |id| { tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.node_id) diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 51afb91de78..4755adc4cd1 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -276,6 +276,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> { ty::ParamEnv { reveal: self.reveal, caller_bounds, + def_id: self.def_id, } }) } @@ -589,7 +590,7 @@ impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> { } BraceStructTypeFoldableImpl! { - impl<'tcx> TypeFoldable<'tcx> for ty::ParamEnv<'tcx> { reveal, caller_bounds } + impl<'tcx> TypeFoldable<'tcx> for ty::ParamEnv<'tcx> { reveal, caller_bounds, def_id } } impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> { diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index ec5aa7c004b..8c193cc8ff1 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -206,8 +206,11 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // The key step here is to update the caller_bounds's predicates to be // the new hybrid bounds we computed. let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_node_id); - let param_env = ty::ParamEnv::new(tcx.intern_predicates(&hybrid_preds.predicates), - Reveal::UserFacing); + let param_env = ty::ParamEnv::new( + tcx.intern_predicates(&hybrid_preds.predicates), + Reveal::UserFacing, + None + ); let param_env = traits::normalize_param_env_or_error(tcx, impl_m.def_id, param_env, |
