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

unused_qualifications lint does not work on import path prefix #100979

Closed
teckick opened this issue Aug 25, 2022 · 1 comment · Fixed by #121528
Closed

unused_qualifications lint does not work on import path prefix #100979

teckick opened this issue Aug 25, 2022 · 1 comment · Fixed by #121528
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@teckick
Copy link

teckick commented Aug 25, 2022

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>

@kpreid
Copy link
Contributor

kpreid commented Dec 15, 2023

I think I just ran into this issue. Here is an reduced example which does not lint even though I expect it to:

#![deny(unused_qualifications)]
use core::fmt;
fn foo() -> core::fmt::Result {  // should be linted because it is not fmt::Result
    Ok(())
}

@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage-legacy labels Jan 26, 2024
@bors bors closed this as completed in ed6d175 Mar 4, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 4, 2024
Rollup merge of rust-lang#121528 - Alexendoo:unused_qualifications, r=petrochenkov

Consider middle segments of paths in `unused_qualifications`

Currently `unused_qualifications` looks at the last segment of a path to see if it can be trimmed, this PR extends the check to the middle segments also

```rust
// currently linted
use std::env::args();
std::env::args(); // Removes `std::env::`
```
```rust
// newly linted
use std::env;
std::env::args(); // Removes `std::`
```

Paths with generics in them are now linted as long as the part being trimmed is before any generic args, e.g. it will now suggest trimming `std::vec::` from `std::vec::Vec<usize>`

Paths with any segments that are from an expansion are no longer linted

Fixes rust-lang#100979
Fixes rust-lang#96698
@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants