about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-08-13 07:14:54 +0000
committerMichael Goulet <michael@errs.io>2022-08-14 20:22:10 +0000
commit54edf1863e120f9b2f3bf1a3f2b5040e9c8ca476 (patch)
tree4b9f8c87cbca6a53035a9f4297fc07babce36a87
parent16b33cc1e32d1814d961d97a6e76defc079316d2 (diff)
downloadrust-54edf1863e120f9b2f3bf1a3f2b5040e9c8ca476.tar.gz
rust-54edf1863e120f9b2f3bf1a3f2b5040e9c8ca476.zip
Also do it for generics
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/checks.rs37
-rw-r--r--src/test/ui/associated-types/associated-types-eq-hr.stderr8
-rw-r--r--src/test/ui/traits/object/enforce-supertrait-projection.stderr4
-rw-r--r--src/test/ui/traits/pointee-tail-is-generic-errors.stderr8
4 files changed, 30 insertions, 27 deletions
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
index 1f2dfc30ae0..bdb7c90aca3 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
@@ -1756,25 +1756,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;
                         }
                     }
                 }
diff --git a/src/test/ui/associated-types/associated-types-eq-hr.stderr b/src/test/ui/associated-types/associated-types-eq-hr.stderr
index b306ae273e8..6cff403b318 100644
--- a/src/test/ui/associated-types/associated-types-eq-hr.stderr
+++ b/src/test/ui/associated-types/associated-types-eq-hr.stderr
@@ -1,8 +1,8 @@
 error[E0271]: type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
-  --> $DIR/associated-types-eq-hr.rs:87:5
+  --> $DIR/associated-types-eq-hr.rs:87:11
    |
 LL |     foo::<UintStruct>();
-   |     ^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
+   |           ^^^^^^^^^^ type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
    |
 note: expected this to be `&isize`
   --> $DIR/associated-types-eq-hr.rs:26:14
@@ -21,10 +21,10 @@ LL |     T: for<'x> TheTrait<&'x isize, A = &'x isize>,
    |                                    ^^^^^^^^^^^^^ required by this bound in `foo`
 
 error[E0271]: type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
-  --> $DIR/associated-types-eq-hr.rs:91:5
+  --> $DIR/associated-types-eq-hr.rs:91:11
    |
 LL |     bar::<IntStruct>();
-   |     ^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
+   |           ^^^^^^^^^ type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
    |
 note: expected this to be `&usize`
   --> $DIR/associated-types-eq-hr.rs:14:14
diff --git a/src/test/ui/traits/object/enforce-supertrait-projection.stderr b/src/test/ui/traits/object/enforce-supertrait-projection.stderr
index eab42ca568a..cbf09386654 100644
--- a/src/test/ui/traits/object/enforce-supertrait-projection.stderr
+++ b/src/test/ui/traits/object/enforce-supertrait-projection.stderr
@@ -1,12 +1,12 @@
 error[E0271]: type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B`
-  --> $DIR/enforce-supertrait-projection.rs:9:5
+  --> $DIR/enforce-supertrait-projection.rs:9:17
    |
 LL | fn transmute<A, B>(x: A) -> B {
    |              -  - expected type parameter
    |              |
    |              found type parameter
 LL |     foo::<A, B, dyn Trait<A = A, B = B>>(x)
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `B`, found type parameter `A`
+   |                 ^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `B`, found type parameter `A`
    |
    = note: expected type parameter `B`
               found type parameter `A`
diff --git a/src/test/ui/traits/pointee-tail-is-generic-errors.stderr b/src/test/ui/traits/pointee-tail-is-generic-errors.stderr
index 8456f84562f..0c3d7060dd7 100644
--- a/src/test/ui/traits/pointee-tail-is-generic-errors.stderr
+++ b/src/test/ui/traits/pointee-tail-is-generic-errors.stderr
@@ -1,8 +1,8 @@
 error[E0271]: type mismatch resolving `<T as Pointee>::Metadata == ()`
-  --> $DIR/pointee-tail-is-generic-errors.rs:13:5
+  --> $DIR/pointee-tail-is-generic-errors.rs:13:15
    |
 LL |     is_thin::<T>();
-   |     ^^^^^^^^^^^^ expected `()`, found associated type
+   |               ^ expected `()`, found associated type
    |
    = note:    expected unit type `()`
            found associated type `<T as Pointee>::Metadata`
@@ -15,13 +15,13 @@ LL | fn is_thin<T: std::ptr::Pointee<Metadata = ()> + ?Sized>() {}
    |                                 ^^^^^^^^^^^^^ required by this bound in `is_thin`
 
 error[E0271]: type mismatch resolving `<Opaque as Pointee>::Metadata == ()`
-  --> $DIR/pointee-tail-is-generic-errors.rs:16:5
+  --> $DIR/pointee-tail-is-generic-errors.rs:16:15
    |
 LL | type Opaque = impl std::fmt::Debug + ?Sized;
    |               ----------------------------- the found opaque type
 ...
 LL |     is_thin::<Opaque>();
-   |     ^^^^^^^^^^^^^^^^^ expected `()`, found associated type
+   |               ^^^^^^ expected `()`, found associated type
    |
    = note:    expected unit type `()`
            found associated type `<Opaque as Pointee>::Metadata`