Use real inference variable in build_fn_sig_ty
This commit is contained in:
parent
c655d4b233
commit
e69cad449a
@ -20,6 +20,7 @@ use rustc_hir::def_id::DefId;
|
|||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
|
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
|
||||||
|
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use rustc_middle::hir::map;
|
use rustc_middle::hir::map;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
|
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
|
||||||
@ -1584,32 +1585,38 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
expected: ty::PolyTraitRef<'tcx>,
|
expected: ty::PolyTraitRef<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||||
pub(crate) fn build_fn_sig_ty<'tcx>(
|
pub(crate) fn build_fn_sig_ty<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
infcx: &InferCtxt<'_, 'tcx>,
|
||||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let inputs = trait_ref.skip_binder().substs.type_at(1);
|
let inputs = trait_ref.skip_binder().substs.type_at(1);
|
||||||
let sig = match inputs.kind() {
|
let sig = match inputs.kind() {
|
||||||
ty::Tuple(inputs)
|
ty::Tuple(inputs)
|
||||||
if tcx.fn_trait_kind_from_lang_item(trait_ref.def_id()).is_some() =>
|
if infcx.tcx.fn_trait_kind_from_lang_item(trait_ref.def_id()).is_some() =>
|
||||||
{
|
{
|
||||||
tcx.mk_fn_sig(
|
infcx.tcx.mk_fn_sig(
|
||||||
inputs.iter(),
|
inputs.iter(),
|
||||||
tcx.mk_ty_infer(ty::TyVar(ty::TyVid::from_u32(0))),
|
infcx.next_ty_var(TypeVariableOrigin {
|
||||||
|
span: DUMMY_SP,
|
||||||
|
kind: TypeVariableOriginKind::MiscVariable,
|
||||||
|
}),
|
||||||
false,
|
false,
|
||||||
hir::Unsafety::Normal,
|
hir::Unsafety::Normal,
|
||||||
abi::Abi::Rust,
|
abi::Abi::Rust,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => tcx.mk_fn_sig(
|
_ => infcx.tcx.mk_fn_sig(
|
||||||
std::iter::once(inputs),
|
std::iter::once(inputs),
|
||||||
tcx.mk_ty_infer(ty::TyVar(ty::TyVid::from_u32(0))),
|
infcx.next_ty_var(TypeVariableOrigin {
|
||||||
|
span: DUMMY_SP,
|
||||||
|
kind: TypeVariableOriginKind::MiscVariable,
|
||||||
|
}),
|
||||||
false,
|
false,
|
||||||
hir::Unsafety::Normal,
|
hir::Unsafety::Normal,
|
||||||
abi::Abi::Rust,
|
abi::Abi::Rust,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
tcx.mk_fn_ptr(trait_ref.rebind(sig))
|
infcx.tcx.mk_fn_ptr(trait_ref.rebind(sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
let argument_kind = match expected.skip_binder().self_ty().kind() {
|
let argument_kind = match expected.skip_binder().self_ty().kind() {
|
||||||
@ -1629,8 +1636,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
let found_span = found_span.unwrap_or(span);
|
let found_span = found_span.unwrap_or(span);
|
||||||
err.span_label(found_span, "found signature defined here");
|
err.span_label(found_span, "found signature defined here");
|
||||||
|
|
||||||
let expected = build_fn_sig_ty(self.tcx, expected);
|
let expected = build_fn_sig_ty(self, expected);
|
||||||
let found = build_fn_sig_ty(self.tcx, found);
|
let found = build_fn_sig_ty(self, found);
|
||||||
|
|
||||||
let (expected_str, found_str) = self.cmp(expected, found);
|
let (expected_str, found_str) = self.cmp(expected, found);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user