Stop using PolyTraitRef for closure/coroutine predicates already instantiated w placeholders
This commit is contained in:
parent
3a0db6c152
commit
d2ec957680
@ -367,7 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}),
|
}),
|
||||||
) = error.code
|
) = error.code
|
||||||
&& let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) =
|
&& let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) =
|
||||||
expected_trait_ref.skip_binder().self_ty().kind()
|
expected_trait_ref.self_ty().kind()
|
||||||
&& span.overlaps(self.tcx.def_span(*def_id))
|
&& span.overlaps(self.tcx.def_span(*def_id))
|
||||||
{
|
{
|
||||||
true
|
true
|
||||||
|
@ -620,11 +620,10 @@ pub enum SelectionError<'tcx> {
|
|||||||
OpaqueTypeAutoTraitLeakageUnknown(DefId),
|
OpaqueTypeAutoTraitLeakageUnknown(DefId),
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(@lcnr): The `Binder` here should be unnecessary. Just use `TraitRef` instead.
|
|
||||||
#[derive(Clone, Debug, TypeVisitable)]
|
#[derive(Clone, Debug, TypeVisitable)]
|
||||||
pub struct SignatureMismatchData<'tcx> {
|
pub struct SignatureMismatchData<'tcx> {
|
||||||
pub found_trait_ref: ty::PolyTraitRef<'tcx>,
|
pub found_trait_ref: ty::TraitRef<'tcx>,
|
||||||
pub expected_trait_ref: ty::PolyTraitRef<'tcx>,
|
pub expected_trait_ref: ty::TraitRef<'tcx>,
|
||||||
pub terr: ty::error::TypeError<'tcx>,
|
pub terr: ty::error::TypeError<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1879,19 +1879,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
found_span: Option<Span>,
|
found_span: Option<Span>,
|
||||||
found: ty::PolyTraitRef<'tcx>,
|
found: ty::TraitRef<'tcx>,
|
||||||
expected: ty::PolyTraitRef<'tcx>,
|
expected: ty::TraitRef<'tcx>,
|
||||||
cause: &ObligationCauseCode<'tcx>,
|
cause: &ObligationCauseCode<'tcx>,
|
||||||
found_node: Option<Node<'_>>,
|
found_node: Option<Node<'_>>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
) -> Diag<'tcx> {
|
) -> Diag<'tcx> {
|
||||||
pub(crate) fn build_fn_sig_ty<'tcx>(
|
pub(crate) fn build_fn_sig_ty<'tcx>(
|
||||||
infcx: &InferCtxt<'tcx>,
|
infcx: &InferCtxt<'tcx>,
|
||||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
trait_ref: ty::TraitRef<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let inputs = trait_ref.skip_binder().args.type_at(1);
|
let inputs = trait_ref.args.type_at(1);
|
||||||
let sig = match inputs.kind() {
|
let sig = match inputs.kind() {
|
||||||
ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id()) => {
|
ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id) => {
|
||||||
infcx.tcx.mk_fn_sig(
|
infcx.tcx.mk_fn_sig(
|
||||||
*inputs,
|
*inputs,
|
||||||
infcx.next_ty_var(TypeVariableOrigin {
|
infcx.next_ty_var(TypeVariableOrigin {
|
||||||
@ -1915,10 +1915,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ty::new_fn_ptr(infcx.tcx, trait_ref.rebind(sig))
|
Ty::new_fn_ptr(infcx.tcx, ty::Binder::dummy(sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
let argument_kind = match expected.skip_binder().self_ty().kind() {
|
let argument_kind = match expected.self_ty().kind() {
|
||||||
ty::Closure(..) => "closure",
|
ty::Closure(..) => "closure",
|
||||||
ty::Coroutine(..) => "coroutine",
|
ty::Coroutine(..) => "coroutine",
|
||||||
_ => "function",
|
_ => "function",
|
||||||
|
@ -3380,11 +3380,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
fn report_cyclic_signature_error(
|
fn report_cyclic_signature_error(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
found_trait_ref: ty::TraitRef<'tcx>,
|
||||||
expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
expected_trait_ref: ty::TraitRef<'tcx>,
|
||||||
terr: TypeError<'tcx>,
|
terr: TypeError<'tcx>,
|
||||||
) -> Diag<'tcx> {
|
) -> Diag<'tcx> {
|
||||||
let self_ty = found_trait_ref.self_ty().skip_binder();
|
let self_ty = found_trait_ref.self_ty();
|
||||||
let (cause, terr) = if let ty::Closure(def_id, _) = self_ty.kind() {
|
let (cause, terr) = if let ty::Closure(def_id, _) = self_ty.kind() {
|
||||||
(
|
(
|
||||||
ObligationCause::dummy_with_span(self.tcx.def_span(def_id)),
|
ObligationCause::dummy_with_span(self.tcx.def_span(def_id)),
|
||||||
@ -3394,7 +3394,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
(obligation.cause.clone(), terr)
|
(obligation.cause.clone(), terr)
|
||||||
};
|
};
|
||||||
self.report_and_explain_type_error(
|
self.report_and_explain_type_error(
|
||||||
TypeTrace::poly_trait_refs(&cause, true, expected_trait_ref, found_trait_ref),
|
TypeTrace::poly_trait_refs(
|
||||||
|
&cause,
|
||||||
|
true,
|
||||||
|
ty::Binder::dummy(expected_trait_ref),
|
||||||
|
ty::Binder::dummy(found_trait_ref),
|
||||||
|
),
|
||||||
terr,
|
terr,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -3434,17 +3439,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
found_trait_ref: ty::TraitRef<'tcx>,
|
||||||
expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
expected_trait_ref: ty::TraitRef<'tcx>,
|
||||||
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
|
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
|
||||||
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
|
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
|
||||||
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
|
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
|
||||||
|
|
||||||
expected_trait_ref.self_ty().error_reported()?;
|
expected_trait_ref.self_ty().error_reported()?;
|
||||||
|
let found_trait_ty = found_trait_ref.self_ty();
|
||||||
let Some(found_trait_ty) = found_trait_ref.self_ty().no_bound_vars() else {
|
|
||||||
self.dcx().bug("bound vars outside binder");
|
|
||||||
};
|
|
||||||
|
|
||||||
let found_did = match *found_trait_ty.kind() {
|
let found_did = match *found_trait_ty.kind() {
|
||||||
ty::Closure(did, _) | ty::FnDef(did, _) | ty::Coroutine(did, ..) => Some(did),
|
ty::Closure(did, _) | ty::FnDef(did, _) | ty::Coroutine(did, ..) => Some(did),
|
||||||
@ -3462,7 +3464,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
|
|
||||||
let mut not_tupled = false;
|
let mut not_tupled = false;
|
||||||
|
|
||||||
let found = match found_trait_ref.skip_binder().args.type_at(1).kind() {
|
let found = match found_trait_ref.args.type_at(1).kind() {
|
||||||
ty::Tuple(tys) => vec![ArgKind::empty(); tys.len()],
|
ty::Tuple(tys) => vec![ArgKind::empty(); tys.len()],
|
||||||
_ => {
|
_ => {
|
||||||
not_tupled = true;
|
not_tupled = true;
|
||||||
@ -3470,7 +3472,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let expected_ty = expected_trait_ref.skip_binder().args.type_at(1);
|
let expected_ty = expected_trait_ref.args.type_at(1);
|
||||||
let expected = match expected_ty.kind() {
|
let expected = match expected_ty.kind() {
|
||||||
ty::Tuple(tys) => {
|
ty::Tuple(tys) => {
|
||||||
tys.iter().map(|t| ArgKind::from_expected_ty(t, Some(span))).collect()
|
tys.iter().map(|t| ArgKind::from_expected_ty(t, Some(span))).collect()
|
||||||
@ -3487,15 +3489,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
// traits manually, but don't make it more confusing when it does
|
// traits manually, but don't make it more confusing when it does
|
||||||
// happen.
|
// happen.
|
||||||
Ok(
|
Ok(
|
||||||
if Some(expected_trait_ref.def_id()) != self.tcx.lang_items().coroutine_trait()
|
if Some(expected_trait_ref.def_id) != self.tcx.lang_items().coroutine_trait()
|
||||||
&& not_tupled
|
&& not_tupled
|
||||||
{
|
{
|
||||||
self.report_and_explain_type_error(
|
self.report_and_explain_type_error(
|
||||||
TypeTrace::poly_trait_refs(
|
TypeTrace::poly_trait_refs(
|
||||||
&obligation.cause,
|
&obligation.cause,
|
||||||
true,
|
true,
|
||||||
expected_trait_ref,
|
ty::Binder::dummy(expected_trait_ref),
|
||||||
found_trait_ref,
|
ty::Binder::dummy(found_trait_ref),
|
||||||
),
|
),
|
||||||
ty::error::TypeError::Mismatch,
|
ty::error::TypeError::Mismatch,
|
||||||
)
|
)
|
||||||
|
@ -1079,8 +1079,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
})
|
})
|
||||||
.map_err(|terr| {
|
.map_err(|terr| {
|
||||||
SignatureMismatch(Box::new(SignatureMismatchData {
|
SignatureMismatch(Box::new(SignatureMismatchData {
|
||||||
expected_trait_ref: ty::Binder::dummy(obligation_trait_ref),
|
expected_trait_ref: obligation_trait_ref,
|
||||||
found_trait_ref: ty::Binder::dummy(found_trait_ref),
|
found_trait_ref,
|
||||||
terr,
|
terr,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user