Fix PartialEq args when #[const_trait] is enabled
This commit is contained in:
parent
5facb422f8
commit
82a9e872d8
5 changed files with 56 additions and 37 deletions
|
@ -494,7 +494,14 @@ 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 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 bool_ty = self.tcx.types.bool;
|
||||
let eq_result = self.temp(bool_ty, source_info.span);
|
||||
|
|
|
@ -258,18 +258,27 @@ 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 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, [ty, ty]),
|
||||
ty::TraitRef::new(tcx, partial_eq_trait_id, args),
|
||||
);
|
||||
|
||||
// This *could* accept a type that isn't actually `PartialEq`, because region bounds get
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue