Skip to content

Commit

Permalink
Add test that serde_conv will not trigger clippy::ptr_arg
Browse files Browse the repository at this point in the history
Relates to #320 #729
  • Loading branch information
jonasbb committed Apr 17, 2024
1 parent 57e4ee2 commit 754c081
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions serde_with/src/serde_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ macro_rules! serde_conv {
#[allow(non_camel_case_types)]
$vis struct $m;

// Prevent clippy lints triggering because of the template here
// https://github.com/jonasbb/serde_with/pull/320
// https://github.com/jonasbb/serde_with/pull/729
#[allow(clippy::all)]
const _:() = {
impl $m {
$vis fn serialize<S>(x: &$t, serializer: S) -> $crate::__private__::Result<S::Ok, S::Error>
Expand Down
13 changes: 13 additions & 0 deletions serde_with_test/tests/serde_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ fn string_to_u32(
#[derive(::s::Serialize, ::s::Deserialize)]
#[serde(crate = "::s")]
struct S2(#[serde(with = "number")] u32);

// Test for clippy warning clippy::ptr_arg
// warning: writing `&String` instead of `&str` involves a new object where a slice will do
// https://github.com/jonasbb/serde_with/pull/320
// https://github.com/jonasbb/serde_with/pull/729
serde_conv!(
pub StringAsHtml,
::std::string::String,
|string: &str| ::std::borrow::ToOwned::to_owned(string),
|string: ::std::string::String| -> ::std::result::Result<_, ::std::convert::Infallible> {
::std::result::Result::Ok(string)
}
);

0 comments on commit 754c081

Please sign in to comment.