about summary refs log tree commit diff
path: root/tests/ui/impl-trait/in-trait
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/impl-trait/in-trait')
-rw-r--r--tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr17
-rw-r--r--tests/ui/impl-trait/in-trait/deep-match-works.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/foreign.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/issue-102571.rs8
-rw-r--r--tests/ui/impl-trait/in-trait/issue-102571.stderr2
-rw-r--r--tests/ui/impl-trait/in-trait/nested-rpitit.rs2
-rw-r--r--tests/ui/impl-trait/in-trait/object-safety.rs2
-rw-r--r--tests/ui/impl-trait/in-trait/refine.rs36
-rw-r--r--tests/ui/impl-trait/in-trait/refine.stderr63
-rw-r--r--tests/ui/impl-trait/in-trait/reveal.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/rpitit-shadowed-by-missing-adt.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/signature-mismatch.failure.stderr2
-rw-r--r--tests/ui/impl-trait/in-trait/signature-mismatch.rs4
-rw-r--r--tests/ui/impl-trait/in-trait/specialization-substs-remap.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/success.rs3
17 files changed, 133 insertions, 13 deletions
diff --git a/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs
index cfc2193f633..5bd5c48ca69 100644
--- a/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs
+++ b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs
@@ -8,6 +8,7 @@ pub trait Foo {
 
 pub struct Foreign;
 impl Foo for Foreign {
+    #[allow(refining_impl_trait)]
     fn bar(self) -> &'static () {
         &()
     }
diff --git a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.rs b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.rs
index ff7ad4bf389..063adb7c378 100644
--- a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.rs
+++ b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.rs
@@ -17,6 +17,7 @@ impl<'a, I: 'a + Iterable> Iterable for &'a I {
     //~^ ERROR impl has stricter requirements than trait
 
     fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> {
+        //~^ WARN impl trait in impl method signature does not match trait method signature
         (*self).iter()
     }
 }
diff --git a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr
index 106b8a7c804..8d08d5e521e 100644
--- a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr
+++ b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr
@@ -12,6 +12,21 @@ help: copy the `where` clause predicates from the trait
 LL |     where Self: 'b;
    |     ~~~~~~~~~~~~~~
 
