From 77b0c47b8284bbb24dab9a5ff95b93f083ce7c54 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 28 Aug 2022 06:27:01 +0000 Subject: [PATCH] Normalize param_env for trait assoc consts in typeck --- compiler/rustc_trait_selection/src/traits/mod.rs | 2 +- compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 40596078f041..92fee9f35277 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -130,7 +130,7 @@ pub fn predicates_for_generics<'tcx>( move |(idx, (predicate, span))| Obligation { cause: cause(idx, span), recursion_depth: 0, - param_env: param_env, + param_env, predicate, }, ) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index a40478db9690..a7b4d08cbf3e 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -1418,13 +1418,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { substs: SubstsRef<'tcx>, code: impl Fn(usize, Span) -> ObligationCauseCode<'tcx>, ) { + // Associated consts have `Self: ~const Trait` bounds that should be satisfiable when + // `Self: Trait` is satisfied because it does not matter whether the impl is `const`. + // Therefore we have to remap the param env here to be non-const. + let param_env = if let hir::def::DefKind::AssocConst = self.tcx.def_kind(def_id) { + self.param_env.without_const() + } else { + self.param_env + }; let (bounds, _) = self.instantiate_bounds(span, def_id, &substs); for obligation in traits::predicates_for_generics( |idx, predicate_span| { traits::ObligationCause::new(span, self.body_id, code(idx, predicate_span)) }, - self.param_env, + param_env, bounds, ) { self.register_predicate(obligation);