about summary refs log tree commit diff
path: root/tests/ui/impl-trait/in-trait/do-not-imply-from-trait-impl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/impl-trait/in-trait/do-not-imply-from-trait-impl.rs')
-rw-r--r--tests/ui/impl-trait/in-trait/do-not-imply-from-trait-impl.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/in-trait/do-not-imply-from-trait-impl.rs b/tests/ui/impl-trait/in-trait/do-not-imply-from-trait-impl.rs
new file mode 100644
index 00000000000..30ca3d271b8
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/do-not-imply-from-trait-impl.rs
@@ -0,0 +1,30 @@
+// Make sure that we don't accidentally collect an RPITIT hidden type that does not
+// hold for all instantiations of the trait signature.
+
+trait MkStatic {
+    fn mk_static(self) -> &'static str;
+}
+
+impl MkStatic for &'static str {
+    fn mk_static(self) -> &'static str { self }
+}
+
+trait Foo {
+    fn foo<'a: 'static, 'late>(&'late self) -> impl MkStatic;
+}
+
+impl Foo for str {
+    fn foo<'a: 'static>(&'a self) -> impl MkStatic + 'static {
+    //~^ ERROR method not compatible with trait
+        self
+    }
+}
+
+fn call_foo<T: Foo + ?Sized>(t: &T) -> &'static str {
+    t.foo().mk_static()
+}
+
+fn main() {
+    let s = call_foo(String::from("hello, world").as_str());
+    println!("> {s}");
+}