Skip to content

Commit 5ead742

Browse files
committed
remap ParamEnv with obligation
1 parent 08aeb1a commit 5ead742

File tree

4 files changed

+24
-8
lines changed
  • compiler

4 files changed

+24
-8
lines changed

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
436436
locations,
437437
);
438438
self.cx.param_env = prev;
439-
440439
}
441440
}
442441
}

Diff for: compiler/rustc_infer/src/traits/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ impl<'tcx> PredicateObligation<'tcx> {
6767
recursion_depth: self.recursion_depth,
6868
})
6969
}
70+
71+
pub fn without_const(mut self, tcx: TyCtxt<'tcx>) -> PredicateObligation<'tcx> {
72+
self.param_env = self.param_env.without_const();
73+
if let ty::PredicateKind::Trait(trait_pred) = self.predicate.kind().skip_binder() && trait_pred.is_const_if_const() {
74+
self.predicate = tcx.mk_predicate(self.predicate.kind().map_bound(|_| ty::PredicateKind::Trait(trait_pred.without_const())));
75+
}
76+
self
77+
}
7078
}
7179

7280
impl<'tcx> TraitObligation<'tcx> {

Diff for: compiler/rustc_middle/src/ty/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,11 @@ impl<'tcx> TraitPredicate<'tcx> {
861861
(BoundConstness::ConstIfConst, hir::Constness::NotConst) => false,
862862
}
863863
}
864+
865+
pub fn without_const(mut self) -> Self {
866+
self.constness = BoundConstness::NotConst;
867+
self
868+
}
864869
}
865870

866871
impl<'tcx> PolyTraitPredicate<'tcx> {

Diff for: compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)