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

fix(serde_conv): allow clippy::ptr_arg #729

Closed
wants to merge 1 commit into from

Conversation

mkroening
Copy link
Contributor

This is #320 again after the allow was removed in f3892d0.

This is the offending code that I have:

serde_with::serde_conv!(
    pub StringAsHtml,
    String,
    |string: &str| html_escape::encode_text(string).into_owned(),
    |html: String| -> Result<_, Infallible> {
        match html_escape::decode_html_entities(&html) {
            Cow::Owned(string) => Ok(string),
            Cow::Borrowed(_) => Ok(html),
        }
    }
);

This results in:

warning: writing `&String` instead of `&str` involves a new object where a slice will do
   --> serde_with/serde_with/src/serde_conv.rs:116:41
    |
107 |   macro_rules! serde_conv {
    |   ----------------------- in this expansion of `serde_with::serde_conv!`
...
116 |                   $vis fn serialize<S>(x: &$t, serializer: S) -> $crate::__private__::Result<S::Ok, S::Error>
    |                                           ^^^
    |
   ::: src/serde.rs:31:1
    |
31  | / serde_with::serde_conv!(
32  | |     pub StringAsHtml,
33  | |     String,
34  | |     |string: &str| html_escape::encode_text(string).into_owned(),
...   |
40  | |     }
41  | | );
    | |_- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
    = note: `#[warn(clippy::ptr_arg)]` on by default

I am not sure if there is a way to resolve the issue on my end.
What do you think?

Copy link

codecov bot commented Apr 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.49%. Comparing base (f4145e3) to head (4a5a4ab).
Report is 10 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #729   +/-   ##
=======================================
  Coverage   66.49%   66.49%           
=======================================
  Files          38       38           
  Lines        2468     2468           
=======================================
  Hits         1641     1641           
  Misses        827      827           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonasbb
Copy link
Owner

jonasbb commented Apr 17, 2024

Sorry that it regressed. I added a test in #731 such that it hopefully doesn't regress anymore.

@jonasbb jonasbb closed this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants