Skip to content

Commit 53d1e44

Browse files
Bhargav Voletinikomatsakis
authored andcommitted
Rename feature to must_not_suspend
1 parent 6b14ce9 commit 53d1e44

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

text/0000-must-not-await-lint.md renamed to text/0000-must-not-suspend-lint.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
- Feature Name: `must_not_await_lint`
1+
- Feature Name: `must_not_suspend_lint`
22
- Start Date: 2020-11-09
33
- RFC PR: [rust-lang/rfcs#3014](https://github.com/rust-lang/rfcs/pull/3014)
44
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)
55

66
# Summary
77
[summary]: #summary
88

9-
Introduce a `#[must_not_await]` lint in the compiler that will warn the user when they are incorrectly holding a struct across an await boundary.
9+
Introduce a `#[must_not_suspend]` lint in the compiler that will warn the user when they are incorrectly holding a struct across an await boundary.
1010

1111
# Motivation
1212
[motivation]: #motivation
@@ -23,7 +23,7 @@ The big reason for including a lint like this is because under the hood the comp
2323
Provide a lint that can be attached to structs to let the compiler know that this struct can not be held across an await boundary.
2424

2525
```rust
26-
#[must_not_await = "Your error message here"]
26+
#[must_not_suspend = "Your error message here"]
2727
struct MyStruct {}
2828
```
2929

@@ -63,15 +63,15 @@ This will be a best effort lint to signal the user about unintended side-effects
6363
# Reference-level explanation
6464
[reference-level-explanation]: #reference-level-explanation
6565

66-
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.
6767

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.
6969

7070
When used on a user-defined composite type, if a value exists across an await point, then this lint is violated.
7171

7272

7373
```rust
74-
#[must_not_await = "Your error message here"]
74+
#[must_not_suspend = "Your error message here"]
7575
struct MyStruct {}
7676

7777
async fn foo() {
@@ -84,7 +84,7 @@ async fn foo() {
8484
When used on a function, if the value returned by a function is held across an await point, this lint is violated.
8585

8686
```rust
87-
#[must_not_await]
87+
#[must_not_suspend]
8888
fn foo() -> i32 { 5i32 }
8989

9090
async fn foo() {
@@ -97,7 +97,7 @@ async fn foo() {
9797
When used on a [trait declaration], if the value implementing that trait is held across an await point, the lint is violated.
9898

9999
```rust
100-
#[must_not_await]
100+
#[must_not_suspend]
101101
trait Lock {
102102
fn foo(&self) -> i32;
103103
}
@@ -107,7 +107,7 @@ fn get_lock() -> impl Lock {
107107
}
108108

109109
async fn foo() {
110-
// violates the #[must_not_await] lint
110+
// violates the #[must_not_suspend] lint
111111
let bar = get_lock();
112112
my_async_op.await;
113113
println!("{:?}", bar);
@@ -118,7 +118,7 @@ When used on a function in a trait declaration, then the behavior also applies w
118118

119119
```rust
120120
trait Trait {
121-
#[must_not_await]
121+
#[must_not_suspend]
122122
fn foo(&self) -> i32;
123123
}
124124

@@ -152,10 +152,10 @@ When used on a function in a trait implementation, the attribute does nothing.
152152
Going through the prior are we see two systems currently which provide simailar/semantically similar behavior:
153153

154154
## 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.
156156

157157
## `#[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.
159159

160160
### Auto trait vs attribute
161161
`#[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
175175

176176
# Common behavior with `#[must_use]` lint
177177

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
179179

180180
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.
181181

0 commit comments

Comments
 (0)