]> git.lizzy.rs Git - rust.git/blob - src/test/ui/async-await/issue-61076.rs
Implement a lint that highlights all moves larger than 1000 bytes
[rust.git] / src / test / ui / async-await / issue-61076.rs
1 // edition:2018
2
3 use core::future::Future;
4 use core::pin::Pin;
5 use core::task::{Context, Poll};
6
7 struct T;
8
9 struct Tuple(i32);
10
11 struct Struct {
12     a: i32
13 }
14
15 impl Struct {
16     fn method(&self) {}
17 }
18
19 impl Future for Struct {
20     type Output = Struct;
21     fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> { Poll::Pending }
22 }
23
24 impl Future for Tuple {
25     type Output = Tuple;
26     fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> { Poll::Pending }
27 }
28
29 impl Future for T {
30     type Output = Result<(), ()>;
31
32     fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
33         Poll::Pending
34     }
35 }
36
37 async fn foo() -> Result<(), ()> {
38     Ok(())
39 }
40
41 async fn bar() -> Result<(), ()> {
42     foo()?; //~ ERROR the `?` operator can only be applied to values that implement `Try`
43     //~^ NOTE the `?` operator cannot be applied to type `impl Future`
44     //~| HELP the trait `Try` is not implemented for `impl Future`
45     //~| NOTE required by `into_result`
46     //~| HELP consider `await`ing on the `Future`
47     //~| NOTE in this expansion of desugaring of operator `?`
48     //~| NOTE in this expansion of desugaring of operator `?`
49     //~| NOTE in this expansion of desugaring of operator `?`
50     //~| NOTE in this expansion of desugaring of operator `?`
51     Ok(())
52 }
53
54 async fn struct_() -> Struct {
55     Struct { a: 1 }
56 }
57
58 async fn tuple() -> Tuple {
59     //~^ NOTE checked the `Output` of this `async fn`, expected opaque type
60     Tuple(1i32)
61 }
62
63 async fn baz() -> Result<(), ()> {
64     let t = T;
65     t?; //~ ERROR the `?` operator can only be applied to values that implement `Try`
66     //~^ NOTE the `?` operator cannot be applied to type `T`
67     //~| HELP the trait `Try` is not implemented for `T`
68     //~| NOTE required by `into_result`
69     //~| HELP consider `await`ing on the `Future`
70     //~| NOTE in this expansion of desugaring of operator `?`
71     //~| NOTE in this expansion of desugaring of operator `?`
72     //~| NOTE in this expansion of desugaring of operator `?`
73     //~| NOTE in this expansion of desugaring of operator `?`
74
75
76     let _: i32 = tuple().0; //~ ERROR no field `0`
77     //~^ HELP consider `await`ing on the `Future`
78     //~| NOTE field not available in `impl Future`
79
80     let _: i32 = struct_().a; //~ ERROR no field `a`
81     //~^ HELP consider `await`ing on the `Future`
82     //~| NOTE field not available in `impl Future`
83
84     struct_().method(); //~ ERROR no method named
85     //~^ NOTE method not found in `impl Future`
86     //~| HELP consider `await`ing on the `Future`
87     Ok(())
88 }
89
90 async fn match_() {
91     match tuple() { //~ HELP consider `await`ing on the `Future`
92         Tuple(_) => {} //~ ERROR mismatched types
93         //~^ NOTE expected opaque type, found struct `Tuple`
94         //~| NOTE expected opaque type `impl Future`
95         //~| NOTE while checking the return type of the `async fn`
96     }
97 }
98
99 fn main() {}