From 11179b8033ba7fbca3c3e1dfc34b982714f82ce8 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Mon, 27 Jun 2022 20:57:02 +0200 Subject: [PATCH] Silence "unnecessary use of `to_string`" lint for `#[derive(TypedPath)]` (#1117) * Fix "unnecessary use of `to_string`" lint for `#[derive(TypedPath)]` * changelog * Update axum-macros/CHANGELOG.md --- axum-macros/CHANGELOG.md | 2 ++ axum-macros/src/typed_path.rs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/axum-macros/CHANGELOG.md b/axum-macros/CHANGELOG.md index 8e14b8ab..11235273 100644 --- a/axum-macros/CHANGELOG.md +++ b/axum-macros/CHANGELOG.md @@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased - **change:** axum's MSRV is now 1.56 ([#1098]) +- **fixed:** Silence "unnecessary use of `to_string`" lint for `#[derive(TypedPath)]` ([#1117]) [#1098]: https://github.com/tokio-rs/axum/pull/1098 +[#1117]: https://github.com/tokio-rs/axum/pull/1117 # 0.2.2 (18. May, 2022) diff --git a/axum-macros/src/typed_path.rs b/axum-macros/src/typed_path.rs index 3caeb0bd..a7654371 100644 --- a/axum-macros/src/typed_path.rs +++ b/axum-macros/src/typed_path.rs @@ -104,12 +104,18 @@ fn expand_named_fields( let display_impl = quote_spanned! {path.span()=> #[automatically_derived] impl ::std::fmt::Display for #ident { + #[allow(clippy::unnecessary_to_owned)] fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { let Self { #(#captures,)* } = self; write!( f, #format_str, - #(#captures = ::axum_extra::__private::utf8_percent_encode(&#captures.to_string(), ::axum_extra::__private::PATH_SEGMENT)),* + #( + #captures = ::axum_extra::__private::utf8_percent_encode( + &#captures.to_string(), + ::axum_extra::__private::PATH_SEGMENT, + ) + ),* ) } } @@ -200,12 +206,18 @@ fn expand_unnamed_fields( let display_impl = quote_spanned! {path.span()=> #[automatically_derived] impl ::std::fmt::Display for #ident { + #[allow(clippy::unnecessary_to_owned)] fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { let Self { #(#destructure_self)* } = self; write!( f, #format_str, - #(#captures = ::axum_extra::__private::utf8_percent_encode(&#captures.to_string(), ::axum_extra::__private::PATH_SEGMENT)),* + #( + #captures = ::axum_extra::__private::utf8_percent_encode( + &#captures.to_string(), + ::axum_extra::__private::PATH_SEGMENT, + ) + ),* ) } }