forked from google/tarpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotate types that impl Future with #[must_use].
These types do nothing unless polled / .awaited. Annotating them with #[must_use] helps prevent a common class of coding errors. Fixes google#368.
- Loading branch information
Showing
12 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use tarpc::client; | ||
|
||
#[tarpc::service] | ||
trait World { | ||
async fn hello(name: String) -> String; | ||
} | ||
|
||
fn main() { | ||
let (client_transport, _) = tarpc::transport::channel::unbounded(); | ||
|
||
#[deny(unused_must_use)] | ||
{ | ||
WorldClient::new(client::Config::default(), client_transport).dispatch; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: unused `RequestDispatch` that must be used | ||
--> tests/compile_fail/must_use_request_dispatch.rs:13:9 | ||
| | ||
13 | WorldClient::new(client::Config::default(), client_transport).dispatch; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> tests/compile_fail/must_use_request_dispatch.rs:11:12 | ||
| | ||
11 | #[deny(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ |
9 changes: 9 additions & 0 deletions
9
tarpc/tests/compile_fail/serde_transport/must_use_tcp_connect.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use tarpc::serde_transport; | ||
use tokio_serde::formats::Json; | ||
|
||
fn main() { | ||
#[deny(unused_must_use)] | ||
{ | ||
serde_transport::tcp::connect::<_, (), (), _, _>("0.0.0.0:0", Json::default); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tarpc/tests/compile_fail/serde_transport/must_use_tcp_connect.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: unused `Connect` that must be used | ||
--> tests/compile_fail/serde_transport/must_use_tcp_connect.rs:7:9 | ||
| | ||
7 | serde_transport::tcp::connect::<_, (), (), _, _>("0.0.0.0:0", Json::default); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> tests/compile_fail/serde_transport/must_use_tcp_connect.rs:5:12 | ||
| | ||
5 | #[deny(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ |
29 changes: 29 additions & 0 deletions
29
tarpc/tests/compile_fail/tokio/must_use_channel_executor.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use tarpc::{ | ||
context, | ||
server::{self, Channel}, | ||
}; | ||
|
||
#[tarpc::service] | ||
trait World { | ||
async fn hello(name: String) -> String; | ||
} | ||
|
||
#[derive(Clone)] | ||
struct HelloServer; | ||
|
||
#[tarpc::server] | ||
impl World for HelloServer { | ||
async fn hello(self, _: context::Context, name: String) -> String { | ||
format!("Hello, {name}!") | ||
} | ||
} | ||
|
||
fn main() { | ||
let (_, server_transport) = tarpc::transport::channel::unbounded(); | ||
let server = server::BaseChannel::with_defaults(server_transport); | ||
|
||
#[deny(unused_must_use)] | ||
{ | ||
server.execute(HelloServer.serve()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tarpc/tests/compile_fail/tokio/must_use_channel_executor.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: unused `TokioChannelExecutor` that must be used | ||
--> tests/compile_fail/tokio/must_use_channel_executor.rs:27:9 | ||
| | ||
27 | server.execute(HelloServer.serve()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> tests/compile_fail/tokio/must_use_channel_executor.rs:25:12 | ||
| | ||
25 | #[deny(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ |
30 changes: 30 additions & 0 deletions
30
tarpc/tests/compile_fail/tokio/must_use_server_executor.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use futures::stream::once; | ||
use tarpc::{ | ||
context, | ||
server::{self, incoming::Incoming}, | ||
}; | ||
|
||
#[tarpc::service] | ||
trait World { | ||
async fn hello(name: String) -> String; | ||
} | ||
|
||
#[derive(Clone)] | ||
struct HelloServer; | ||
|
||
#[tarpc::server] | ||
impl World for HelloServer { | ||
async fn hello(self, _: context::Context, name: String) -> String { | ||
format!("Hello, {name}!") | ||
} | ||
} | ||
|
||
fn main() { | ||
let (_, server_transport) = tarpc::transport::channel::unbounded(); | ||
let server = once(async move { server::BaseChannel::with_defaults(server_transport) }); | ||
|
||
#[deny(unused_must_use)] | ||
{ | ||
server.execute(HelloServer.serve()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tarpc/tests/compile_fail/tokio/must_use_server_executor.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: unused `TokioServerExecutor` that must be used | ||
--> tests/compile_fail/tokio/must_use_server_executor.rs:28:9 | ||
| | ||
28 | server.execute(HelloServer.serve()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> tests/compile_fail/tokio/must_use_server_executor.rs:26:12 | ||
| | ||
26 | #[deny(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ |