rust-lang / rust-lang/rust

Could `unused_imports` be suppressed when there are name resolution failures?

Open
#118,303 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics D-verbose T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
use std::ops::ControlFlow::{self, Continue, Break};
use std::cmp::Ordering::*;

#[inline]
fn chain_less(a: &u32, other: &u32) -> ControlFlow<bool> {
    match a.partial_cmp(other) {
        None => Break(false),
        Some(Less) => Break(true),
        Some(Equal) => Contine(()),
        Some(Greater) => Break(false),
    }
}
Current output
warning: unused import: `Continue`
 --> src/lib.rs:1:35
  |
1 | use std::ops::ControlFlow::{self, Continue, Break};
  |                                   ^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0425]: cannot find function, tuple struct or tuple variant `Contine` in this scope
 --> src/lib.rs:9:24
  |
9 |         Some(Equal) => Contine(()),
  |                        ^^^^^^^ help: a tuple variant with a similar name exists: `Continue`
 --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/ops/control_flow.rs:89:5
  |
  = note: similarly named tuple variant `Continue` defined here

For more information about this error, try `rustc --explain E0425`.
Desired output
error[E0425]: cannot find function, tuple struct or tuple variant `Contine` in this scope
 --> src/lib.rs:9:24
  |
9 |         Some(Equal) => Contine(()),
  |                        ^^^^^^^ help: a tuple variant with a similar name exists: `Continue`
 --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/ops/control_flow.rs:89:5
  |
  = note: similarly named tuple variant `Continue` defined here
Rationale and extra context

repro: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=efc0eb84c1ba836842fbb5c05d36f6ba

When I got the import correct, but typo'd it in the use, it would be nice if the compiler didn't complain about the unused import.

(From a layman's perspective, it also feels weird that it's reported as unused before the errors in the code that are looking up names, even though I guess from an implementation perspective it's reasonable that a token that doesn't appear again and isn't a trait is of course unused without needing to do lookup.)

Other cases

No response

Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer in src/lib.rs, using the Rust Playground link to confirm the current warning and name-resolution error. Trace how unused_imports is emitted alongside the unresolved Contine error; done means the unused-import warning is suppressed when name resolution fails, while the error remains.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.