@@ -1418,12 +1418,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14181418 substs : SubstsRef < ' tcx > ,
14191419 code : impl Fn ( usize , Span ) -> ObligationCauseCode < ' tcx > ,
14201420 ) {
1421- let mut param_env = self . param_env ;
1422- match self . tcx . def_kind ( def_id) {
1421+ let param_env = self . param_env ;
1422+
1423+ let remap = match self . tcx . def_kind ( def_id) {
14231424 // Associated consts have `Self: ~const Trait` bounds that should be satisfiable when
14241425 // `Self: Trait` is satisfied because it does not matter whether the impl is `const`.
14251426 // Therefore we have to remap the param env here to be non-const.
1426- hir:: def:: DefKind :: AssocConst => param_env = param_env . without_const ( ) ,
1427+ hir:: def:: DefKind :: AssocConst => true ,
14271428 hir:: def:: DefKind :: AssocFn
14281429 if self . tcx . def_kind ( self . tcx . parent ( def_id) ) == hir:: def:: DefKind :: Trait =>
14291430 {
@@ -1437,19 +1438,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14371438 //
14381439 // FIXME(fee1-dead) FIXME(const_trait_impl): update this doc when trait methods can satisfy
14391440 // `~const FnOnce` or can be coerced to `const fn` pointer.
1440- param_env = param_env . without_const ( ) ;
1441+ true
14411442 }
1442- _ => { }
1443- }
1443+ _ => false ,
1444+ } ;
14441445 let ( bounds, _) = self . instantiate_bounds ( span, def_id, & substs) ;
14451446
1446- for obligation in traits:: predicates_for_generics (
1447+ for mut obligation in traits:: predicates_for_generics (
14471448 |idx, predicate_span| {
14481449 traits:: ObligationCause :: new ( span, self . body_id , code ( idx, predicate_span) )
14491450 } ,
14501451 param_env,
14511452 bounds,
14521453 ) {
1454+ if remap {
1455+ obligation = obligation. without_const ( self . tcx ) ;
1456+ }
14531457 self . register_predicate ( obligation) ;
14541458 }
14551459 }
0 commit comments