PolyTraitRefs -> TraitRefs
This commit is contained in:
parent
d2ec957680
commit
9e630d3f21
6 changed files with 20 additions and 43 deletions
|
@ -424,25 +424,7 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
|
||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
TypeTrace {
|
TypeTrace {
|
||||||
cause: cause.clone(),
|
cause: cause.clone(),
|
||||||
values: PolyTraitRefs(ExpectedFound::new(
|
values: TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
|
||||||
a_is_expected,
|
|
||||||
ty::Binder::dummy(a),
|
|
||||||
ty::Binder::dummy(b),
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
|
|
||||||
fn to_trace(
|
|
||||||
cause: &ObligationCause<'tcx>,
|
|
||||||
a_is_expected: bool,
|
|
||||||
a: Self,
|
|
||||||
b: Self,
|
|
||||||
) -> TypeTrace<'tcx> {
|
|
||||||
TypeTrace {
|
|
||||||
cause: cause.clone(),
|
|
||||||
values: PolyTraitRefs(ExpectedFound::new(a_is_expected, a, b)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1653,7 +1653,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
.report(diag);
|
.report(diag);
|
||||||
(false, Mismatch::Fixed("signature"))
|
(false, Mismatch::Fixed("signature"))
|
||||||
}
|
}
|
||||||
ValuePairs::PolyTraitRefs(_) => (false, Mismatch::Fixed("trait")),
|
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
|
||||||
ValuePairs::Aliases(infer::ExpectedFound { expected, .. }) => {
|
ValuePairs::Aliases(infer::ExpectedFound { expected, .. }) => {
|
||||||
(false, Mismatch::Fixed(self.tcx.def_descr(expected.def_id)))
|
(false, Mismatch::Fixed(self.tcx.def_descr(expected.def_id)))
|
||||||
}
|
}
|
||||||
|
@ -1969,8 +1969,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
self.note_and_explain_type_err(diag, exp_found, cause, span, cause.body_id.to_def_id());
|
self.note_and_explain_type_err(diag, exp_found, cause, span, cause.body_id.to_def_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ValuePairs::PolyTraitRefs(exp_found)) = values
|
if let Some(ValuePairs::TraitRefs(exp_found)) = values
|
||||||
&& let ty::Closure(def_id, _) = exp_found.expected.skip_binder().self_ty().kind()
|
&& let ty::Closure(def_id, _) = exp_found.expected.self_ty().kind()
|
||||||
&& let Some(def_id) = def_id.as_local()
|
&& let Some(def_id) = def_id.as_local()
|
||||||
&& terr.involves_regions()
|
&& terr.involves_regions()
|
||||||
{
|
{
|
||||||
|
@ -2188,7 +2188,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
infer::Aliases(exp_found) => self.expected_found_str(exp_found),
|
infer::Aliases(exp_found) => self.expected_found_str(exp_found),
|
||||||
infer::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
|
infer::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
|
||||||
infer::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
|
infer::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
|
||||||
infer::PolyTraitRefs(exp_found) => {
|
infer::TraitRefs(exp_found) => {
|
||||||
let pretty_exp_found = ty::error::ExpectedFound {
|
let pretty_exp_found = ty::error::ExpectedFound {
|
||||||
expected: exp_found.expected.print_trait_sugared(),
|
expected: exp_found.expected.print_trait_sugared(),
|
||||||
found: exp_found.found.print_trait_sugared(),
|
found: exp_found.found.print_trait_sugared(),
|
||||||
|
|
|
@ -195,13 +195,13 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
value_pairs: &ValuePairs<'tcx>,
|
value_pairs: &ValuePairs<'tcx>,
|
||||||
) -> Option<Diag<'tcx>> {
|
) -> Option<Diag<'tcx>> {
|
||||||
let (expected_args, found_args, trait_def_id) = match value_pairs {
|
let (expected_args, found_args, trait_def_id) = match value_pairs {
|
||||||
ValuePairs::PolyTraitRefs(ExpectedFound { expected, found })
|
ValuePairs::TraitRefs(ExpectedFound { expected, found })
|
||||||
if expected.def_id() == found.def_id() =>
|
if expected.def_id == found.def_id =>
|
||||||
{
|
{
|
||||||
// It's possible that the placeholders come from a binder
|
// It's possible that the placeholders come from a binder
|
||||||
// outside of this value pair. Use `no_bound_vars` as a
|
// outside of this value pair. Use `no_bound_vars` as a
|
||||||
// simple heuristic for that.
|
// simple heuristic for that.
|
||||||
(expected.no_bound_vars()?.args, found.no_bound_vars()?.args, expected.def_id())
|
(expected.args, found.args, expected.def_id)
|
||||||
}
|
}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
|
@ -599,7 +599,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
hir: hir::Node<'_>,
|
hir: hir::Node<'_>,
|
||||||
exp_found: &ty::error::ExpectedFound<ty::PolyTraitRef<'tcx>>,
|
exp_found: &ty::error::ExpectedFound<ty::TraitRef<'tcx>>,
|
||||||
diag: &mut Diag<'_>,
|
diag: &mut Diag<'_>,
|
||||||
) {
|
) {
|
||||||
// 0. Extract fn_decl from hir
|
// 0. Extract fn_decl from hir
|
||||||
|
@ -614,10 +614,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
|
|
||||||
// 1. Get the args of the closure.
|
// 1. Get the args of the closure.
|
||||||
// 2. Assume exp_found is FnOnce / FnMut / Fn, we can extract function parameters from [1].
|
// 2. Assume exp_found is FnOnce / FnMut / Fn, we can extract function parameters from [1].
|
||||||
let Some(expected) = exp_found.expected.skip_binder().args.get(1) else {
|
let Some(expected) = exp_found.expected.args.get(1) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let Some(found) = exp_found.found.skip_binder().args.get(1) else {
|
let Some(found) = exp_found.found.args.get(1) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let expected = expected.unpack();
|
let expected = expected.unpack();
|
||||||
|
|
|
@ -403,7 +403,7 @@ pub enum ValuePairs<'tcx> {
|
||||||
Regions(ExpectedFound<ty::Region<'tcx>>),
|
Regions(ExpectedFound<ty::Region<'tcx>>),
|
||||||
Terms(ExpectedFound<ty::Term<'tcx>>),
|
Terms(ExpectedFound<ty::Term<'tcx>>),
|
||||||
Aliases(ExpectedFound<ty::AliasTy<'tcx>>),
|
Aliases(ExpectedFound<ty::AliasTy<'tcx>>),
|
||||||
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
|
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
|
||||||
PolySigs(ExpectedFound<ty::PolyFnSig<'tcx>>),
|
PolySigs(ExpectedFound<ty::PolyFnSig<'tcx>>),
|
||||||
ExistentialTraitRef(ExpectedFound<ty::PolyExistentialTraitRef<'tcx>>),
|
ExistentialTraitRef(ExpectedFound<ty::PolyExistentialTraitRef<'tcx>>),
|
||||||
ExistentialProjection(ExpectedFound<ty::PolyExistentialProjection<'tcx>>),
|
ExistentialProjection(ExpectedFound<ty::PolyExistentialProjection<'tcx>>),
|
||||||
|
@ -1882,15 +1882,15 @@ impl<'tcx> TypeTrace<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn poly_trait_refs(
|
pub fn trait_refs(
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: ty::PolyTraitRef<'tcx>,
|
a: ty::TraitRef<'tcx>,
|
||||||
b: ty::PolyTraitRef<'tcx>,
|
b: ty::TraitRef<'tcx>,
|
||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
TypeTrace {
|
TypeTrace {
|
||||||
cause: cause.clone(),
|
cause: cause.clone(),
|
||||||
values: PolyTraitRefs(ExpectedFound::new(a_is_expected, a, b)),
|
values: TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3394,12 +3394,7 @@ 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(
|
TypeTrace::trait_refs(&cause, true, expected_trait_ref, found_trait_ref),
|
||||||
&cause,
|
|
||||||
true,
|
|
||||||
ty::Binder::dummy(expected_trait_ref),
|
|
||||||
ty::Binder::dummy(found_trait_ref),
|
|
||||||
),
|
|
||||||
terr,
|
terr,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -3493,11 +3488,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
&& not_tupled
|
&& not_tupled
|
||||||
{
|
{
|
||||||
self.report_and_explain_type_error(
|
self.report_and_explain_type_error(
|
||||||
TypeTrace::poly_trait_refs(
|
TypeTrace::trait_refs(
|
||||||
&obligation.cause,
|
&obligation.cause,
|
||||||
true,
|
true,
|
||||||
ty::Binder::dummy(expected_trait_ref),
|
expected_trait_ref,
|
||||||
ty::Binder::dummy(found_trait_ref),
|
found_trait_ref,
|
||||||
),
|
),
|
||||||
ty::error::TypeError::Mismatch,
|
ty::error::TypeError::Mismatch,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue