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

Unreasonable "consider importing" suggestions #84081

Closed
porglezomp opened this issue Apr 11, 2021 · 0 comments · Fixed by #84113
Closed

Unreasonable "consider importing" suggestions #84081

porglezomp opened this issue Apr 11, 2021 · 0 comments · Fixed by #84113
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@porglezomp
Copy link
Contributor

I made a typo text -> test and got a very strange suggestion.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1fdd70937900d5a5443d66f0c200ada6

use std::{fs, io::Read};

fn foo() {
    let mut f = fs::File::new("hello");
    let mut text = String::new();
    f.read_to_string(&mut test).unwrap();
}

The current output is:

Standard Error

   Compiling playground v0.0.1 (/playground)

error[E0423]: expected value, found attribute macro `test`
 --> src/lib.rs:6:27
  |
6 |     f.read_to_string(&mut test).unwrap();
  |                           ^^^^
  |
help: a local variable with a similar name exists
  |
6 |     f.read_to_string(&mut text).unwrap();
  |                           ^^^^
help: consider importing one of these items instead
  |
1 | use crate::fs::io::sys::ext::net::raw_fd::sys_common::backtrace::backtrace_rs::symbolize::gimli::mystd::detect::bit::test;
  |
1 | use crate::fs::io::sys::ext::net::raw_fd::sys_common::backtrace::backtrace_rs::symbolize::gimli::mystd::detect::cache::test;
  |

The import suggestions here are kind of nonsense.
(They are only suggested if fs is imported.)
It seems like "consider importing one of these items instead" shouldn't suggest private items, at the very least in the case of external crates.

(For the current crate, maybe you wanted one of your own items to be available, but those should still probably be called out as being private items?)

@porglezomp porglezomp added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 11, 2021
@jyn514 jyn514 added the A-resolve Area: Path resolution label Apr 11, 2021
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-resolve Area: Path resolution 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.

2 participants