]> git.lizzy.rs Git - rust.git/blob - tests/ui/generator/drop-tracking-parent-expression.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / generator / drop-tracking-parent-expression.rs
1 // compile-flags: -Zdrop-tracking
2 #![feature(generators, negative_impls, rustc_attrs)]
3
4 macro_rules! type_combinations {
5     (
6         $( $name:ident => { $( $tt:tt )* } );* $(;)?
7     ) => { $(
8         mod $name {
9             $( $tt )*
10
11             impl !Sync for Client {}
12             impl !Send for Client {}
13         }
14
15         // Struct update syntax. This fails because the Client used in the update is considered
16         // dropped *after* the yield.
17         {
18             let g = move || match drop($name::Client { ..$name::Client::default() }) {
19             //~^ `significant_drop::Client` which is not `Send`
20             //~| `insignificant_dtor::Client` which is not `Send`
21             //~| `derived_drop::Client` which is not `Send`
22                 _ => yield,
23             };
24             assert_send(g);
25             //~^ ERROR cannot be sent between threads
26             //~| ERROR cannot be sent between threads
27             //~| ERROR cannot be sent between threads
28         }
29
30         // Simple owned value. This works because the Client is considered moved into `drop`,
31         // even though the temporary expression doesn't end until after the yield.
32         {
33             let g = move || match drop($name::Client::default()) {
34                 _ => yield,
35             };
36             assert_send(g);
37         }
38     )* }
39 }
40
41 fn assert_send<T: Send>(_thing: T) {}
42
43 fn main() {
44     type_combinations!(
45         // OK
46         copy => { #[derive(Copy, Clone, Default)] pub struct Client; };
47         // NOT OK: MIR borrowck thinks that this is used after the yield, even though
48         // this has no `Drop` impl and only the drops of the fields are observable.
49         // FIXME: this should compile.
50         derived_drop => { #[derive(Default)] pub struct Client { pub nickname: String } };
51         // NOT OK
52         significant_drop => {
53             #[derive(Default)]
54             pub struct Client;
55             impl Drop for Client {
56                 fn drop(&mut self) {}
57             }
58         };
59         // NOT OK (we need to agree with MIR borrowck)
60         insignificant_dtor => {
61             #[derive(Default)]
62             #[rustc_insignificant_dtor]
63             pub struct Client;
64             impl Drop for Client {
65                 fn drop(&mut self) {}
66             }
67         };
68     );
69 }