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_await` 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), functions and traits.
67
67
68
-
The `must_not_await` attribute may include a message by using the [`MetaNameValueStr`] syntax such as `#[must_not_await = "example message"]`. The message will be given alongside the warning.
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
70
70
When used on a user-defined composite type, if a value exists across an await point, then this lint is violated.
71
71
72
72
73
73
```rust
74
-
#[must_not_await="Your error message here"]
74
+
#[must_not_suspend="Your error message here"]
75
75
structMyStruct {}
76
76
77
77
asyncfnfoo() {
@@ -84,7 +84,7 @@ async fn foo() {
84
84
When used on a function, if the value returned by a function is held across an await point, this lint is violated.
85
85
86
86
```rust
87
-
#[must_not_await]
87
+
#[must_not_suspend]
88
88
fnfoo() ->i32 { 5i32 }
89
89
90
90
asyncfnfoo() {
@@ -97,7 +97,7 @@ async fn foo() {
97
97
When used on a [trait declaration], if the value implementing that trait is held across an await point, the lint is violated.
98
98
99
99
```rust
100
-
#[must_not_await]
100
+
#[must_not_suspend]
101
101
traitLock {
102
102
fnfoo(&self) ->i32;
103
103
}
@@ -107,7 +107,7 @@ fn get_lock() -> impl Lock {
107
107
}
108
108
109
109
asyncfnfoo() {
110
-
// violates the #[must_not_await] lint
110
+
// violates the #[must_not_suspend] lint
111
111
letbar=get_lock();
112
112
my_async_op.await;
113
113
println!("{:?}", bar);
@@ -118,7 +118,7 @@ When used on a function in a trait declaration, then the behavior also applies w
118
118
119
119
```rust
120
120
traitTrait {
121
-
#[must_not_await]
121
+
#[must_not_suspend]
122
122
fnfoo(&self) ->i32;
123
123
}
124
124
@@ -152,10 +152,10 @@ When used on a function in a trait implementation, the attribute does nothing.
152
152
Going through the prior are we see two systems currently which provide simailar/semantically similar behavior:
153
153
154
154
## Clippy `await_holding_lock` lint
155
-
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_await]` 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_await]` type inside of it.
155
+
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.
156
156
157
157
## `#[must_use]` attribute
158
-
The `#[must_use]` attribute ensures that if a type or the result of a function is not used, a warning is displayed. This ensures that the user is notified about the importance of said value. Currently the attribute does not automatically get applied to any type which contains a type declared as `#[must_use]`, but the implementation for both `#[must_not_await]` and `#[must_use]` should be similar in their behavior.
158
+
The `#[must_use]` attribute ensures that if a type or the result of a function is not used, a warning is displayed. This ensures that the user is notified about the importance of said value. Currently the attribute does not automatically get applied to any type which contains a type declared as `#[must_use]`, but the implementation for both `#[must_not_suspend]` and `#[must_use]` should be similar in their behavior.
159
159
160
160
### Auto trait vs attribute
161
161
`#[must_use]` is implemented as an attribute, and from prior art and [other literature][linear-types], we can gather that the decision was made due to the complexity of implementing true linear types in Rust. [`std::panic::UnwindSafe`][UnwindSafe] on the other hand is implemented as a marker trait with structural composition.
@@ -175,7 +175,7 @@ The `#[must_use]` attribute ensures that if a type or the result of a function i
175
175
176
176
# Common behavior with `#[must_use]` lint
177
177
178
-
Both `#[must_use]` and `#[must_not_await]` are [`warn-by-default`] lints, and are applied to types decorated with the attribute. Currently the `#[must_use]` lint does not automatically propagate the lint in nested structures/enums due to the additional complexity that it adds on top of the possible breaking changes introduced in the wider ecosystem
178
+
Both `#[must_use]` and `#[must_not_suspend]` are [`warn-by-default`] lints, and are applied to types decorated with the attribute. Currently the `#[must_use]` lint does not automatically propagate the lint in nested structures/enums due to the additional complexity that it adds on top of the possible breaking changes introduced in the wider ecosystem
179
179
180
180
Automatically propagating the lint for types containing a type marked by one of these attributes would make for a more ergonomic user experience, and would reduce syntactic noise.
0 commit comments