Rollup merge of #100483 - compiler-errors:point-to-projection-too, r=jyn514
Point to generic or arg if it's the self type of unsatisfied projection predicate We do this for `TraitPredicate`s in `point_at_type_arg_instead_of_call_if_possible` and `point_at_arg_instead_of_call_if_possible`, so also do it for `ProjectionPredicate`. Improves spans for a lot of unit tests.
This commit is contained in:
commit
ee63d09bd6
16 changed files with 155 additions and 92 deletions
|
@ -1664,12 +1664,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
ObligationCauseCode::ImplDerivedObligation(code) => {
|
||||
code.derived.parent_trait_pred.self_ty().skip_binder().into()
|
||||
}
|
||||
_ if let ty::PredicateKind::Trait(predicate) =
|
||||
error.obligation.predicate.kind().skip_binder() =>
|
||||
{
|
||||
predicate.self_ty().into()
|
||||
}
|
||||
_ => continue,
|
||||
_ => match error.obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(predicate) => predicate.self_ty().into(),
|
||||
ty::PredicateKind::Projection(predicate) => {
|
||||
predicate.projection_ty.self_ty().into()
|
||||
}
|
||||
_ => continue,
|
||||
},
|
||||
};
|
||||
let self_ = self.resolve_vars_if_possible(self_);
|
||||
let ty_matches_self = |ty: Ty<'tcx>| ty.walk().any(|arg| arg == self_);
|
||||
|
@ -1759,25 +1760,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
if let hir::ExprKind::Call(path, _) = &call_expr.kind {
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &path.kind {
|
||||
for error in errors {
|
||||
if let ty::PredicateKind::Trait(predicate) =
|
||||
error.obligation.predicate.kind().skip_binder()
|
||||
let self_ty = match error.obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(predicate) => predicate.self_ty(),
|
||||
ty::PredicateKind::Projection(predicate) => {
|
||||
predicate.projection_ty.self_ty()
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
// If any of the type arguments in this path segment caused the
|
||||
// `FulfillmentError`, point at its span (#61860).
|
||||
for arg in path
|
||||
.segments
|
||||
.iter()
|
||||
.filter_map(|seg| seg.args.as_ref())
|
||||
.flat_map(|a| a.args.iter())
|
||||
{
|
||||
// If any of the type arguments in this path segment caused the
|
||||
// `FulfillmentError`, point at its span (#61860).
|
||||
for arg in path
|
||||
.segments
|
||||
.iter()
|
||||
.filter_map(|seg| seg.args.as_ref())
|
||||
.flat_map(|a| a.args.iter())
|
||||
if let hir::GenericArg::Type(hir_ty) = &arg
|
||||
&& let Some(ty) =
|
||||
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
|
||||
&& self.resolve_vars_if_possible(ty) == self_ty
|
||||
{
|
||||
if let hir::GenericArg::Type(hir_ty) = &arg
|
||||
&& let Some(ty) =
|
||||
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
|
||||
&& self.resolve_vars_if_possible(ty) == predicate.self_ty()
|
||||
{
|
||||
error.obligation.cause.span = hir_ty.span;
|
||||
break;
|
||||
}
|
||||
error.obligation.cause.span = hir_ty.span;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue