diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-08-15 10:28:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-15 10:28:11 +0200 |
| commit | ee63d09bd6e37439dfbe8814dd5664bb1f4b6438 (patch) | |
| tree | 38e4679ea3cc5b304ae67bdc7baedfc8e095c454 /compiler | |
| parent | 965ed812fbdd645d3988ded7b8c6a0946cac3cf3 (diff) | |
| parent | 54edf1863e120f9b2f3bf1a3f2b5040e9c8ca476 (diff) | |
| download | rust-ee63d09bd6e37439dfbe8814dd5664bb1f4b6438.tar.gz rust-ee63d09bd6e37439dfbe8814dd5664bb1f4b6438.zip | |
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.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_typeck/src/check/fn_ctxt/checks.rs | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 1177113ad8a..296fdf504ce 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -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; } } } |
