diff --git a/axum-core/CHANGELOG.md b/axum-core/CHANGELOG.md index 2202a061..7abc92c6 100644 --- a/axum-core/CHANGELOG.md +++ b/axum-core/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased -- None. +- **fixed:** Add `#[must_use]` attributes to types that do nothing unless used ([#1809]) + +[#1809]: https://github.com/tokio-rs/axum/pull/1809 # 0.3.2 (20. January, 2023) diff --git a/axum-core/src/extract/default_body_limit.rs b/axum-core/src/extract/default_body_limit.rs index 48ed5a7b..26891548 100644 --- a/axum-core/src/extract/default_body_limit.rs +++ b/axum-core/src/extract/default_body_limit.rs @@ -73,6 +73,7 @@ use tower_layer::Layer; /// [`RequestExt::with_limited_body`]: crate::RequestExt::with_limited_body /// [`RequestExt::into_limited_body`]: crate::RequestExt::into_limited_body #[derive(Debug, Clone)] +#[must_use] pub struct DefaultBodyLimit { kind: DefaultBodyLimitKind, } diff --git a/axum-core/src/response/append_headers.rs b/axum-core/src/response/append_headers.rs index 4f1ae964..e4ac4812 100644 --- a/axum-core/src/response/append_headers.rs +++ b/axum-core/src/response/append_headers.rs @@ -30,6 +30,7 @@ use std::fmt; /// } /// ``` #[derive(Debug)] +#[must_use] pub struct AppendHeaders(pub I); impl IntoResponse for AppendHeaders diff --git a/axum-extra/CHANGELOG.md b/axum-extra/CHANGELOG.md index 0ca46010..1160edaa 100644 --- a/axum-extra/CHANGELOG.md +++ b/axum-extra/CHANGELOG.md @@ -9,11 +9,13 @@ and this project adheres to [Semantic Versioning]. - **added:** Add `Multipart`. This is similar to `axum::extract::Multipart` except that it enforces field exclusivity at runtime instead of compile time, - as this improves usability. - + as this improves usability ([#1692]) - **added:** Implement `Clone` for `CookieJar`, `PrivateCookieJar` and `SignedCookieJar` ([#1808]) +- **fixed:** Add `#[must_use]` attributes to types that do nothing unless used ([#1809]) +[#1692]: https://github.com/tokio-rs/axum/pull/1692 [#1808]: https://github.com/tokio-rs/axum/pull/1808 +[#1809]: https://github.com/tokio-rs/axum/pull/1809 # 0.6.0 (24. February, 2022) diff --git a/axum-extra/src/body/async_read_body.rs b/axum-extra/src/body/async_read_body.rs index 6e66f0df..5ea0fc59 100644 --- a/axum-extra/src/body/async_read_body.rs +++ b/axum-extra/src/body/async_read_body.rs @@ -46,6 +46,7 @@ pin_project! { /// ``` #[cfg(feature = "async-read-body")] #[derive(Debug)] + #[must_use] pub struct AsyncReadBody { #[pin] read: StreamBody>, diff --git a/axum-extra/src/either.rs b/axum-extra/src/either.rs index 73c3412b..2742debb 100755 --- a/axum-extra/src/either.rs +++ b/axum-extra/src/either.rs @@ -108,6 +108,7 @@ use tower_service::Service; /// /// See the [module docs](self) for examples. #[derive(Debug, Clone)] +#[must_use] pub enum Either { #[allow(missing_docs)] E1(E1), @@ -119,6 +120,7 @@ pub enum Either { /// /// See the [module docs](self) for examples. #[derive(Debug, Clone)] +#[must_use] pub enum Either3 { #[allow(missing_docs)] E1(E1), @@ -132,6 +134,7 @@ pub enum Either3 { /// /// See the [module docs](self) for examples. #[derive(Debug, Clone)] +#[must_use] pub enum Either4 { #[allow(missing_docs)] E1(E1), @@ -147,6 +150,7 @@ pub enum Either4 { /// /// See the [module docs](self) for examples. #[derive(Debug, Clone)] +#[must_use] pub enum Either5 { #[allow(missing_docs)] E1(E1), @@ -164,6 +168,7 @@ pub enum Either5 { /// /// See the [module docs](self) for examples. #[derive(Debug, Clone)] +#[must_use] pub enum Either6 { #[allow(missing_docs)] E1(E1), @@ -183,6 +188,7 @@ pub enum Either6 { /// /// See the [module docs](self) for examples. #[derive(Debug, Clone)] +#[must_use] pub enum Either7 { #[allow(missing_docs)] E1(E1), @@ -204,6 +210,7 @@ pub enum Either7 { /// /// See the [module docs](self) for examples. #[derive(Debug, Clone)] +#[must_use] pub enum Either8 { #[allow(missing_docs)] E1(E1), diff --git a/axum-extra/src/json_lines.rs b/axum-extra/src/json_lines.rs index 83336311..99244287 100644 --- a/axum-extra/src/json_lines.rs +++ b/axum-extra/src/json_lines.rs @@ -58,6 +58,7 @@ pin_project! { /// ``` // we use `AsExtractor` as the default because you're more likely to name this type if its used // as an extractor + #[must_use] pub struct JsonLines { #[pin] inner: Inner, diff --git a/axum-extra/src/protobuf.rs b/axum-extra/src/protobuf.rs index 6748dc82..6da01175 100644 --- a/axum-extra/src/protobuf.rs +++ b/axum-extra/src/protobuf.rs @@ -94,6 +94,7 @@ use std::ops::{Deref, DerefMut}; /// ``` #[derive(Debug, Clone, Copy, Default)] #[cfg_attr(docsrs, doc(cfg(feature = "protobuf")))] +#[must_use] pub struct Protobuf(pub T); #[async_trait] diff --git a/axum-extra/src/response/erased_json.rs b/axum-extra/src/response/erased_json.rs index c61d3145..df7257c5 100644 --- a/axum-extra/src/response/erased_json.rs +++ b/axum-extra/src/response/erased_json.rs @@ -30,6 +30,7 @@ use serde::Serialize; /// ``` #[cfg_attr(docsrs, doc(cfg(feature = "erased-json")))] #[derive(Debug)] +#[must_use] pub struct ErasedJson(serde_json::Result); impl ErasedJson { diff --git a/axum-extra/src/routing/resource.rs b/axum-extra/src/routing/resource.rs index 11f49d22..a4d350bb 100644 --- a/axum-extra/src/routing/resource.rs +++ b/axum-extra/src/routing/resource.rs @@ -33,6 +33,7 @@ use axum::{ /// # let _: Router = app; /// ``` #[derive(Debug)] +#[must_use] pub struct Resource { pub(crate) name: String, pub(crate) router: Router, diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 089f8473..5e6734c8 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -7,12 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased +- **fixed:** Add `#[must_use]` attributes to types that do nothing unless used ([#1809]) - **fixed:** Add `#[must_use]` to `WebSocketUpgrade::on_upgrade` ([#1801]) - **fixed:** Fix routing issues when loading a `Router` via a dynamic library ([#1806]) -[#1806]: https://github.com/tokio-rs/axum/pull/1806 - [#1801]: https://github.com/tokio-rs/axum/pull/1801 +[#1806]: https://github.com/tokio-rs/axum/pull/1806 +[#1809]: https://github.com/tokio-rs/axum/pull/1809 # 0.6.9 (24. February, 2023) diff --git a/axum/src/body/stream_body.rs b/axum/src/body/stream_body.rs index 3d83ef56..6ad2f695 100644 --- a/axum/src/body/stream_body.rs +++ b/axum/src/body/stream_body.rs @@ -52,6 +52,7 @@ pin_project! { /// ``` /// /// [`Stream`]: futures_util::stream::Stream + #[must_use] pub struct StreamBody { #[pin] stream: SyncWrapper, diff --git a/axum/src/extension.rs b/axum/src/extension.rs index 575d62ca..5f94cd69 100644 --- a/axum/src/extension.rs +++ b/axum/src/extension.rs @@ -70,6 +70,7 @@ use tower_service::Service; /// struct Foo(&'static str); /// ``` #[derive(Debug, Clone, Copy, Default)] +#[must_use] pub struct Extension(pub T); #[async_trait] diff --git a/axum/src/form.rs b/axum/src/form.rs index 11412081..5318dd01 100644 --- a/axum/src/form.rs +++ b/axum/src/form.rs @@ -61,6 +61,7 @@ use std::ops::Deref; /// [`Multipart`]: crate::extract::Multipart #[cfg_attr(docsrs, doc(cfg(feature = "form")))] #[derive(Debug, Clone, Copy, Default)] +#[must_use] pub struct Form(pub T); #[async_trait] diff --git a/axum/src/json.rs b/axum/src/json.rs index 27325e86..e6d8588c 100644 --- a/axum/src/json.rs +++ b/axum/src/json.rs @@ -97,6 +97,7 @@ use std::ops::{Deref, DerefMut}; /// ``` #[derive(Debug, Clone, Copy, Default)] #[cfg_attr(docsrs, doc(cfg(feature = "json")))] +#[must_use] pub struct Json(pub T); #[async_trait] diff --git a/axum/src/middleware/from_extractor.rs b/axum/src/middleware/from_extractor.rs index e704ba11..8c9a2483 100644 --- a/axum/src/middleware/from_extractor.rs +++ b/axum/src/middleware/from_extractor.rs @@ -110,6 +110,7 @@ pub fn from_extractor_with_state(state: S) -> FromExtractorLayer { /// See [`from_extractor`] for more details. /// /// [`Layer`]: tower::Layer +#[must_use] pub struct FromExtractorLayer { state: S, _marker: PhantomData E>, diff --git a/axum/src/middleware/from_fn.rs b/axum/src/middleware/from_fn.rs index 28686504..f380a580 100644 --- a/axum/src/middleware/from_fn.rs +++ b/axum/src/middleware/from_fn.rs @@ -161,6 +161,7 @@ pub fn from_fn_with_state(state: S, f: F) -> FromFnLayer { /// [`tower::Layer`] is used to apply middleware to [`Router`](crate::Router)'s. /// /// Created with [`from_fn`]. See that function for more details. +#[must_use] pub struct FromFnLayer { f: F, state: S, diff --git a/axum/src/middleware/map_request.rs b/axum/src/middleware/map_request.rs index d6aa64a5..5d1801ac 100644 --- a/axum/src/middleware/map_request.rs +++ b/axum/src/middleware/map_request.rs @@ -165,6 +165,7 @@ pub fn map_request_with_state(state: S, f: F) -> MapRequestLayer { f: F, state: S, diff --git a/axum/src/middleware/map_response.rs b/axum/src/middleware/map_response.rs index 73b759c3..06f98257 100644 --- a/axum/src/middleware/map_response.rs +++ b/axum/src/middleware/map_response.rs @@ -149,6 +149,7 @@ pub fn map_response_with_state(state: S, f: F) -> MapResponseLayer { f: F, state: S, diff --git a/axum/src/response/mod.rs b/axum/src/response/mod.rs index 393885c4..2c149748 100644 --- a/axum/src/response/mod.rs +++ b/axum/src/response/mod.rs @@ -39,6 +39,7 @@ pub use sse::Sse; /// /// Will automatically get `Content-Type: text/html`. #[derive(Clone, Copy, Debug)] +#[must_use] pub struct Html(pub T); impl IntoResponse for Html @@ -98,7 +99,7 @@ mod tests { } } - Router::<(), Body>::new() + _ = Router::<(), Body>::new() .route("/", get(impl_trait_ok)) .route("/", get(impl_trait_err)) .route("/", get(impl_trait_both)) @@ -208,7 +209,7 @@ mod tests { ) } - Router::<(), Body>::new() + _ = Router::<(), Body>::new() .route("/", get(status)) .route("/", get(status_headermap)) .route("/", get(status_header_array)) diff --git a/axum/src/response/sse.rs b/axum/src/response/sse.rs index 3ae691f8..bbe2c5f2 100644 --- a/axum/src/response/sse.rs +++ b/axum/src/response/sse.rs @@ -53,6 +53,7 @@ use tokio::time::Sleep; /// An SSE response #[derive(Clone)] +#[must_use] pub struct Sse { stream: S, keep_alive: Option, @@ -163,6 +164,7 @@ where /// Server-sent event #[derive(Debug, Default, Clone)] +#[must_use] pub struct Event { buffer: BytesMut, flags: EventFlags, @@ -383,6 +385,7 @@ bitflags::bitflags! { /// Configure the interval between keep-alive messages, the content /// of each message, and the associated stream. #[derive(Debug, Clone)] +#[must_use] pub struct KeepAlive { event: Bytes, max_interval: Duration, diff --git a/axum/src/routing/method_routing.rs b/axum/src/routing/method_routing.rs index 6db9dba5..cd942902 100644 --- a/axum/src/routing/method_routing.rs +++ b/axum/src/routing/method_routing.rs @@ -513,6 +513,7 @@ where /// S: Service>, /// {} /// ``` +#[must_use] pub struct MethodRouter { get: MethodEndpoint, head: MethodEndpoint, diff --git a/axum/src/routing/mod.rs b/axum/src/routing/mod.rs index b13c25bb..0777a511 100644 --- a/axum/src/routing/mod.rs +++ b/axum/src/routing/mod.rs @@ -48,6 +48,7 @@ pub use self::method_routing::{ pub(crate) struct RouteId(u32); /// The router type for composing handlers and services. +#[must_use] pub struct Router { routes: HashMap>, node: Arc, diff --git a/axum/src/routing/tests/mod.rs b/axum/src/routing/tests/mod.rs index fe0eb0da..33770e33 100644 --- a/axum/src/routing/tests/mod.rs +++ b/axum/src/routing/tests/mod.rs @@ -522,7 +522,7 @@ fn routes_with_overlapping_method_routes() { fn merging_with_overlapping_method_routes() { async fn handler() {} let app: Router = Router::new().route("/foo/bar", get(handler)); - app.clone().merge(app); + _ = app.clone().merge(app); } #[crate::test] diff --git a/axum/src/routing/tests/nest.rs b/axum/src/routing/tests/nest.rs index e9129534..e0fb6b6e 100644 --- a/axum/src/routing/tests/nest.rs +++ b/axum/src/routing/tests/nest.rs @@ -257,7 +257,7 @@ async fn multiple_top_level_nests() { #[crate::test] #[should_panic(expected = "Invalid route: nested routes cannot contain wildcards (*)")] async fn nest_cannot_contain_wildcards() { - Router::<(), Body>::new().nest("/one/*rest", Router::new()); + _ = Router::<(), Body>::new().nest("/one/*rest", Router::new()); } #[crate::test] diff --git a/axum/src/typed_header.rs b/axum/src/typed_header.rs index 612cd6a3..c047af74 100644 --- a/axum/src/typed_header.rs +++ b/axum/src/typed_header.rs @@ -50,6 +50,7 @@ use std::{convert::Infallible, ops::Deref}; /// ``` #[cfg(feature = "headers")] #[derive(Debug, Clone, Copy)] +#[must_use] pub struct TypedHeader(pub T); #[async_trait]