Skip to content

Odd import suggestion for NonZeroU8 when std::sync::atomic is in scope #80079

Closed
@jonas-schievink

Description

@jonas-schievink
use std::sync::atomic;

fn main() {
    NonZeroU8::new(1);
}
error[E0433]: failed to resolve: use of undeclared type `NonZeroU8`
 --> src/main.rs:4:5
  |
4 |     NonZeroU8::new(1);
  |     ^^^^^^^^^ not found in this scope
  |
help: consider importing one of these items
  |
1 | use core::num::NonZeroU8;
  |
1 | use crate::atomic::fmt::str::iter::option::convert::num::NonZeroU8;

The suggested import path, crate::atomic::fmt::str::iter::option::convert::num::NonZeroU8, goes through private imports (so it doesn't work), and is also ridiculously long. These suggestions might want to take inspiration from rust-analyzer and only display the shortest path(s) to any candidate (and also should not include private imports).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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