From 42316617898cacd52489121e9abebeff247e0840 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 28 Aug 2022 04:02:43 +0000 Subject: Do not require const predicates to hold when checking if a projection type is wf --- compiler/rustc_trait_selection/src/traits/wf.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_trait_selection/src') diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index f95e217da30..a86234291ca 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -392,7 +392,8 @@ impl<'tcx> WfPredicates<'tcx> { // `i32: Clone` // `i32: Copy` // ] - let obligations = self.nominal_obligations(data.item_def_id, data.substs); + // Projection types do not require const predicates. + let obligations = self.nominal_obligations_without_const(data.item_def_id, data.substs); self.out.extend(obligations); let tcx = self.tcx(); -- cgit 1.4.1-3-g733a5 From 77b0c47b8284bbb24dab9a5ff95b93f083ce7c54 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 28 Aug 2022 06:27:01 +0000 Subject: 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(-) (limited to 'compiler/rustc_trait_selection/src') diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 40596078f04..92fee9f3527 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 a40478db969..a7b4d08cbf3 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); -- cgit 1.4.1-3-g733a5