]> git.lizzy.rs Git - rust.git/commitdiff
add a test for gate `impl_trait_in_fn_trait_return`
authorMaybe Waffle <waffle.lapkin@gmail.com>
Thu, 28 Jul 2022 22:28:36 +0000 (02:28 +0400)
committerMaybe Waffle <waffle.lapkin@gmail.com>
Tue, 25 Oct 2022 13:25:52 +0000 (13:25 +0000)
src/test/ui/feature-gates/feature-gate-impl_trait_in_fn_trait_return.rs [new file with mode: 0644]
src/test/ui/feature-gates/feature-gate-impl_trait_in_fn_trait_return.stderr [new file with mode: 0644]

diff --git a/src/test/ui/feature-gates/feature-gate-impl_trait_in_fn_trait_return.rs b/src/test/ui/feature-gates/feature-gate-impl_trait_in_fn_trait_return.rs
new file mode 100644 (file)
index 0000000..0db8088
--- /dev/null
@@ -0,0 +1,6 @@
+fn f() -> impl Fn() -> impl Sized { || () }
+//~^ ERROR `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return
+fn g() -> &'static dyn Fn() -> impl Sized { &|| () }
+//~^ ERROR `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return
+
+fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-impl_trait_in_fn_trait_return.stderr b/src/test/ui/feature-gates/feature-gate-impl_trait_in_fn_trait_return.stderr
new file mode 100644 (file)
index 0000000..c485bc5
--- /dev/null
@@ -0,0 +1,15 @@
+error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return
+  --> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:1:24
+   |
+LL | fn f() -> impl Fn() -> impl Sized { || () }
+   |                        ^^^^^^^^^^
+
+error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return
+  --> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:3:32
+   |
+LL | fn g() -> &'static dyn Fn() -> impl Sized { &|| () }
+   |                                ^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0562`.