]> git.proxmox.com Git - rustc.git/blame - tests/ui/impl-trait/in-trait/signature-mismatch.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / tests / ui / impl-trait / in-trait / signature-mismatch.rs
CommitLineData
2b03887a 1// edition:2021
781aab86
FG
2// revisions: success failure
3//[success] check-pass
2b03887a 4
781aab86 5#![feature(return_position_impl_trait_in_trait, lint_reasons)]
2b03887a
FG
6
7use std::future::Future;
8
781aab86 9pub trait Captures<'a> {}
fe692bf9
FG
10impl<T> Captures<'_> for T {}
11
781aab86 12pub trait Captures2<'a, 'b> {}
fe692bf9
FG
13impl<T> Captures2<'_, '_> for T {}
14
2b03887a 15pub trait AsyncTrait {
781aab86 16 #[cfg(success)]
2b03887a 17 fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
781aab86
FG
18
19 #[cfg(success)]
fe692bf9 20 fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>>;
781aab86
FG
21
22 #[cfg(success)]
fe692bf9 23 fn async_fn_multiple<'a>(&'a self, buff: &[u8])
781aab86
FG
24 -> impl Future<Output = Vec<u8>> + Captures<'a>;
25
26 #[cfg(failure)]
fe692bf9
FG
27 fn async_fn_reduce_outlive<'a, T>(
28 &'a self,
29 buff: &[u8],
30 t: T,
31 ) -> impl Future<Output = Vec<u8>> + 'a;
781aab86
FG
32
33 #[cfg(success)]
fe692bf9
FG
34 fn async_fn_reduce<'a, T>(
35 &'a self,
36 buff: &[u8],
37 t: T,
38 ) -> impl Future<Output = Vec<u8>> + Captures<'a>;
2b03887a
FG
39}
40
41pub struct Struct;
42
43impl AsyncTrait for Struct {
781aab86
FG
44 // Does not capture more lifetimes that trait def'n, since trait def'n
45 // implicitly captures all in-scope lifetimes.
46 #[cfg(success)]
47 #[expect(refining_impl_trait)]
2b03887a 48 fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
fe692bf9
FG
49 async move { buff.to_vec() }
50 }
51
781aab86
FG
52 // Does not capture more lifetimes that trait def'n, since trait def'n
53 // implicitly captures all in-scope lifetimes.
54 #[cfg(success)]
55 #[expect(refining_impl_trait)]
fe692bf9 56 fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
fe692bf9
FG
57 async move { buff.to_vec() }
58 }
59
781aab86
FG
60 // Does not capture more lifetimes that trait def'n, since trait def'n
61 // implicitly captures all in-scope lifetimes.
62 #[cfg(success)]
63 #[expect(refining_impl_trait)]
fe692bf9
FG
64 fn async_fn_multiple<'a, 'b>(
65 &'a self,
66 buff: &'b [u8],
67 ) -> impl Future<Output = Vec<u8>> + Captures2<'a, 'b> {
2b03887a
FG
68 async move { buff.to_vec() }
69 }
fe692bf9 70
781aab86
FG
71 // This error message is awkward, but `impl Future<Output = Vec<u8>>`
72 // cannot outlive `'a` (from the trait signature) because it captures
73 // both `T` and `'b`.
74 #[cfg(failure)]
fe692bf9
FG
75 fn async_fn_reduce_outlive<'a, 'b, T>(
76 &'a self,
77 buff: &'b [u8],
78 t: T,
79 ) -> impl Future<Output = Vec<u8>> {
781aab86 80 //[failure]~^ ERROR lifetime mismatch
fe692bf9
FG
81 async move {
82 let _t = t;
83 vec![]
84 }
85 }
86
781aab86
FG
87 // Does not capture fewer lifetimes that trait def'n (not that it matters),
88 // since impl also captures all in-scope lifetimes.
89 #[cfg(success)]
fe692bf9
FG
90 fn async_fn_reduce<'a, 'b, T>(&'a self, buff: &'b [u8], t: T) -> impl Future<Output = Vec<u8>> {
91 async move {
92 let _t = t;
93 vec![]
94 }
95 }
2b03887a
FG
96}
97
98fn main() {}