Skip to content

incorrect result of #![deny(unused_qualifications)] in match block #9372

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

Closed
teckick opened this issue Aug 24, 2022 · 3 comments
Closed

incorrect result of #![deny(unused_qualifications)] in match block #9372

teckick opened this issue Aug 24, 2022 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@teckick
Copy link

teckick commented Aug 24, 2022

Summary

#![deny(unused_qualifications)] does not work in match block.

Lint Name

#![deny(unused_qualifications)]

Reproducer

I tried this code:

tree:

|- main.rs
|- status.rs

// main.rs

#![deny(unused_qualifications)]
#![allow(dead_code)]

mod status;

use status::StatusCode;

fn main() -> anyhow::Result<()> {
    let st = StatusCode::Ok;
    let resp = status::Resp{status: st};
    match resp.status() {
        status::StatusCode::Ok => {Ok(())} // lint should warn but not
        status::StatusCode::NotFound => {Ok(())}  // lint should warn but not
    }
}
// status.rs

#[derive(Clone)]
pub enum StatusCode {
    Ok,
    NotFound,
}

pub struct Resp {
    pub(crate) status: StatusCode,
}

impl Resp {
    pub fn status(&self) -> StatusCode {
        self.status.clone()
    }
}

run the following cmd:

cargo clippy

I expected to see this happen:

error: unnecessary qualification

Instead, this happened:

no error

Version

rustc 1.62.1 (e092d0b6b 2022-07-16)
binary: rustc
commit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3
commit-date: 2022-07-16
host: x86_64-apple-darwin
release: 1.62.1
LLVM version: 14.0.5
@teckick teckick added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Aug 24, 2022
@Xuanwo
Copy link

Xuanwo commented Aug 24, 2022

I can't find unused-qualifications in https://rust-lang.github.io/rust-clippy/master/index.html.

I'm guessing it's a rustc lint?

There are some things need to check:

  • Upgrade to 1.63 (the latest stable) to check again.
  • Use cargo +nightly check to check whether this has been resolved nightly.

@giraffate
Copy link
Contributor

The unused_qualifications is the rustc's lint: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/builtin/static.UNUSED_QUALIFICATIONS.html, so it would be better that this issue is moved to rust-lang/rust.

The main.rs bring status::StatusCode in that scope, but it doesn't use status::StatusCode as it is. It uses status::StatusCode::Ok and status::StatusCode::NotFound, so the unused_qualifications lint doesn't fire.

@teckick
Copy link
Author

teckick commented Aug 25, 2022

@giraffate Thanks for answer! I start another issue in rust-lang/rust.

@teckick teckick closed this as completed Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

3 participants