Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 77b0c47

Browse files
committed
Normalize param_env for trait assoc consts in typeck
1 parent 07608bd commit 77b0c47

File tree

2 files changed

+10
-2
lines changed
  • compiler
    • rustc_trait_selection/src/traits
    • rustc_typeck/src/check/fn_ctxt

2 files changed

+10
-2
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn predicates_for_generics<'tcx>(
130130
move |(idx, (predicate, span))| Obligation {
131131
cause: cause(idx, span),
132132
recursion_depth: 0,
133-
param_env: param_env,
133+
param_env,
134134
predicate,
135135
},
136136
)

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,13 +1418,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14181418
substs: SubstsRef<'tcx>,
14191419
code: impl Fn(usize, Span) -> ObligationCauseCode<'tcx>,
14201420
) {
1421+
// Associated consts have `Self: ~const Trait` bounds that should be satisfiable when
1422+
// `Self: Trait` is satisfied because it does not matter whether the impl is `const`.
1423+
// Therefore we have to remap the param env here to be non-const.
1424+
let param_env = if let hir::def::DefKind::AssocConst = self.tcx.def_kind(def_id) {
1425+
self.param_env.without_const()
1426+
} else {
1427+
self.param_env
1428+
};
14211429
let (bounds, _) = self.instantiate_bounds(span, def_id, &substs);
14221430

14231431
for obligation in traits::predicates_for_generics(
14241432
|idx, predicate_span| {
14251433
traits::ObligationCause::new(span, self.body_id, code(idx, predicate_span))
14261434
},
1427-
self.param_env,
1435+
param_env,
14281436
bounds,
14291437
) {
14301438
self.register_predicate(obligation);

0 commit comments

Comments
 (0)