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 clashes with unused_import #121331

Closed
matthiaskrgr opened this issue Feb 20, 2024 · 1 comment · Fixed by #122373
Closed

unused_qualifications clashes with unused_import #121331

matthiaskrgr opened this issue Feb 20, 2024 · 1 comment · Fixed by #122373
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-coroutines `#![feature(coroutines)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 20, 2024

Code

#![warn(unused_qualifications)]
#![feature(coroutines, coroutine_trait)]

use std::ops::{
    Coroutine,
    CoroutineState::{self, *},
};
use std::pin::Pin;

fn finish<T>(mut amt: usize, mut t: T) -> T::Return
    where T: Coroutine<(), Yield = ()> + Unpin,
{
    loop {
        match Pin::new(&mut t).resume(()) {
            CoroutineState::Yielded(()) => amt = amt.checked_sub(1).unwrap(),
            CoroutineState::Complete(ret) => {
                assert_eq!(amt, 0);
                return ret
            }
        }
    }

}

pub fn main() {}

Current output

warning: unused import: `*`
 --> src/main.rs:6:28
  |
6 |     CoroutineState::{self, *},
  |                            ^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unnecessary qualification
  --> src/main.rs:15:13
   |
15 |             CoroutineState::Yielded(()) => amt = amt.checked_sub(1).unwrap(),
   |             ^^^^^^^^^^^^^^^^^^^^^^^
   |
note: the lint level is defined here
  --> src/main.rs:1:9
   |
1  | #![warn(unused_qualifications)]
   |         ^^^^^^^^^^^^^^^^^^^^^
help: remove the unnecessary path segments
   |
15 -             CoroutineState::Yielded(()) => amt = amt.checked_sub(1).unwrap(),
15 +             Yielded(()) => amt = amt.checked_sub(1).unwrap(),
   |

warning: unnecessary qualification
  --> src/main.rs:16:13
   |
16 |             CoroutineState::Complete(ret) => {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: remove the unnecessary path segments
   |
16 -             CoroutineState::Complete(ret) => {
16 +             Complete(ret) => {
   |

Desired output

No response

Rationale and extra context

The suggestion fails to apply with cargo fix

The following errors were reported:
error[E0531]: cannot find tuple struct or tuple variant `Yielded` in this scope
  --> src/main.rs:15:13
   |
15 |             Yielded(()) => amt = amt.checked_sub(1).unwrap(),
   |             ^^^^^^^ not found in this scope
   |
help: consider importing one of these items
   |
4  + use core::ops::CoroutineState::Yielded;
   |
4  + use crate::CoroutineState::Yielded;
   |
4  + use std::ops::CoroutineState::Yielded;
   |

error[E0531]: cannot find tuple struct or tuple variant `Complete` in this scope
  --> src/main.rs:16:13
   |
16 |             Complete(ret) => {
   |             ^^^^^^^^ not found in this scope
   |
help: consider importing one of these items
   |
4  + use core::ops::CoroutineState::Complete;
   |
4  + use crate::CoroutineState::Complete;
   |
4  + use std::ops::CoroutineState::Complete;
   |

warning: unused import: `self`
```

### Other cases

_No response_

### Rust Version

```Shell
rustc 1.78.0-nightly (3246e7951 2024-02-19)
binary: rustc
commit-hash: 3246e79513cb89ddbfc0f21cb5a877e5b321dcc5
commit-date: 2024-02-19
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
```


### Anything else?

_No response_

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"surechen"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-coroutines `#![feature(coroutines)]` labels Feb 20, 2024
@matthiaskrgr matthiaskrgr changed the title false positive: unused_qualifications unused_qualifications clashes with unused_import Feb 20, 2024
@surechen
Copy link
Contributor

@rustbot claim

surechen added a commit to surechen/rust that referenced this issue Mar 11, 2024
surechen added a commit to surechen/rust that referenced this issue Mar 12, 2024
surechen added a commit to surechen/rust that referenced this issue Mar 12, 2024
surechen added a commit to surechen/rust that referenced this issue Mar 12, 2024
surechen added a commit to surechen/rust that referenced this issue Mar 13, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 14, 2024
Fix the conflict problem between the diagnostics fixes of lint `unnecessary_qualification`  and  `unused_imports`

fixes rust-lang#121331

For an `item` that triggers lint unnecessary_qualification, if the `use item` which imports this item is also trigger unused import, fixing the two lints at the same time may lead to the problem that the `item` cannot be found.
This PR will avoid reporting lint unnecessary_qualification when conflict occurs.

r? `@petrochenkov`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 14, 2024
Fix the conflict problem between the diagnostics fixes of lint `unnecessary_qualification`  and  `unused_imports`

fixes rust-lang#121331

For an `item` that triggers lint unnecessary_qualification, if the `use item` which imports this item is also trigger unused import, fixing the two lints at the same time may lead to the problem that the `item` cannot be found.
This PR will avoid reporting lint unnecessary_qualification when conflict occurs.

r? ``@petrochenkov``
@bors bors closed this as completed in 1a81a94 Mar 15, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 15, 2024
Rollup merge of rust-lang#122373 - surechen:fix_121331, r=petrochenkov

Fix the conflict problem between the diagnostics fixes of lint `unnecessary_qualification`  and  `unused_imports`

fixes rust-lang#121331

For an `item` that triggers lint unnecessary_qualification, if the `use item` which imports this item is also trigger unused import, fixing the two lints at the same time may lead to the problem that the `item` cannot be found.
This PR will avoid reporting lint unnecessary_qualification when conflict occurs.

r? ``@petrochenkov``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-coroutines `#![feature(coroutines)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants