1
Fork 0

Add with_opt_const_effect_param helper, simplify

This commit is contained in:
Michael Goulet 2023-11-28 21:17:55 +00:00
parent 89c2c85fe1
commit d3404d2b98
7 changed files with 37 additions and 30 deletions

View file

@ -494,14 +494,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, Some(source_info.span));
let mut args: Vec<ty::GenericArg<'tcx>> = vec![ty.into(), ty.into()];
// If `PartialEq` is `#[const_trait]`, then add a const effect param
if self.tcx.generics_of(eq_def_id).host_effect_index.is_some() {
args.push(self.tcx.expected_const_effect_param_for_body(self.def_id).into());
}
let method = trait_method(self.tcx, eq_def_id, sym::eq, args);
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

@ -265,20 +265,19 @@ impl<'tcx> ConstToPat<'tcx> {
// error, because that's never worked, due to compiler
// using `PartialEq::eq` in this scenario in the past.)
let partial_eq_trait_id = tcx.require_lang_item(hir::LangItem::PartialEq, Some(self.span));
let mut args: Vec<ty::GenericArg<'tcx>> = vec![ty.into(), ty.into()];
// If `PartialEq` is `#[const_trait]`, then add a const effect param
if tcx.generics_of(partial_eq_trait_id).host_effect_index.is_some() {
args.push(
tcx.expected_const_effect_param_for_body(tcx.hir().enclosing_body_owner(self.id))
.into(),
);
}
let partial_eq_obligation = Obligation::new(
tcx,
ObligationCause::dummy(),
self.param_env,
ty::TraitRef::new(tcx, partial_eq_trait_id, args),
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