Add with_opt_const_effect_param helper, simplify
This commit is contained in:
parent
89c2c85fe1
commit
d3404d2b98
7 changed files with 37 additions and 30 deletions
|
@ -8,7 +8,6 @@ use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, StashKey};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{self, CtorKind, Namespace, Res};
|
use rustc_hir::def::{self, CtorKind, Namespace, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::HirId;
|
|
||||||
use rustc_hir_analysis::autoderef::Autoderef;
|
use rustc_hir_analysis::autoderef::Autoderef;
|
||||||
use rustc_infer::{
|
use rustc_infer::{
|
||||||
infer,
|
infer,
|
||||||
|
@ -373,7 +372,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let (fn_sig, def_id) = match *callee_ty.kind() {
|
let (fn_sig, def_id) = match *callee_ty.kind() {
|
||||||
ty::FnDef(def_id, args) => {
|
ty::FnDef(def_id, args) => {
|
||||||
self.enforce_context_effects(call_expr.hir_id, call_expr.span, def_id, args);
|
self.enforce_context_effects(call_expr.span, def_id, args);
|
||||||
let fn_sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, args);
|
let fn_sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, args);
|
||||||
|
|
||||||
// Unit testing: function items annotated with
|
// Unit testing: function items annotated with
|
||||||
|
@ -770,7 +769,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
#[tracing::instrument(level = "debug", skip(self, span))]
|
#[tracing::instrument(level = "debug", skip(self, span))]
|
||||||
pub(super) fn enforce_context_effects(
|
pub(super) fn enforce_context_effects(
|
||||||
&self,
|
&self,
|
||||||
call_expr_hir: HirId,
|
|
||||||
span: Span,
|
span: Span,
|
||||||
callee_did: DefId,
|
callee_did: DefId,
|
||||||
callee_args: GenericArgsRef<'tcx>,
|
callee_args: GenericArgsRef<'tcx>,
|
||||||
|
|
|
@ -165,7 +165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
method: MethodCallee<'tcx>,
|
method: MethodCallee<'tcx>,
|
||||||
) {
|
) {
|
||||||
self.enforce_context_effects(hir_id, span, method.def_id, method.args);
|
self.enforce_context_effects(span, method.def_id, method.args);
|
||||||
self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id)));
|
self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id)));
|
||||||
self.write_args(hir_id, method.args);
|
self.write_args(hir_id, method.args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,12 +282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
span: provided_arg.span,
|
span: provided_arg.span,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
self.enforce_context_effects(
|
self.enforce_context_effects(provided_arg.span, def_id, args)
|
||||||
provided_arg.hir_id,
|
|
||||||
provided_arg.span,
|
|
||||||
def_id,
|
|
||||||
args,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -813,6 +813,23 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
None => self.consts.true_,
|
None => self.consts.true_,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Constructs generic args for an item, optionally appending a const effect param type
|
||||||
|
pub fn with_opt_const_effect_param(
|
||||||
|
self,
|
||||||
|
caller_def_id: LocalDefId,
|
||||||
|
callee_def_id: DefId,
|
||||||
|
args: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
|
||||||
|
) -> ty::GenericArgsRef<'tcx> {
|
||||||
|
let generics = self.generics_of(callee_def_id);
|
||||||
|
assert_eq!(generics.parent, None);
|
||||||
|
|
||||||
|
let opt_const_param = generics.host_effect_index.is_some().then(|| {
|
||||||
|
ty::GenericArg::from(self.expected_const_effect_param_for_body(caller_def_id))
|
||||||
|
});
|
||||||
|
|
||||||
|
self.mk_args_from_iter(args.into_iter().map(|arg| arg.into()).chain(opt_const_param))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OpaqueTypeExpander<'tcx> {
|
struct OpaqueTypeExpander<'tcx> {
|
||||||
|
|
|
@ -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 eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, Some(source_info.span));
|
||||||
|
let method = trait_method(
|
||||||
let mut args: Vec<ty::GenericArg<'tcx>> = vec![ty.into(), ty.into()];
|
self.tcx,
|
||||||
// If `PartialEq` is `#[const_trait]`, then add a const effect param
|
eq_def_id,
|
||||||
if self.tcx.generics_of(eq_def_id).host_effect_index.is_some() {
|
sym::eq,
|
||||||
args.push(self.tcx.expected_const_effect_param_for_body(self.def_id).into());
|
self.tcx.with_opt_const_effect_param(self.def_id, eq_def_id, [ty, ty]),
|
||||||
}
|
);
|
||||||
|
|
||||||
let method = trait_method(self.tcx, eq_def_id, sym::eq, args);
|
|
||||||
|
|
||||||
let bool_ty = self.tcx.types.bool;
|
let bool_ty = self.tcx.types.bool;
|
||||||
let eq_result = self.temp(bool_ty, source_info.span);
|
let eq_result = self.temp(bool_ty, source_info.span);
|
||||||
|
|
|
@ -265,20 +265,19 @@ impl<'tcx> ConstToPat<'tcx> {
|
||||||
// error, because that's never worked, due to compiler
|
// error, because that's never worked, due to compiler
|
||||||
// using `PartialEq::eq` in this scenario in the past.)
|
// 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 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(
|
let partial_eq_obligation = Obligation::new(
|
||||||
tcx,
|
tcx,
|
||||||
ObligationCause::dummy(),
|
ObligationCause::dummy(),
|
||||||
self.param_env,
|
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
|
// This *could* accept a type that isn't actually `PartialEq`, because region bounds get
|
||||||
|
|
|
@ -344,9 +344,9 @@ trait PartialEq<Rhs: ?Sized = Self> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ?Sized, B: ?Sized> PartialEq<&B> for &A
|
impl<A: ?Sized, B: ?Sized> const PartialEq<&B> for &A
|
||||||
where
|
where
|
||||||
A: PartialEq<B>,
|
A: ~const PartialEq<B>,
|
||||||
{
|
{
|
||||||
fn eq(&self, other: &&B) -> bool {
|
fn eq(&self, other: &&B) -> bool {
|
||||||
PartialEq::eq(*self, *other)
|
PartialEq::eq(*self, *other)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue