Skip to content

Commit 50f8ae3

Browse files
committed
Add a def-id in ty::ParamEnv
1 parent 69007bd commit 50f8ae3

File tree

6 files changed

+48
-18
lines changed

6 files changed

+48
-18
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ for ty::steal::Steal<T>
885885

886886
impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
887887
caller_bounds,
888-
reveal
888+
reveal,
889+
def_id
889890
});
890891

891892
impl_stable_hash_for!(enum traits::Reveal {

src/librustc/traits/auto_trait.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,17 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
388388
computed_preds.extend(user_computed_preds.iter().cloned());
389389
let normalized_preds =
390390
elaborate_predicates(tcx, computed_preds.clone().into_iter().collect());
391-
new_env = ty::ParamEnv::new(tcx.mk_predicates(normalized_preds), param_env.reveal);
391+
new_env = ty::ParamEnv::new(
392+
tcx.mk_predicates(normalized_preds),
393+
param_env.reveal,
394+
None
395+
);
392396
}
393397

394398
let final_user_env = ty::ParamEnv::new(
395399
tcx.mk_predicates(user_computed_preds.into_iter()),
396400
user_env.reveal,
401+
None
397402
);
398403
debug!(
399404
"evaluate_nested_obligations(ty_did={:?}, trait_did={:?}): succeeded with '{:?}' \

src/librustc/traits/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,11 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
804804
debug!("normalize_param_env_or_error: elaborated-predicates={:?}",
805805
predicates);
806806

807-
let elaborated_env = ty::ParamEnv::new(tcx.intern_predicates(&predicates),
808-
unnormalized_env.reveal);
807+
let elaborated_env = ty::ParamEnv::new(
808+
tcx.intern_predicates(&predicates),
809+
unnormalized_env.reveal,
810+
unnormalized_env.def_id
811+
);
809812

810813
// HACK: we are trying to normalize the param-env inside *itself*. The problem is that
811814
// 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>,
852855
// predicates here anyway. Keeping them here anyway because it seems safer.
853856
let outlives_env: Vec<_> =
854857
non_outlives_predicates.iter().chain(&outlives_predicates).cloned().collect();
855-
let outlives_env = ty::ParamEnv::new(tcx.intern_predicates(&outlives_env),
856-
unnormalized_env.reveal);
858+
let outlives_env = ty::ParamEnv::new(
859+
tcx.intern_predicates(&outlives_env),
860+
unnormalized_env.reveal,
861+
None
862+
);
857863
let outlives_predicates =
858864
match do_normalize_predicates(tcx, region_context, cause,
859865
outlives_env, outlives_predicates) {
@@ -869,7 +875,11 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
869875
let mut predicates = non_outlives_predicates;
870876
predicates.extend(outlives_predicates);
871877
debug!("normalize_param_env_or_error: final predicates={:?}", predicates);
872-
ty::ParamEnv::new(tcx.intern_predicates(&predicates), unnormalized_env.reveal)
878+
ty::ParamEnv::new(
879+
tcx.intern_predicates(&predicates),
880+
unnormalized_env.reveal,
881+
unnormalized_env.def_id
882+
)
873883
}
874884

875885
pub fn fully_normalize<'a, 'gcx, 'tcx, T>(

src/librustc/ty/mod.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,11 @@ pub struct ParamEnv<'tcx> {
16171617
/// want `Reveal::All` -- note that this is always paired with an
16181618
/// empty environment. To get that, use `ParamEnv::reveal()`.
16191619
pub reveal: traits::Reveal,
1620+
1621+
/// If this `ParamEnv` comes from a call to `tcx.param_env(def_id)`,
1622+
/// register that `def_id` (useful for transitioning to the chalk trait
1623+
/// solver).
1624+
pub def_id: Option<DefId>,
16201625
}
16211626

16221627
impl<'tcx> ParamEnv<'tcx> {
@@ -1626,7 +1631,7 @@ impl<'tcx> ParamEnv<'tcx> {
16261631
/// type-checking.
16271632
#[inline]
16281633
pub fn empty() -> Self {
1629-
Self::new(List::empty(), Reveal::UserFacing)
1634+
Self::new(List::empty(), Reveal::UserFacing, None)
16301635
}
16311636

16321637
/// Construct a trait environment with no where clauses in scope
@@ -1638,15 +1643,17 @@ impl<'tcx> ParamEnv<'tcx> {
16381643
/// or invoke `param_env.with_reveal_all()`.
16391644
#[inline]
16401645
pub fn reveal_all() -> Self {
1641-
Self::new(List::empty(), Reveal::All)
1646+
Self::new(List::empty(), Reveal::All, None)
16421647
}
16431648

16441649
/// Construct a trait environment with the given set of predicates.
16451650
#[inline]
1646-
pub fn new(caller_bounds: &'tcx List<ty::Predicate<'tcx>>,
1647-
reveal: Reveal)
1648-
-> Self {
1649-
ty::ParamEnv { caller_bounds, reveal }
1651+
pub fn new(
1652+
caller_bounds: &'tcx List<ty::Predicate<'tcx>>,
1653+
reveal: Reveal,
1654+
def_id: Option<DefId>
1655+
) -> Self {
1656+
ty::ParamEnv { caller_bounds, reveal, def_id }
16501657
}
16511658

16521659
/// Returns a new parameter environment with the same clauses, but
@@ -3148,8 +3155,11 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
31483155
// are any errors at that point, so after type checking you can be
31493156
// sure that this will succeed without errors anyway.
31503157

3151-
let unnormalized_env = ty::ParamEnv::new(tcx.intern_predicates(&predicates),
3152-
traits::Reveal::UserFacing);
3158+
let unnormalized_env = ty::ParamEnv::new(
3159+
tcx.intern_predicates(&predicates),
3160+
traits::Reveal::UserFacing,
3161+
Some(def_id)
3162+
);
31533163

31543164
let body_id = tcx.hir().as_local_node_id(def_id).map_or(DUMMY_NODE_ID, |id| {
31553165
tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.node_id)

src/librustc/ty/structural_impls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
276276
ty::ParamEnv {
277277
reveal: self.reveal,
278278
caller_bounds,
279+
def_id: self.def_id,
279280
}
280281
})
281282
}
@@ -589,7 +590,7 @@ impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
589590
}
590591

591592
BraceStructTypeFoldableImpl! {
592-
impl<'tcx> TypeFoldable<'tcx> for ty::ParamEnv<'tcx> { reveal, caller_bounds }
593+
impl<'tcx> TypeFoldable<'tcx> for ty::ParamEnv<'tcx> { reveal, caller_bounds, def_id }
593594
}
594595

595596
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {

src/librustc_typeck/check/compare_method.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,11 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
206206
// The key step here is to update the caller_bounds's predicates to be
207207
// the new hybrid bounds we computed.
208208
let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_node_id);
209-
let param_env = ty::ParamEnv::new(tcx.intern_predicates(&hybrid_preds.predicates),
210-
Reveal::UserFacing);
209+
let param_env = ty::ParamEnv::new(
210+
tcx.intern_predicates(&hybrid_preds.predicates),
211+
Reveal::UserFacing,
212+
None
213+
);
211214
let param_env = traits::normalize_param_env_or_error(tcx,
212215
impl_m.def_id,
213216
param_env,

0 commit comments

Comments
 (0)