Bless clippy.

This commit is contained in:
Camille GILLOT 2023-01-28 23:20:02 +00:00
parent 0a2d39de2e
commit 19e160fe2f
6 changed files with 82 additions and 161 deletions

View file

@ -7,8 +7,10 @@ async fn bad() -> u32 {
} }
async fn bad_reason() -> u32 { async fn bad_reason() -> u32 {
let _x = Ipv4Addr::new(127, 0, 0, 1); let x = Ipv4Addr::new(127, 0, 0, 1);
baz().await let y = baz().await;
let _x = x;
y
} }
async fn good() -> u32 { async fn good() -> u32 {

View file

@ -11,11 +11,11 @@ LL | let _x = String::from("hello");
error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml` error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml`
--> $DIR/await_holding_invalid_type.rs:10:9 --> $DIR/await_holding_invalid_type.rs:10:9
| |
LL | let _x = Ipv4Addr::new(127, 0, 0, 1); LL | let x = Ipv4Addr::new(127, 0, 0, 1);
| ^^ | ^
error: `std::string::String` may not be held across an `await` point per `clippy.toml` error: `std::string::String` may not be held across an `await` point per `clippy.toml`
--> $DIR/await_holding_invalid_type.rs:31:13 --> $DIR/await_holding_invalid_type.rs:33:13
| |
LL | let _x = String::from("hi!"); LL | let _x = String::from("hi!");
| ^^ | ^^

View file

@ -6,13 +6,10 @@ LL | let guard = x.lock().unwrap();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:9:9 --> $DIR/await_holding_lock.rs:11:15
| |
LL | / let guard = x.lock().unwrap(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_____^
= note: `-D clippy::await-holding-lock` implied by `-D warnings` = note: `-D clippy::await-holding-lock` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::await_holding_lock)]` = help: to override `-D warnings` add `#[allow(clippy::await_holding_lock)]`
@ -24,13 +21,10 @@ LL | let guard = x.read().unwrap();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:25:9 --> $DIR/await_holding_lock.rs:27:15
| |
LL | / let guard = x.read().unwrap(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_____^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:31:13 --> $DIR/await_holding_lock.rs:31:13
@ -40,13 +34,10 @@ LL | let mut guard = x.write().unwrap();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:31:9 --> $DIR/await_holding_lock.rs:33:15
| |
LL | / let mut guard = x.write().unwrap(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_____^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:53:13 --> $DIR/await_holding_lock.rs:53:13
@ -56,16 +47,13 @@ LL | let guard = x.lock().unwrap();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:53:9 --> $DIR/await_holding_lock.rs:56:28
| |
LL | / let guard = x.lock().unwrap(); LL | let second = baz().await;
LL | | | ^^^^^
LL | | LL |
LL | | let second = baz().await; LL | let third = baz().await;
... | | ^^^^^
LL | | first + second + third
LL | | }
| |_____^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:67:17 --> $DIR/await_holding_lock.rs:67:17
@ -75,13 +63,10 @@ LL | let guard = x.lock().unwrap();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:67:13 --> $DIR/await_holding_lock.rs:69:19
| |
LL | / let guard = x.lock().unwrap(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | };
| |_________^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:80:17 --> $DIR/await_holding_lock.rs:80:17
@ -91,13 +76,10 @@ LL | let guard = x.lock().unwrap();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:80:13 --> $DIR/await_holding_lock.rs:82:19
| |
LL | / let guard = x.lock().unwrap(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_________^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:93:13 --> $DIR/await_holding_lock.rs:93:13
@ -107,13 +89,10 @@ LL | let guard = x.lock();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:93:9 --> $DIR/await_holding_lock.rs:95:15
| |
LL | / let guard = x.lock(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_____^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:109:13 --> $DIR/await_holding_lock.rs:109:13
@ -123,13 +102,10 @@ LL | let guard = x.read();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:109:9 --> $DIR/await_holding_lock.rs:111:15
| |
LL | / let guard = x.read(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_____^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:115:13 --> $DIR/await_holding_lock.rs:115:13
@ -139,13 +115,10 @@ LL | let mut guard = x.write();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:115:9 --> $DIR/await_holding_lock.rs:117:15
| |
LL | / let mut guard = x.write(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_____^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:137:13 --> $DIR/await_holding_lock.rs:137:13
@ -155,16 +128,13 @@ LL | let guard = x.lock();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:137:9 --> $DIR/await_holding_lock.rs:140:28
| |
LL | / let guard = x.lock(); LL | let second = baz().await;
LL | | | ^^^^^
LL | | LL |
LL | | let second = baz().await; LL | let third = baz().await;
... | | ^^^^^
LL | | first + second + third
LL | | }
| |_____^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:151:17 --> $DIR/await_holding_lock.rs:151:17
@ -174,13 +144,10 @@ LL | let guard = x.lock();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:151:13 --> $DIR/await_holding_lock.rs:153:19
| |
LL | / let guard = x.lock(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | };
| |_________^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:164:17 --> $DIR/await_holding_lock.rs:164:17
@ -190,13 +157,10 @@ LL | let guard = x.lock();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:164:13 --> $DIR/await_holding_lock.rs:166:19
| |
LL | / let guard = x.lock(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_________^
error: this `MutexGuard` is held across an `await` point error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:185:9 --> $DIR/await_holding_lock.rs:185:9
@ -206,15 +170,10 @@ LL | let mut guard = x.lock().unwrap();
| |
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:185:5 --> $DIR/await_holding_lock.rs:189:11
| |
LL | / let mut guard = x.lock().unwrap(); LL | baz().await;
LL | | | ^^^^^
LL | | *guard += 1;
LL | | drop(guard);
LL | | baz().await;
LL | | }
| |_^
error: aborting due to 13 previous errors error: aborting due to 13 previous errors

View file

@ -6,13 +6,10 @@ LL | let b = x.borrow();
| |
= help: ensure the reference is dropped before calling `await` = help: ensure the reference is dropped before calling `await`
note: these are all the `await` points this reference is held through note: these are all the `await` points this reference is held through
--> $DIR/await_holding_refcell_ref.rs:6:5 --> $DIR/await_holding_refcell_ref.rs:8:11
| |
LL | / let b = x.borrow(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_^
= note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings` = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::await_holding_refcell_ref)]` = help: to override `-D warnings` add `#[allow(clippy::await_holding_refcell_ref)]`
@ -24,13 +21,10 @@ LL | let b = x.borrow_mut();
| |
= help: ensure the reference is dropped before calling `await` = help: ensure the reference is dropped before calling `await`
note: these are all the `await` points this reference is held through note: these are all the `await` points this reference is held through
--> $DIR/await_holding_refcell_ref.rs:12:5 --> $DIR/await_holding_refcell_ref.rs:14:11
| |
LL | / let b = x.borrow_mut(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_^
error: this `RefCell` reference is held across an `await` point error: this `RefCell` reference is held across an `await` point
--> $DIR/await_holding_refcell_ref.rs:34:9 --> $DIR/await_holding_refcell_ref.rs:34:9
@ -40,16 +34,13 @@ LL | let b = x.borrow_mut();
| |
= help: ensure the reference is dropped before calling `await` = help: ensure the reference is dropped before calling `await`
note: these are all the `await` points this reference is held through note: these are all the `await` points this reference is held through
--> $DIR/await_holding_refcell_ref.rs:34:5 --> $DIR/await_holding_refcell_ref.rs:37:24
| |
LL | / let b = x.borrow_mut(); LL | let second = baz().await;
LL | | | ^^^^^
LL | | LL |
LL | | let second = baz().await; LL | let third = baz().await;
... | | ^^^^^
LL | | first + second + third
LL | | }
| |_^
error: this `RefCell` reference is held across an `await` point error: this `RefCell` reference is held across an `await` point
--> $DIR/await_holding_refcell_ref.rs:47:9 --> $DIR/await_holding_refcell_ref.rs:47:9
@ -59,16 +50,10 @@ LL | let b = x.borrow_mut();
| |
= help: ensure the reference is dropped before calling `await` = help: ensure the reference is dropped before calling `await`
note: these are all the `await` points this reference is held through note: these are all the `await` points this reference is held through
--> $DIR/await_holding_refcell_ref.rs:47:5 --> $DIR/await_holding_refcell_ref.rs:50:24
| |
LL | / let b = x.borrow_mut(); LL | let second = baz().await;
LL | | | ^^^^^
LL | |
LL | | let second = baz().await;
... |
LL | | first + second + third
LL | | }
| |_^
error: this `RefCell` reference is held across an `await` point error: this `RefCell` reference is held across an `await` point
--> $DIR/await_holding_refcell_ref.rs:63:13 --> $DIR/await_holding_refcell_ref.rs:63:13
@ -78,13 +63,10 @@ LL | let b = x.borrow_mut();
| |
= help: ensure the reference is dropped before calling `await` = help: ensure the reference is dropped before calling `await`
note: these are all the `await` points this reference is held through note: these are all the `await` points this reference is held through
--> $DIR/await_holding_refcell_ref.rs:63:9 --> $DIR/await_holding_refcell_ref.rs:65:15
| |
LL | / let b = x.borrow_mut(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | };
| |_____^
error: this `RefCell` reference is held across an `await` point error: this `RefCell` reference is held across an `await` point
--> $DIR/await_holding_refcell_ref.rs:76:13 --> $DIR/await_holding_refcell_ref.rs:76:13
@ -94,13 +76,10 @@ LL | let b = x.borrow_mut();
| |
= help: ensure the reference is dropped before calling `await` = help: ensure the reference is dropped before calling `await`
note: these are all the `await` points this reference is held through note: these are all the `await` points this reference is held through
--> $DIR/await_holding_refcell_ref.rs:76:9 --> $DIR/await_holding_refcell_ref.rs:78:15
| |
LL | / let b = x.borrow_mut(); LL | baz().await
LL | | | ^^^^^
LL | | baz().await
LL | | }
| |_____^
error: aborting due to 6 previous errors error: aborting due to 6 previous errors

View file

@ -59,6 +59,7 @@ where
{ {
let rt = &t; let rt = &t;
async { true }.await; async { true }.await;
let _ = rt;
t t
} }

View file

@ -12,19 +12,12 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
LL | LL |
LL | async { true }.await LL | async { true }.await
| ^^^^^ await occurs here, with `rc` maybe used later | ^^^^^ await occurs here, with `rc` maybe used later
LL | }
| - `rc` is later dropped here
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send`
note: future is not `Send` as this value is used across an await note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync`
--> $DIR/future_not_send.rs:9:20 --> $DIR/future_not_send.rs:7:39
| |
LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool { LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
| ---- has type `&std::cell::Cell<usize>` which is not `Send` | ^^^^ has type `&std::cell::Cell<usize>` which is not `Send`, because `std::cell::Cell<usize>` is not `Sync`
LL |
LL | async { true }.await
| ^^^^^ await occurs here, with `cell` maybe used later
LL | }
| - `cell` is later dropped here
= note: `std::cell::Cell<usize>` doesn't implement `std::marker::Sync` = note: `std::cell::Cell<usize>` doesn't implement `std::marker::Sync`
= note: `-D clippy::future-not-send` implied by `-D warnings` = note: `-D clippy::future-not-send` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::future_not_send)]` = help: to override `-D warnings` add `#[allow(clippy::future_not_send)]`
@ -43,8 +36,6 @@ LL | pub async fn public_future(rc: Rc<[u8]>) {
LL | LL |
LL | async { true }.await; LL | async { true }.await;
| ^^^^^ await occurs here, with `rc` maybe used later | ^^^^^ await occurs here, with `rc` maybe used later
LL | }
| - `rc` is later dropped here
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send`
error: future cannot be sent between threads safely error: future cannot be sent between threads safely
@ -93,9 +84,6 @@ LL | async fn private_future(&self) -> usize {
LL | LL |
LL | async { true }.await; LL | async { true }.await;
| ^^^^^ await occurs here, with `&self` maybe used later | ^^^^^ await occurs here, with `&self` maybe used later
LL | self.rc.len()
LL | }
| - `&self` is later dropped here
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync`
error: future cannot be sent between threads safely error: future cannot be sent between threads safely
@ -104,16 +92,11 @@ error: future cannot be sent between threads safely
LL | pub async fn public_future(&self) { LL | pub async fn public_future(&self) {
| ^ future returned by `public_future` is not `Send` | ^ future returned by `public_future` is not `Send`
| |
note: future is not `Send` as this value is used across an await note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync`
--> $DIR/future_not_send.rs:46:31 --> $DIR/future_not_send.rs:44:32
| |
LL | pub async fn public_future(&self) { LL | pub async fn public_future(&self) {
| ----- has type `&Dummy` which is not `Send` | ^^^^^ has type `&Dummy` which is not `Send`, because `Dummy` is not `Sync`
LL |
LL | self.private_future().await;
| ^^^^^ await occurs here, with `&self` maybe used later
LL | }
| - `&self` is later dropped here
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync`
error: future cannot be sent between threads safely error: future cannot be sent between threads safely
@ -129,19 +112,16 @@ LL | let rt = &t;
| -- has type `&T` which is not `Send` | -- has type `&T` which is not `Send`
LL | async { true }.await; LL | async { true }.await;
| ^^^^^ await occurs here, with `rt` maybe used later | ^^^^^ await occurs here, with `rt` maybe used later
LL | t
LL | }
| - `rt` is later dropped here
= note: `T` doesn't implement `std::marker::Sync` = note: `T` doesn't implement `std::marker::Sync`
error: future cannot be sent between threads safely error: future cannot be sent between threads safely
--> $DIR/future_not_send.rs:72:34 --> $DIR/future_not_send.rs:73:34
| |
LL | async fn unclear_future<T>(t: T) {} LL | async fn unclear_future<T>(t: T) {}
| ^ future returned by `unclear_future` is not `Send` | ^ future returned by `unclear_future` is not `Send`
| |
note: captured value is not `Send` note: captured value is not `Send`
--> $DIR/future_not_send.rs:72:28 --> $DIR/future_not_send.rs:73:28
| |
LL | async fn unclear_future<T>(t: T) {} LL | async fn unclear_future<T>(t: T) {}
| ^ has type `T` which is not `Send` | ^ has type `T` which is not `Send`