Skip to content

Unresolved import error suggests semicolon in list import #103943

Closed
@est31

Description

@est31

If there is a list import with use path::{...}; with a wrong path, Rust is giving wrong suggestions for that path, it suggests a semicolon. E.g. for this code:

use std::collections::{HashMap, Entry};

It prints:

error[E0432]: unresolved import `std::collections::Entry`
 --> src/lib.rs:1:33
  |
1 | use std::collections::{HashMap, Entry};
  |                                 ^^^^^ no `Entry` in `collections`
  |
help: consider importing one of these items instead
  |
1 | use std::collections::{HashMap, hashbrown::hash_map::Entry;
  |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 | use std::collections::{HashMap, hashbrown::hash_set::Entry;
  |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 | use std::collections::{HashMap, hashlink::lru_cache::Entry;
  |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 | use std::collections::{HashMap, http::header::Entry;
  |                                 ~~~~~~~~~~~~~~~~~~~~
    and 14 other candidates

You can't use a semicolon here however, you have to use a comma. Also, it suggests absolute paths, while it should take into account that we are looking for sub-paths of std::collections.

It should suggest code like:

use std::collections::{HashMap, hash_map::Entry};

use std::collections::{HashMap, btree_map::Entry};

cc @compiler-errors

@rustbot label A-diagnostics

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-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