From 08aeb1aa9b8baff7025fa4ae9958ce2ca0876c40 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 15 Sep 2022 15:48:35 +0000 Subject: [PATCH] unconditionally remap to nonconst in borrowck --- compiler/rustc_borrowck/src/type_check/mod.rs | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 79e7eb0f1cc2..9aea99b6a124 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -424,31 +424,19 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } if let ty::FnDef(def_id, substs) = *constant.literal.ty().kind() { - // N.B.: When instantiating a trait method as a function item, it does not actually matter - // whether the trait is `const` or not, or whether `where T: ~const Tr` needs to be satisfied - // as `const`. If we were to introduce instantiating trait methods as `const fn`s, we would - // check that after this, either via a bound `where F: ~const FnOnce` or when coercing to a - // `const fn` pointer. - // - // FIXME(fee1-dead) FIXME(const_trait_impl): update this doc when trait methods can satisfy - // `~const FnOnce` or can be coerced to `const fn` pointer. - let const_norm = self.tcx().def_kind(def_id) == hir::def::DefKind::AssocFn - && self.tcx().def_kind(ty::DefIdTree::parent(self.tcx(), def_id)) - == hir::def::DefKind::Trait; - + // const_trait_impl: use a non-const param env when checking that a FnDef type is well formed. + // this is because the well-formedness of the function does not need to be proved to have `const` + // impls for trait bounds. let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs); let prev = self.cx.param_env; - if const_norm { - self.cx.param_env = prev.without_const(); - } + self.cx.param_env = prev.without_const(); self.cx.normalize_and_prove_instantiated_predicates( def_id, instantiated_predicates, locations, ); - if const_norm { - self.cx.param_env = prev; - } + self.cx.param_env = prev; + } } }