Skip to content

unused_qualifications lint does not work on import path prefix #100979

Closed
@teckick

Description

@teckick

unused_qualifications lint does not work on import path prefix.

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::Success;
    let resp = status::Resp{status: st};
    match resp.status() {
        status::StatusCode::Success => {Ok(())} // expect a warn but not
        status::StatusCode::NotFound => {Ok(())} // expect a warn but not
    }
}
// status.rs

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

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

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

I expected to see this happen: explanation

error: unnecessary qualification
  --> src/main.rs:13:9
   |
13 |         status::StatusCode::Success => {Ok(())}
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Instead, this happened: explanation

no error

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (addacb587 2022-08-24)
binary: rustc
commit-hash: addacb5878b9970ebc1665768a05cb601e7aea15
commit-date: 2022-08-24
host: x86_64-apple-darwin
release: 1.65.0-nightly
LLVM version: 15.0.0

However, the code is warned in Clion with Rust plugin (version 0.4.176.4815-222):

image

https://blog.jetbrains.com/rust/2022/05/19/what-s-new-in-intellij-rust-for-2022-1/#The_Unnecessarily_qualified_path_inspection

Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions