about summary refs log tree commit diff
path: root/src/test/ui/issues
diff options
context:
space:
mode:
authorrhysd <lin90162@yahoo.co.jp>2021-10-08 01:00:15 +0900
committerrhysd <lin90162@yahoo.co.jp>2021-10-09 00:07:37 +0900
commit7b9ddbdcf261c0010b24f53281bf2f27d02eb6f2 (patch)
treea880d11cf342266656ebd93b3b948a7dddad74a7 /src/test/ui/issues
parentca8078d7b2e40c24a39e5fe2a910afef4c91ebfc (diff)
Show detailed expected/found types in error message when trait paths are the same
Diffstat (limited to 'src/test/ui/issues')
-rw-r--r--src/test/ui/issues/issue-20831-debruijn.stderr4
-rw-r--r--src/test/ui/issues/issue-65230.rs19
-rw-r--r--src/test/ui/issues/issue-65230.stderr38
3 files changed, 59 insertions, 2 deletions
diff --git a/src/test/ui/issues/issue-20831-debruijn.stderr b/src/test/ui/issues/issue-20831-debruijn.stderr
index 03e3311e0f3..02c80c29408 100644
--- a/src/test/ui/issues/issue-20831-debruijn.stderr
+++ b/src/test/ui/issues/issue-20831-debruijn.stderr
@@ -19,8 +19,8 @@ note: ...so that the types are compatible
    |
 LL |     fn subscribe(&mut self, t : Box<dyn Subscriber<Input=<Self as Publisher>::Output> + 'a>) {
    |        ^^^^^^^^^
-   = note: expected `Publisher<'_>`
-              found `Publisher<'_>`
+   = note: expected `<MyStruct<'a> as Publisher<'_>>`
+              found `<MyStruct<'_> as Publisher<'_>>`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-65230.rs b/src/test/ui/issues/issue-65230.rs
new file mode 100644
index 00000000000..10d9e810996
--- /dev/null
+++ b/src/test/ui/issues/issue-65230.rs
@@ -0,0 +1,19 @@
+trait T {
+    type U;
+    fn f(&self) -> Self::U;
+}
+
+struct X<'a>(&'a mut i32);
+
+impl<'a> T for X<'a> {
+    type U = &'a i32;
+    fn f(&self) -> Self::U {
+        self.0
+    }
+    //~^^^ ERROR cannot infer an appropriate lifetime for lifetime parameter `'a`
+    //
+    // Return type of `f` has lifetime `'a` but it tries to return `self.0` which
+    // has lifetime `'_`.
+}
+
+fn main() {}
diff --git a/src/test/ui/issues/issue-65230.stderr b/src/test/ui/issues/issue-65230.stderr
new file mode 100644
index 00000000000..21e3f6b1ebb
--- /dev/null
+++ b/src/test/ui/issues/issue-65230.stderr
@@ -0,0 +1,38 @@
+error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
+  --> $DIR/issue-65230.rs:10:28
+   |
+LL |       fn f(&self) -> Self::U {
+   |  ____________________________^
+LL | |         self.0
+LL | |     }
+   | |_____^
+   |
+note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 10:10...
+  --> $DIR/issue-65230.rs:10:10
+   |
+LL |     fn f(&self) -> Self::U {
+   |          ^^^^^
+note: ...so that reference does not outlive borrowed content
+  --> $DIR/issue-65230.rs:11:9
+   |
+LL |         self.0
+   |         ^^^^^^
+note: but, the lifetime must be valid for the lifetime `'a` as defined on the impl at 8:6...
+  --> $DIR/issue-65230.rs:8:6
+   |
+LL | impl<'a> T for X<'a> {
+   |      ^^
+note: ...so that the types are compatible
+  --> $DIR/issue-65230.rs:10:28
+   |
+LL |       fn f(&self) -> Self::U {
+   |  ____________________________^
+LL | |         self.0
+LL | |     }
+   | |_____^
+   = note: expected `<X<'a> as T>`
+              found `<X<'_> as T>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0495`.