about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-05-31 21:30:01 +0200
committerGitHub <noreply@github.com>2020-05-31 21:30:01 +0200
commit8e83a7e1262e8ff00496e23645e7fec3874b055c (patch)
tree2192e86d44596fb432606124449c07734a6ca88d /src
parent6cd9a67314a07ecb29f096f821d76ea0855b1156 (diff)
parent1a68c8e8d957e8df19e5adced776879bbe3d5344 (diff)
Rollup merge of #72807 - xiaotianrandom:fix-assoc-type-diagnostics, r=estebank
Avoid setting wrong obligation cause span of associated type mismatch

Removes code that sets wrong obligation cause span of associated type mismatch. See the linked issue for details.

Closes #72806.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trait_selection/traits/wf.rs31
-rw-r--r--src/test/ui/associated-types/issue-72806.rs20
-rw-r--r--src/test/ui/associated-types/issue-72806.stderr9
3 files changed, 41 insertions, 19 deletions
diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs
index 714ca7a30cf..39c7528a632 100644
--- a/src/librustc_trait_selection/traits/wf.rs
+++ b/src/librustc_trait_selection/traits/wf.rs
@@ -172,25 +172,18 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
         };
     match pred.kind() {
         ty::PredicateKind::Projection(proj) => {
-            // The obligation comes not from the current `impl` nor the `trait` being
-            // implemented, but rather from a "second order" obligation, like in
-            // `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs`.
-            let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
-            if let Some(impl_item_span) =
-                items.iter().find(|item| item.ident == trait_assoc_item.ident).map(fix_span)
-            {
-                cause.span = impl_item_span;
-            } else {
-                let kind = &proj.ty().skip_binder().kind;
-                if let ty::Projection(projection_ty) = kind {
-                    // This happens when an associated type has a projection coming from another
-                    // associated type. See `traits-assoc-type-in-supertrait-bad.rs`.
-                    let trait_assoc_item = tcx.associated_item(projection_ty.item_def_id);
-                    if let Some(impl_item_span) =
-                        items.iter().find(|item| item.ident == trait_assoc_item.ident).map(fix_span)
-                    {
-                        cause.span = impl_item_span;
-                    }
+            // The obligation comes not from the current `impl` nor the `trait` being implemented,
+            // but rather from a "second order" obligation, where an associated type has a
+            // projection coming from another associated type. See
+            // `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs` and
+            // `traits-assoc-type-in-supertrait-bad.rs`.
+            let kind = &proj.ty().skip_binder().kind;
+            if let ty::Projection(projection_ty) = kind {
+                let trait_assoc_item = tcx.associated_item(projection_ty.item_def_id);
+                if let Some(impl_item_span) =
+                    items.iter().find(|item| item.ident == trait_assoc_item.ident).map(fix_span)
+                {
+                    cause.span = impl_item_span;
                 }
             }
         }
diff --git a/src/test/ui/associated-types/issue-72806.rs b/src/test/ui/associated-types/issue-72806.rs
new file mode 100644
index 00000000000..ae63781d568
--- /dev/null
+++ b/src/test/ui/associated-types/issue-72806.rs
@@ -0,0 +1,20 @@
+trait Bar {
+    type Ok;
+    type Sibling: Bar2<Ok=char>;
+}
+trait Bar2 {
+    type Ok;
+}
+
+struct Foo;
+struct Foo2;
+
+impl Bar for Foo {  //~ ERROR type mismatch resolving `<Foo2 as Bar2>::Ok == char`
+    type Ok = ();
+    type Sibling = Foo2;
+}
+impl Bar2 for Foo2 {
+    type Ok = u32;
+}
+
+fn main() {}
diff --git a/src/test/ui/associated-types/issue-72806.stderr b/src/test/ui/associated-types/issue-72806.stderr
new file mode 100644
index 00000000000..03a6565848d
--- /dev/null
+++ b/src/test/ui/associated-types/issue-72806.stderr
@@ -0,0 +1,9 @@
+error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == char`
+  --> $DIR/issue-72806.rs:12:6
+   |
+LL | impl Bar for Foo {
+   |      ^^^ expected `u32`, found `char`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0271`.