Skip to content

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

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

Open
karolzwolak opened this issue Mar 11, 2025 · 0 comments

Comments

@karolzwolak
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant