diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2022-08-28 06:27:01 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2022-09-16 11:48:43 +0800 |
| commit | 77b0c47b8284bbb24dab9a5ff95b93f083ce7c54 (patch) | |
| tree | e77e5b877b923e9d5a34c59c5d5075c26f246243 | |
| parent | 07608bd60ecfa75a72c13372c1545665ab147f2c (diff) | |
| download | rust-77b0c47b8284bbb24dab9a5ff95b93f083ce7c54.tar.gz rust-77b0c47b8284bbb24dab9a5ff95b93f083ce7c54.zip | |
Normalize param_env for trait assoc consts in typeck
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/mod.rs | 2 | ||||
| -rw-r--r-- | 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 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); |
