Skip to content

unused_qualifications clashes with unused_import #121331

Closed
@matthiaskrgr

Description

@matthiaskrgr

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 -->

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsF-coroutines`#![feature(coroutines)]`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