]> git.lizzy.rs Git - rust.git/blob - src/test/ui/async-await/issue-61076.rs
Rollup merge of #75892 - ArekPiekarz:unstable_book_tls_model_typo, r=petrochenkov
[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 `std::ops::Try`
43     Ok(())
44 }
45
46 async fn struct_() -> Struct {
47     Struct { a: 1 }
48 }
49
50 async fn tuple() -> Tuple {
51     Tuple(1i32)
52 }
53
54 async fn baz() -> Result<(), ()> {
55     let t = T;
56     t?; //~ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
57
58     let _: i32 = tuple().0; //~ ERROR no field `0`
59
60     let _: i32 = struct_().a; //~ ERROR no field `a`
61
62     struct_().method(); //~ ERROR no method named
63
64     Ok(())
65 }
66
67 async fn match_() {
68     match tuple() {
69         Tuple(_) => {} //~ ERROR mismatched types
70     }
71 }
72
73 fn main() {}