about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-06-22 00:00:37 +0900
committerGitHub <noreply@github.com>2021-06-22 00:00:37 +0900
commitac410564f0ec68c59c0d9bc6980b469467bf50c0 (patch)
treee77166cc32011c469782403c57843f1eca7500f2
parent3ee78b38fe8cba0b7028fca58bf16d2bd8c73e5f (diff)
parentc09b6996317b711d6153116c13fd8085f3868f93 (diff)
Rollup merge of #86248 - JohnTitor:issue-85113, r=Mark-Simulacrum
Add a regression test for issue-85113

Fixed by #86118, closes #85113
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-85113.rs22
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-85113.stderr48
2 files changed, 70 insertions, 0 deletions
diff --git a/src/test/ui/type-alias-impl-trait/issue-85113.rs b/src/test/ui/type-alias-impl-trait/issue-85113.rs
new file mode 100644
index 00000000000..b09833f3ed0
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-85113.rs
@@ -0,0 +1,22 @@
+#![feature(min_type_alias_impl_trait)]
+#![feature(impl_trait_in_bindings)]
+#![allow(incomplete_features)]
+
+type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
+//~^ ERROR: hidden type for `impl Trait` captures lifetime that does not appear in bounds
+//~| ERROR: the type `&'<empty> str` does not fulfill the required lifetime
+//~| ERROR: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
+
+trait Output<'a> {}
+
+impl<'a> Output<'a> for &'a str {}
+
+fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> {
+    let out: OpaqueOutputImpl<'a> = arg;
+    arg
+}
+
+fn main() {
+    let s = String::from("wassup");
+    cool_fn(&s);
+}
diff --git a/src/test/ui/type-alias-impl-trait/issue-85113.stderr b/src/test/ui/type-alias-impl-trait/issue-85113.stderr
new file mode 100644
index 00000000000..361d66866ef
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-85113.stderr
@@ -0,0 +1,48 @@
+error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
+  --> $DIR/issue-85113.rs:5:29
+   |
+LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
+   |                             ^^^^^^^^^^^^^^^^^^^^
+   |
+note: hidden type `&'<empty> str` captures lifetime smaller than the function body
+  --> $DIR/issue-85113.rs:5:29
+   |
+LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
+   |                             ^^^^^^^^^^^^^^^^^^^^
+
+error[E0477]: the type `&'<empty> str` does not fulfill the required lifetime
+  --> $DIR/issue-85113.rs:5:29
+   |
+LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
+   |                             ^^^^^^^^^^^^^^^^^^^^
+   |
+note: type must outlive the lifetime `'a` as defined on the item at 5:23
+  --> $DIR/issue-85113.rs:5:23
+   |
+LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
+   |                       ^^
+
+error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
+  --> $DIR/issue-85113.rs:5:29
+   |
+LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
+   |                             ^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: first, the lifetime cannot outlive the empty lifetime...
+note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the item at 5:23...
+  --> $DIR/issue-85113.rs:5:23
+   |
+LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
+   |                       ^^
+note: ...so that the types are compatible
+  --> $DIR/issue-85113.rs:5:29
+   |
+LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
+   |                             ^^^^^^^^^^^^^^^^^^^^
+   = note: expected `Output<'a>`
+              found `Output<'_>`
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0477, E0495, E0700.
+For more information about an error, try `rustc --explain E0477`.