Skip to content

Wrong highlighting in E0432 when import and suggestion share prefix #148070

@faculerena

Description

@faculerena

I tried this code:

use sync;
fn main(){}

I expected to see this:

 --> /tmp/test.rs:1:5
  |
1 | use sync;
  |     ^^^^ no `sync` in the root
  |
help: consider importing this module instead
  |
1 | use std::sync;
  |     +++++

Instead, this happened:

 --> /tmp/test.rs:1:5
  |
1 | use sync;
  |     ^^^^ no `sync` in the root
  |
help: consider importing this module instead
  |
1 | use std::sync;
  |      +++++

Note that in the second case, the highlighted part is td::s instead of std::.

The error is that as std:: starts with the same prefix as sync, it fails to highlight correctly what to add. It's not wrong, as if you add that it works, but it looks weird.

The same happens with time if you have tokio or tracing_suscriber as a dependency.

Meta

rustc --version --verbose:

rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8

This happens up until the last nightly compiler, and happens since it was added.

I could narrow the error, and I tried a fix in #148061 but it makes tests fail, as other warnings depend on this behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.D-imprecise-spansDiagnostics: spans don't point to exactly the erroneous codeT-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