Skip to content
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

Unresolved import error suggests semicolon in list import #103943

Closed
est31 opened this issue Nov 3, 2022 · 4 comments
Closed

Unresolved import error suggests semicolon in list import #103943

est31 opened this issue Nov 3, 2022 · 4 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@est31
Copy link
Member

est31 commented Nov 3, 2022

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

@est31 est31 added the C-bug Category: This is a bug. label Nov 3, 2022
@rustbot rustbot added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 3, 2022
@TaKO8Ki TaKO8Ki self-assigned this Nov 4, 2022
@Rageking8
Copy link
Contributor

@rustbot label +T-compiler +D-invalid-suggestion

@rustbot rustbot added D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 4, 2022
@est31
Copy link
Member Author

est31 commented Jan 26, 2023

@compiler-errors ignored me, not sure why, but it got fixed by #106175

@est31 est31 closed this as completed Jan 26, 2023
@compiler-errors
Copy link
Member

@est31, uh, I forgot to add it to the list of issues closed by
the PR, that simple 😅

I promise you there's no good reason for me to have ignored you intentionally

@est31
Copy link
Member Author

est31 commented Jan 26, 2023

@compiler-errors no worries! thanks for the fix :) ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants