Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test that serde_conv will not trigger clippy::ptr_arg #731

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}
);