diff --git a/frontend/exporter/src/constant_utils.rs b/frontend/exporter/src/constant_utils.rs index 698614328..fb3a4323b 100644 --- a/frontend/exporter/src/constant_utils.rs +++ b/frontend/exporter/src/constant_utils.rs @@ -362,7 +362,7 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug { // Solve the trait obligations let parent_def_id = tcx.parent(ucv.def); - let param_env = tcx.param_env(s.owner_id()); + let param_env = s.param_env(); let trait_refs = solve_item_traits(s, param_env, parent_def_id, ucv.substs, None); @@ -391,13 +391,13 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug { } impl<'tcx> ConstantExt<'tcx> for rustc_middle::ty::Const<'tcx> { fn eval_constant>(&self, s: &S) -> Option { - let evaluated = self.eval(s.base().tcx, get_param_env(s)); + let evaluated = self.eval(s.base().tcx, s.param_env()); (&evaluated != self).then_some(evaluated) } } impl<'tcx> ConstantExt<'tcx> for rustc_middle::mir::ConstantKind<'tcx> { fn eval_constant>(&self, s: &S) -> Option { - let evaluated = self.eval(s.base().tcx, get_param_env(s)); + let evaluated = self.eval(s.base().tcx, s.param_env()); (&evaluated != self).then_some(evaluated) } } @@ -505,7 +505,7 @@ pub(crate) fn const_value_reference_to_constant_expr<'tcx, S: UnderOwnerState<'t let tcx = s.base().tcx; // We use [try_destructure_mir_constant] to destructure the constant - let param_env = get_param_env(s); + let param_env = s.param_env(); // We have to clone some values: it is a bit annoying, but I don't // manage to get the lifetimes working otherwise... let cvalue = rustc_middle::mir::ConstantKind::Val(val, ty); diff --git a/frontend/exporter/src/rustc_utils.rs b/frontend/exporter/src/rustc_utils.rs index 465d24327..676d44407 100644 --- a/frontend/exporter/src/rustc_utils.rs +++ b/frontend/exporter/src/rustc_utils.rs @@ -212,9 +212,14 @@ pub fn translate_span(span: rustc_span::Span, sess: &rustc_session::Session) -> } } -#[tracing::instrument(skip(s))] -pub(crate) fn get_param_env<'tcx, S: UnderOwnerState<'tcx>>(s: &S) -> ty::ParamEnv<'tcx> { - s.base().tcx.param_env(s.owner_id()) +pub trait ParamEnv<'tcx> { + fn param_env(&self) -> ty::ParamEnv<'tcx>; +} + +impl<'tcx, S: UnderOwnerState<'tcx>> ParamEnv<'tcx> for S { + fn param_env(&self) -> ty::ParamEnv<'tcx> { + self.base().tcx.param_env(self.owner_id()) + } } #[tracing::instrument] diff --git a/frontend/exporter/src/traits.rs b/frontend/exporter/src/traits.rs index eb14359db..cf6e821cf 100644 --- a/frontend/exporter/src/traits.rs +++ b/frontend/exporter/src/traits.rs @@ -409,7 +409,7 @@ pub fn super_clause_to_clause_and_impl_expr<'tcx, S: UnderOwnerState<'tcx>>( let impl_expr = new_clause .as_predicate() .to_opt_poly_trait_pred()? - .impl_expr(s, get_param_env(s)); + .impl_expr(s, s.param_env()); let mut new_clause_no_binder = new_clause.sinto(s); new_clause_no_binder.id = original_predicate_id; Some((new_clause_no_binder, impl_expr, span.sinto(s))) diff --git a/frontend/exporter/src/types/copied.rs b/frontend/exporter/src/types/copied.rs index effdaa604..2b36fc032 100644 --- a/frontend/exporter/src/types/copied.rs +++ b/frontend/exporter/src/types/copied.rs @@ -1605,12 +1605,12 @@ impl Alias { let rebased_substs = alias_ty.rebase_substs_onto_impl(alias_ty.substs, tcx); let norm_rebased_substs = tcx.try_subst_and_normalize_erasing_regions( rebased_substs, - get_param_env(s), + s.param_env(), EarlyBinder::bind(trait_ref), ); let norm_substs = tcx.try_subst_and_normalize_erasing_regions( alias_ty.substs, - get_param_env(s), + s.param_env(), EarlyBinder::bind(trait_ref), ); let early_binder_substs = @@ -1636,7 +1636,7 @@ impl Alias { }; AliasKind::Projection { assoc_item: tcx.associated_item(alias_ty.def_id).sinto(s), - impl_expr: poly_trait_ref.impl_expr(s, get_param_env(s)), + impl_expr: poly_trait_ref.impl_expr(s, s.param_env()), } } RustAliasKind::Inherent => AliasKind::Inherent, @@ -1683,8 +1683,7 @@ pub enum Ty { rustc_middle::ty::TyKind::Adt(adt_def, substs) => { let def_id = adt_def.did().sinto(state); let generic_args: Vec = substs.sinto(state); - let param_env = state.base().tcx.param_env(state.owner_id()); - let trait_refs = solve_item_traits(state, param_env, adt_def.did(), substs, None); + let trait_refs = solve_item_traits(state, state.param_env(), adt_def.did(), substs, None); Ty::Adt { def_id, generic_args, trait_refs } }, )] @@ -2224,9 +2223,9 @@ pub enum ExprKind { let tcx = gstate.base().tcx; r#impl = tcx.opt_associated_item(*def_id).as_ref().and_then(|assoc| { poly_trait_ref(gstate, assoc, substs) - }).map(|poly_trait_ref| poly_trait_ref.impl_expr(gstate, get_param_env(gstate))); + }).map(|poly_trait_ref| poly_trait_ref.impl_expr(gstate, gstate.param_env())); generic_args = substs.sinto(gstate); - bounds_impls = solve_item_traits(gstate, get_param_env(gstate), *def_id, substs, None); + bounds_impls = solve_item_traits(gstate, gstate.param_env(), *def_id, substs, None); Expr { contents, span: e.span.sinto(gstate), @@ -2478,7 +2477,7 @@ pub enum ExprKind { let tcx = gstate.base().tcx; tcx.opt_associated_item(*def_id).as_ref().and_then(|assoc| { poly_trait_ref(gstate, assoc, substs) - }).map(|poly_trait_ref| poly_trait_ref.impl_expr(gstate, tcx.param_env(gstate.owner_id()))) + }).map(|poly_trait_ref| poly_trait_ref.impl_expr(gstate, gstate.param_env())) })] r#impl: Option, }, diff --git a/frontend/exporter/src/types/mir.rs b/frontend/exporter/src/types/mir.rs index d4e43f143..a4d7476bb 100644 --- a/frontend/exporter/src/types/mir.rs +++ b/frontend/exporter/src/types/mir.rs @@ -213,7 +213,7 @@ pub(crate) fn get_function_from_def_id_and_substs<'tcx, S: BaseState<'tcx> + Has substs: rustc_middle::ty::subst::SubstsRef<'tcx>, ) -> (DefId, Vec, Vec, Option) { let tcx = s.base().tcx; - let param_env = tcx.param_env(s.owner_id()); + let param_env = s.param_env(); // Retrieve the trait requirements for the **method**. // For instance, if we write: @@ -852,7 +852,7 @@ pub enum AggregateKind { Tuple, #[custom_arm(rustc_middle::mir::AggregateKind::Adt(def_id, vid, substs, annot, fid) => { let adt_kind = s.base().tcx.adt_def(def_id).adt_kind().sinto(s); - let param_env = s.base().tcx.param_env(s.owner_id()); + let param_env = s.param_env(); let trait_refs = solve_item_traits(s, param_env, *def_id, substs, None); AggregateKind::Adt( def_id.sinto(s), @@ -884,7 +884,7 @@ pub enum AggregateKind { // Solve the trait obligations. Note that we solve the parent let tcx = s.base().tcx; - let param_env = tcx.param_env(s.owner_id()); + let param_env = s.param_env(); let parent_substs = closure.parent_substs(); let substs = tcx.mk_substs(parent_substs); // Retrieve the predicates from the parent (i.e., the function which calls diff --git a/frontend/exporter/src/types/mir_traits.rs b/frontend/exporter/src/types/mir_traits.rs index ae0755210..182e4607f 100644 --- a/frontend/exporter/src/types/mir_traits.rs +++ b/frontend/exporter/src/types/mir_traits.rs @@ -8,7 +8,7 @@ pub fn get_trait_info<'tcx, S: UnderOwnerState<'tcx>>( assoc: &rustc_middle::ty::AssocItem, ) -> ImplExpr { let tcx = s.base().tcx; - let param_env = tcx.param_env(s.owner_id()); + let param_env = s.param_env(); // Retrieve the trait let tr_def_id = tcx.trait_of_item(assoc.def_id).unwrap();