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

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

Closed
jonas-schievink opened this issue Dec 16, 2020 · 0 comments · Fixed by #84113
Closed

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

jonas-schievink opened this issue Dec 16, 2020 · 0 comments · Fixed by #84113
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jonas-schievink
Copy link
Contributor

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

@jonas-schievink jonas-schievink added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-diagnostics Area: Messages for errors, warnings, and lints labels Dec 16, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 17, 2021
…r=petrochenkov

Detect when suggested paths enter extern crates more rigorously

When reporting resolution errors, the compiler tries to avoid suggesting importing inaccessible paths from other crates. However, the search for suggestions only recognized when it was entering a crate root directly, and so failed to recognize a path like `crate::module::private_item`, where `module` was imported from another crate with `use other_crate::module`, as entering another crate.

Fixes rust-lang#80079
Fixes rust-lang#84081
@bors bors closed this as completed in 42e5621 Apr 17, 2021
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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant