You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `must_not_suspend` attribute is used to issue a diagnostic warning when a value is not "used". It can be applied to user-defined composite types (structs, enums and unions), functions and traits.
66
+
The `must_not_suspend` attribute is used to issue a diagnostic warning when a value is not "used". It can be applied to user-defined composite types (structs, enums and unions), traits.
67
67
68
68
The `must_not_suspend` attribute may include a message by using the [`MetaNameValueStr`] syntax such as `#[must_not_suspend = "example message"]`. The message will be given alongside the warning.
69
69
@@ -81,19 +81,6 @@ async fn foo() {
81
81
}
82
82
```
83
83
84
-
When used on a function, if the value returned by a function is held across an await point, this lint is violated.
85
-
86
-
```rust
87
-
#[must_not_suspend]
88
-
fnfoo() ->i32 { 5i32 }
89
-
90
-
asyncfnfoo() {
91
-
letbar=foo();
92
-
my_async_op.await;
93
-
println!("{:?}", bar);
94
-
}
95
-
```
96
-
97
84
When used on a [trait declaration], if the value implementing that trait is held across an await point, the lint is violated.
98
85
99
86
```rust
@@ -114,26 +101,6 @@ async fn foo() {
114
101
}
115
102
```
116
103
117
-
When used on a function in a trait declaration, then the behavior also applies when the call expression is a function from the implementation of the trait.
118
-
119
-
```rust
120
-
traitTrait {
121
-
#[must_not_suspend]
122
-
fnfoo(&self) ->i32;
123
-
}
124
-
125
-
implTraitfori32 {
126
-
fnfoo(&self) ->i32 { 0i32 }
127
-
}
128
-
129
-
asyncfnfoo() {
130
-
letbar=5i32.foo();
131
-
my_async_op.await;
132
-
println!("{:?}", bar);
133
-
}
134
-
```
135
-
136
-
137
104
When used on a function in a trait implementation, the attribute does nothing.
Going through the prior are we see two systems currently which provide simailar/semantically similar behavior:
119
+
Going through the prior art we see two systems currently which provide similar/semantically similar behavior:
153
120
154
121
## Clippy `await_holding_lock` lint
155
122
This lint goes through all types in `generator_interior_types` looking for `MutexGuard`, `RwLockReadGuard` and `RwLockWriteGuard`. While this is a first great step, we think that this can be further extended to handle not only the hardcoded lock guards, but any type which is should not be held across an await point. By marking a type as `#[must_not_suspend]` we can warn when any arbitrary type is being held across an await boundary. An additional benefit to this approach is that this behaviour can be extended to any type which holds a `#[must_not_suspend]` type inside of it.
0 commit comments