-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add internal lint derive_deserialize_allowing_unknown
#14360
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
base: master
Are you sure you want to change the base?
Add internal lint derive_deserialize_allowing_unknown
#14360
Conversation
Why should that only be an internal lint? I could see it as a restriction lint, with some documentation that anything deserialized from user data should have that attribute. |
@llogiq Thank you very much for your comments.
I had the impression that Clippy preferred to not lint third-party APIs. For example, I recall this comment from 2022: #8434 (review) Granted, the comment called
I think some might disagree (hence, the reason for the optional attribute). But if the lint is allow by default, that might not matter. Please tell me if I should proceed with changing the lint's category. |
This comment has been minimized.
This comment has been minimized.
824d8ea
to
e9d1c4f
Compare
@llogiq Did you have any further thoughts on this lint? |
This comment has been minimized.
This comment has been minimized.
`cargo dev dogfood` fails at this commit. The next commit addresses the errors that are produced.
e9d1c4f
to
60d7fe3
Compare
Adds an internal lint to check for
#[derive(serde::Deserialize)]
without#[serde(deny_unknown_fields)]
.Today, if you run Clippy with the following clippy.toml, Clippy will produce a warning, but there will be no accompanying note:
The underlying problem is: the enum that derives
serde::Deserialize
(DisallowedPathEnum
) does not have the attribute#[serde(deny_unknown_fields)]
.This lint identifies such problems by checking trait
impl
s. An alternative I considered was to walkclippy_config::conf::Conf
directly. However, that would not catch theDisallowedPathEnum
case because it is not used inConf
directly.Just to be clear, no one asked for this. So I hope the maintainers do not mind.
changelog: none