Skip to content

Commit bc9ffbe

Browse files
committed
Implement param_env for RPITITs assoc type
1 parent 290c638 commit bc9ffbe

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

compiler/rustc_middle/src/query/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ rustc_queries! {
13241324
/// might want to use `reveal_all()` method to change modes.
13251325
query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
13261326
desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1327+
feedable
13271328
}
13281329

13291330
/// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.

compiler/rustc_ty_utils/src/assoc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ fn impl_associated_item_for_impl_trait_in_trait(
342342
fn_has_self_parameter: false,
343343
});
344344

345+
// Copy param_env of the containing function. The synthesized associated type doesn't have
346+
// extra predicates to assume.
347+
impl_assoc_ty.param_env(tcx.param_env(impl_fn_def_id));
348+
345349
// Copy impl_defaultness of the containing function.
346350
impl_assoc_ty.impl_defaultness(tcx.impl_defaultness(impl_fn_def_id));
347351

compiler/rustc_ty_utils/src/ty.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use rustc_hir as hir;
33
use rustc_hir::def::DefKind;
44
use rustc_index::bit_set::BitSet;
55
use rustc_middle::ty::{
6-
self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt,
7-
TypeSuperVisitable, TypeVisitable, TypeVisitor,
6+
self, Binder, EarlyBinder, ImplTraitInTraitData, Predicate, PredicateKind, ToPredicate, Ty,
7+
TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
88
};
99
use rustc_session::config::TraitSolver;
1010
use rustc_span::def_id::{DefId, CRATE_DEF_ID};
@@ -117,6 +117,15 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] {
117117

118118
/// See `ParamEnv` struct definition for details.
119119
fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
120+
// When computing the param_env of an RPITIT, copy param_env of the containing function. The
121+
// synthesized associated type doesn't have extra predicates to assume.
122+
let def_id =
123+
if let Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) {
124+
fn_def_id
125+
} else {
126+
def_id
127+
};
128+
120129
// Compute the bounds on Self and the type parameters.
121130
let ty::InstantiatedPredicates { mut predicates, .. } =
122131
tcx.predicates_of(def_id).instantiate_identity(tcx);

0 commit comments

Comments
 (0)