-error: aborting due to previous error
+warning: impl trait in impl method signature does not match trait method signature
+  --> $DIR/bad-item-bound-within-rpitit.rs:19:28
+   |
+LL |     fn iter(&self) -> impl '_ + Iterator<Item = Self::Item<'_>>;
+   |                       ----------------------------------------- return type from trait method defined here
+...
+LL |     fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> {
+   |                            ^^ this bound is stronger than that defined on the trait
+   |
+   = note: `#[warn(refining_impl_trait)]` on by default
+help: replace the return type so that it matches the trait
+   |
+LL |     fn iter(&self) -> impl Iterator<Item = <&'a I as Iterable>::Item<'_>> + '_ {
+   |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: aborting due to previous error; 1 warning emitted
 
 For more information about this error, try `rustc --explain E0276`.
diff --git a/tests/ui/impl-trait/in-trait/deep-match-works.rs b/tests/ui/impl-trait/in-trait/deep-match-works.rs
index 78cff97c616..ffd10d9b1ff 100644
--- a/tests/ui/impl-trait/in-trait/deep-match-works.rs
+++ b/tests/ui/impl-trait/in-trait/deep-match-works.rs
@@ -10,6 +10,7 @@ trait Foo {
 }
 
 impl Foo for () {
+    #[allow(refining_impl_trait)]
     fn bar() -> Wrapper<i32> {
         Wrapper(0)
     }
diff --git a/tests/ui/impl-trait/in-trait/foreign.rs b/tests/ui/impl-trait/in-trait/foreign.rs
index b0c93a02935..035d91c1876 100644
--- a/tests/ui/impl-trait/in-trait/foreign.rs
+++ b/tests/ui/impl-trait/in-trait/foreign.rs
@@ -9,6 +9,7 @@ use std::sync::Arc;
 // Implement an RPITIT from another crate.
 struct Local;
 impl Foo for Local {
+    #[allow(refining_impl_trait)]
     fn bar(self) -> Arc<String> {
         Arc::new(String::new())
     }
diff --git a/tests/ui/impl-trait/in-trait/issue-102571.rs b/tests/ui/impl-trait/in-trait/issue-102571.rs
index 61c91e64417..ccb53031c44 100644
--- a/tests/ui/impl-trait/in-trait/issue-102571.rs
+++ b/tests/ui/impl-trait/in-trait/issue-102571.rs
@@ -8,14 +8,6 @@ trait Foo {
     fn bar(self) -> impl Deref<Target = impl Display + ?Sized>;
 }
 
-struct A;
-
-impl Foo for A {
-    fn bar(self) -> &'static str {
-        "Hello, world"
-    }
-}
-
 fn foo<T: Foo>(t: T) {
     let () = t.bar();
     //~^ ERROR mismatched types
diff --git a/tests/ui/impl-trait/in-trait/issue-102571.stderr b/tests/ui/impl-trait/in-trait/issue-102571.stderr
index 87219941d91..594b9ae9cd6 100644
--- a/tests/ui/impl-trait/in-trait/issue-102571.stderr
+++ b/tests/ui/impl-trait/in-trait/issue-102571.stderr
@@ -1,5 +1,5 @@
 error[E0308]: mismatched types
-  --> $DIR/issue-102571.rs:20:9
+  --> $DIR/issue-102571.rs:12:9
    |
 LL |     let () = t.bar();
    |         ^^   ------- this expression has type `impl Deref<Target = impl std::fmt::Display + ?Sized>`
diff --git a/tests/ui/impl-trait/in-trait/nested-rpitit.rs b/tests/ui/impl-trait/in-trait/nested-rpitit.rs
index 65285e3a3cc..cb943eb5af9 100644
--- a/tests/ui/impl-trait/in-trait/nested-rpitit.rs
+++ b/tests/ui/impl-trait/in-trait/nested-rpitit.rs
@@ -13,6 +13,7 @@ trait Foo {
 struct A;
 
 impl Foo for A {
+    #[allow(refining_impl_trait)]
     fn bar(self) -> &'static str {
         "Hello, world"
     }
@@ -21,6 +22,7 @@ impl Foo for A {
 struct B;
 
 impl Foo for B {
+    #[allow(refining_impl_trait)]
     fn bar(self) -> Box<i32> {
         Box::new(42)
     }
diff --git a/tests/ui/impl-trait/in-trait/object-safety.rs b/tests/ui/impl-trait/in-trait/object-safety.rs
index 9a231e59b09..d1c9fba4e99 100644
--- a/tests/ui/impl-trait/in-trait/object-safety.rs
+++ b/tests/ui/impl-trait/in-trait/object-safety.rs
@@ -8,7 +8,7 @@ trait Foo {
 }
 
 impl Foo for u32 {
-    fn baz(&self) -> u32 {
+    fn baz(&self) -> impl Debug {
         32
     }
 }
diff --git a/tests/ui/impl-trait/in-trait/refine.rs b/tests/ui/impl-trait/in-trait/refine.rs
new file mode 100644
index 00000000000..e9b5e669fde
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/refine.rs
@@ -0,0 +1,36 @@
+#![feature(return_position_impl_trait_in_trait, async_fn_in_trait)]
+#![deny(refining_impl_trait)]
+
+trait Foo {
+    fn bar() -> impl Sized;
+}
+
+struct A;
+impl Foo for A {
+    fn bar() -> impl Copy {}
+    //~^ ERROR impl method signature does not match trait method signature
+}
+
+struct B;
+impl Foo for B {
+    fn bar() {}
+    //~^ ERROR impl method signature does not match trait method signature
+}
+
+struct C;
+impl Foo for C {
+    fn bar() -> () {}
+    //~^ ERROR impl method signature does not match trait method signature
+}
+
+trait Late {
+    fn bar<'a>(&'a self) -> impl Sized + 'a;
+}
+
+struct D;
+impl Late for D {
+    fn bar(&self) -> impl Copy + '_ {}
+    //~^ ERROR impl method signature does not match trait method signature
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/in-trait/refine.stderr b/tests/ui/impl-trait/in-trait/refine.stderr
new file mode 100644
index 00000000000..28d53270da3
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/refine.stderr
@@ -0,0 +1,63 @@
+error: impl trait in impl method signature does not match trait method signature
+  --> $DIR/refine.rs:10:22
+   |
+LL |     fn bar() -> impl Sized;
+   |                 ---------- return type from trait method defined here
+...
+LL |     fn bar() -> impl Copy {}
+   |                      ^^^^ this bound is stronger than that defined on the trait
+   |
+note: the lint level is defined here
+  --> $DIR/refine.rs:2:9
+   |
+LL | #![deny(refining_impl_trait)]
+   |         ^^^^^^^^^^^^^^^^^^^
+help: replace the return type so that it matches the trait
+   |
+LL |     fn bar() -> impl Sized {}
+   |                 ~~~~~~~~~~
+
+error: impl trait in impl method signature does not match trait method signature
+  --> $DIR/refine.rs:16:5
+   |
+LL |     fn bar() -> impl Sized;
+   |                 ---------- return type from trait method defined here
+...
+LL |     fn bar() {}
+   |     ^^^^^^^^
+   |
+help: replace the return type so that it matches the trait
+   |
+LL |     fn bar() -> impl Sized {}
+   |              +++++++++++++
+
+error: impl trait in impl method signature does not match trait method signature
+  --> $DIR/refine.rs:22:17
+   |
+LL |     fn bar() -> impl Sized;
+   |                 ---------- return type from trait method defined here
+...
+LL |     fn bar() -> () {}
+   |                 ^^
+   |
+help: replace the return type so that it matches the trait
+   |
+LL |     fn bar() -> impl Sized {}
+   |                 ~~~~~~~~~~
+
+error: impl trait in impl method signature does not match trait method signature
+  --> $DIR/refine.rs:32:27
+   |
+LL |     fn bar<'a>(&'a self) -> impl Sized + 'a;
+   |                             --------------- return type from trait method defined here
+...
+LL |     fn bar(&self) -> impl Copy + '_ {}
+   |                           ^^^^ this bound is stronger than that defined on the trait
+   |
+help: replace the return type so that it matches the trait
+   |
+LL |     fn bar(&self) -> impl Sized + '_ {}
+   |                      ~~~~~~~~~~~~~~~
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/impl-trait/in-trait/reveal.rs b/tests/ui/impl-trait/in-trait/reveal.rs
index d6ede1cc495..65425ba1a84 100644
--- a/tests/ui/impl-trait/in-trait/reveal.rs
+++ b/tests/ui/impl-trait/in-trait/reveal.rs
@@ -8,6 +8,7 @@ trait Foo {
 }
 
 impl Foo for () {
+    #[allow(refining_impl_trait)]
     fn f() -> Box<String> {
         Box::new(String::new())
     }
diff --git a/tests/ui/impl-trait/in-trait/rpitit-shadowed-by-missing-adt.rs b/tests/ui/impl-trait/in-trait/rpitit-shadowed-by-missing-adt.rs
index 7682884f879..747f7ed9e72 100644
--- a/tests/ui/impl-trait/in-trait/rpitit-shadowed-by-missing-adt.rs
+++ b/tests/ui/impl-trait/in-trait/rpitit-shadowed-by-missing-adt.rs
@@ -10,6 +10,7 @@ pub trait Tr {
 }
 
 impl Tr for () {
+    #[allow(refining_impl_trait)]
     fn w() -> &'static () {
         &()
     }
diff --git a/tests/ui/impl-trait/in-trait/signature-mismatch.failure.stderr b/tests/ui/impl-trait/in-trait/signature-mismatch.failure.stderr
index 186580f5756..468cf12f1bc 100644
--- a/tests/ui/impl-trait/in-trait/signature-mismatch.failure.stderr
+++ b/tests/ui/impl-trait/in-trait/signature-mismatch.failure.stderr
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/signature-mismatch.rs:77:10
+  --> $DIR/signature-mismatch.rs:79:10
    |
 LL |         &'a self,
    |         -------- this parameter and the return type are declared with different lifetimes...
diff --git a/tests/ui/impl-trait/in-trait/signature-mismatch.rs b/tests/ui/impl-trait/in-trait/signature-mismatch.rs
index c84a3b8f46b..135467d57ee 100644
--- a/tests/ui/impl-trait/in-trait/signature-mismatch.rs
+++ b/tests/ui/impl-trait/in-trait/signature-mismatch.rs
@@ -3,7 +3,6 @@
 //[success] check-pass
 
 #![feature(return_position_impl_trait_in_trait)]
-#![allow(incomplete_features)]
 
 use std::future::Future;
 
@@ -45,6 +44,7 @@ impl AsyncTrait for Struct {
     // Does not capture more lifetimes that trait def'n, since trait def'n
     // implicitly captures all in-scope lifetimes.
     #[cfg(success)]
+    #[allow(refining_impl_trait)]
     fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
         async move { buff.to_vec() }
     }
@@ -52,6 +52,7 @@ impl AsyncTrait for Struct {
     // Does not capture more lifetimes that trait def'n, since trait def'n
     // implicitly captures all in-scope lifetimes.
     #[cfg(success)]
+    #[allow(refining_impl_trait)]
     fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
         async move { buff.to_vec() }
     }
@@ -59,6 +60,7 @@ impl AsyncTrait for Struct {
     // Does not capture more lifetimes that trait def'n, since trait def'n
     // implicitly captures all in-scope lifetimes.
     #[cfg(success)]
+    #[allow(refining_impl_trait)]
     fn async_fn_multiple<'a, 'b>(
         &'a self,
         buff: &'b [u8],
diff --git a/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs b/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs
index c9ee877db8e..83812d6cd8a 100644
--- a/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs
+++ b/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs
@@ -12,6 +12,7 @@ impl<U> Foo for U
 where
     U: Copy,
 {
+    #[allow(refining_impl_trait)]
     fn bar(&self) -> U {
         *self
     }
diff --git a/tests/ui/impl-trait/in-trait/success.rs b/tests/ui/impl-trait/in-trait/success.rs
index 4cbe682b46f..f583604a021 100644
--- a/tests/ui/impl-trait/in-trait/success.rs
+++ b/tests/ui/impl-trait/in-trait/success.rs
@@ -10,12 +10,14 @@ trait Foo {
 }
 
 impl Foo for i32 {
+    #[allow(refining_impl_trait)]
     fn bar(&self) -> i32 {
         *self
     }
 }
 
 impl Foo for &'static str {
+    #[allow(refining_impl_trait)]
     fn bar(&self) -> &'static str {
         *self
     }
@@ -24,6 +26,7 @@ impl Foo for &'static str {
 struct Yay;
 
 impl Foo for Yay {
+    #[allow(refining_impl_trait)]
     fn bar(&self) -> String {
         String::from(":^)")
     }