Skip to content

Unreasonable "consider importing" suggestions #84081

Closed
@porglezomp

Description

@porglezomp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyT-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