rust-playground icon indicating copy to clipboard operation
rust-playground copied to clipboard

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

Open karolzwolak opened this issue 7 months ago • 0 comments

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

karolzwolak avatar Mar 11 '25 19:03 karolzwolak