Skip to content

Import suggestions for submodules don't put the suggestions in the submodule #1144

Open
@karolzwolak

Description

@karolzwolak
mod sub {
    fn foo() {
        let map = HashMap::new();
    }
}

suggestios:

Compiling playground v0.0.1 (/playground)
error[E0433]: failed to resolve: use of undeclared type `HashMap`
 --> src/lib.rs:3:19
  |
3 |         let map = HashMap::new();
  |                   ^^^^^^^ use of undeclared type `HashMap`
  |
help: consider importing one of these items
  |
2 +     use std::collections::HashMap;
  |
2 +     use ahash::HashMap;
  |
2 +     use hashbrown::HashMap;
  |
2 +     use nom::lib::std::collections::HashMap;
  |

For more information about this error, try `rustc --explain E0433`.
error: could not compile `playground` (lib) due to 1 previous error

The compiler suggests to put these imports at line 2 (so just after mod sub {, which fixes the issue and correctly imports the hashmap, but when you click to add it, the import gets added at the start of the file.

current behavior:

use std::collections::HashMap;
mod sub {
    fn foo() {
        let map = HashMap::new();
    }
}

expected:

mod sub{
    use std::collections::HashMap;
    fn foo() {
        let map = HashMap::new();
    }
}

playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions