1
Fork 0

Auto merge of #118379 - compiler-errors:const-params-for-partialeq, r=fee1-dead

Fix `PartialEq` args when `#[const_trait]` is enabled

This is based off of your PR that enforces effects on all methods, so just see the last commits.

r? fee1-dead
This commit is contained in:
bors 2023-11-30 05:24:53 +00:00
commit e55544c804
8 changed files with 85 additions and 91 deletions

View file

@ -496,7 +496,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, Some(source_info.span));
let method = trait_method(self.tcx, eq_def_id, sym::eq, [ty, ty]);
let method = trait_method(
self.tcx,
eq_def_id,
sym::eq,
self.tcx.with_opt_const_effect_param(self.def_id, eq_def_id, [ty, ty]),
);
let bool_ty = self.tcx.types.bool;
let eq_result = self.temp(bool_ty, source_info.span);

View file

@ -258,18 +258,26 @@ impl<'tcx> ConstToPat<'tcx> {
#[instrument(level = "trace", skip(self), ret)]
fn type_has_partial_eq_impl(&self, ty: Ty<'tcx>) -> bool {
let tcx = self.tcx();
// double-check there even *is* a semantic `PartialEq` to dispatch to.
//
// (If there isn't, then we can safely issue a hard
// error, because that's never worked, due to compiler
// using `PartialEq::eq` in this scenario in the past.)
let tcx = self.tcx();
let partial_eq_trait_id = tcx.require_lang_item(hir::LangItem::PartialEq, Some(self.span));
let partial_eq_obligation = Obligation::new(
tcx,
ObligationCause::dummy(),
self.param_env,
ty::TraitRef::new(tcx, partial_eq_trait_id, [ty, ty]),
ty::TraitRef::new(
tcx,
partial_eq_trait_id,
tcx.with_opt_const_effect_param(
tcx.hir().enclosing_body_owner(self.id),
partial_eq_trait_id,
[ty, ty],
),
),
);
// This *could* accept a type that isn't actually `PartialEq`, because region bounds get