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

#[allow(clippy::option_option)] not working when paired with #[serde(deserialize_with)] #4298

Closed
schungx opened this issue Jul 24, 2019 · 6 comments · Fixed by #6303
Closed
Labels
E-needs-test Call for participation: writing tests good-first-issue These issues are a good way to get started with Clippy T-macros Type: Issues with macros and macro expansion

Comments

@schungx
Copy link

schungx commented Jul 24, 2019

Using: VS Code with RLS, Windows

This produces clippy warning on option_option:

    #[allow(clippy::option_option)]
    #[serde(deserialize_with = "func")]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    #[serde(borrow)]
    foo: Option<Option<Cow<'a, str>>>,
consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases.

However, removing #[serde(deserialize_with ... )] makes it work:

    #[allow(clippy::option_option)]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    #[serde(borrow)]
    foo: Option<Option<Cow<'a, str>>>,

I suspect #[serde(serialize_with ...)] will also trip up this feature. So something about serde's serialize_with and deserialize_with attributes conflict with option_option.

@schungx schungx changed the title option_option not working when paired with certain #[serde(deserialize_with)] option_option not working when paired with #[serde(deserialize_with)] Jul 24, 2019
@schungx schungx changed the title option_option not working when paired with #[serde(deserialize_with)] #[allow(clippy::option_option)] not working when paired with #[serde(deserialize_with)] Jul 24, 2019
@flip1995
Copy link
Member

Minimal reproducer:

use serde::{Deserialize, Deserializer, Serialize}; // 1.0.94
use std::borrow::Cow;

#[derive(Serialize, Deserialize)]
struct Foo<'a> {
    #[allow(clippy::option_option)]
    #[serde(deserialize_with = "func")]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    #[serde(borrow)]
    foo: Option<Option<Cow<'a, str>>>,
}

#[allow(clippy::option_option)]
fn func<'a, D>(_: D) -> Result<Option<Option<Cow<'a, str>>>, D::Error>
where
    D: Deserializer<'a>,
{
    Ok(Some(Some(Cow::Borrowed("hi"))))
}

fn main() {}

Playground

The warning messages are because of the expansion of deserialize_with. This probably just needs a macro check.

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy T-macros Type: Issues with macros and macro expansion C-bug Category: Clippy is not doing the correct thing labels Jul 25, 2019
@tnielens
Copy link
Contributor

Seems to be fixed, @flip1995 reproduction example does not trigger any lint.

@flip1995 flip1995 added E-needs-test Call for participation: writing tests and removed C-bug Category: Clippy is not doing the correct thing labels May 21, 2020
@schungx
Copy link
Author

schungx commented May 22, 2020

Seems to be fixed

Yes, it looks like it fixed itself a while ago.

Closing this one.

@schungx schungx closed this as completed May 22, 2020
tnielens added a commit to tnielens/rust-clippy that referenced this issue May 22, 2020
@tnielens
Copy link
Contributor

The uitest suite on this test case still triggers incorrectly. Maybe a serde version difference? This issue could stay open.

tnielens added a commit to tnielens/rust-clippy that referenced this issue May 22, 2020
@schungx schungx reopened this May 23, 2020
bors added a commit that referenced this issue May 25, 2020
…1995

option_option test case #4298

Adds regression test case for #4298.

The bug seems still present although rust Playground said otherwise.
bors added a commit that referenced this issue May 25, 2020
…1995

option_option test case #4298

Adds regression test case for #4298.

The bug seems still present although rust Playground said otherwise.

changelog: none
@ThibsG
Copy link
Contributor

ThibsG commented Oct 30, 2020

@montrivo, do you remember if the error was triggering only in CI or also locally?
I don't get the error locally by removing #[allow(clippy::option_option)].

@tnielens
Copy link
Contributor

I don't remember anymore.

bors added a commit that referenced this issue Nov 10, 2020
Remove `allow` in `option_option` lint test

As it is not triggering locally anymore, I propose to remove `#[allow(clippy::option_option)]` from the test.

The goal is also to see what happens on CI.

closes: #4298

changelog: none
@bors bors closed this as completed in d0858d0 Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: writing tests good-first-issue These issues are a good way to get started with Clippy T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants