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

Help message when importing item from wrong module is wrong #105566

Closed
Aloso opened this issue Dec 11, 2022 · 2 comments · Fixed by #106175
Closed

Help message when importing item from wrong module is wrong #105566

Aloso opened this issue Dec 11, 2022 · 2 comments · Fixed by #106175
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aloso
Copy link
Contributor

Aloso commented Dec 11, 2022

Given the following code: playground link

use serde::{Serialize, IgnoredAny};

The current output is:

error[E0432]: unresolved import `serde::IgnoredAny`
 --> src/lib.rs:1:24
  |
1 | use serde::{Serialize, IgnoredAny};
  |                        ^^^^^^^^^^ no `IgnoredAny` in the root
  |
help: consider importing this struct instead
  |
1 | use serde::{Serialize, serde::de::IgnoredAny;
  |                        ~~~~~~~~~~~~~~~~~~~~~~

The help message is wrong for two reasons:

  • The closing bracket is missing
  • The crate name (serde) is repeated in the path, so the suggested code would import serde::serde::de::IgnoredAny instead of serde::de::IgnoredAny.

Ideally the output should look like:

help: consider importing this struct instead
  |
1 | use serde::{Serialize, de::IgnoredAny};
  |                        ~~~~~~~~~~~~~~

Note that the help message was only added recently, so this bug exists only on beta and nightly at the moment.

@Aloso Aloso added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 11, 2022
@fmease
Copy link
Member

fmease commented Dec 12, 2022

Duplicate of #105373.

@Aloso
Copy link
Contributor Author

Aloso commented Dec 12, 2022

Thanks for checking!

@Aloso Aloso closed this as completed Dec 12, 2022
compiler-errors added a commit to compiler-errors/rust that referenced this issue Jan 9, 2023
…=oli-obk

Fix bad import suggestion with nested `use` tree

Fixes rust-lang#105566
Fixes rust-lang#105373

Ideally, we'd find some way to turn these into structured suggestions -- perhaps on a separate line as a different `use` statement, but I have no idea how to access the span for the whole `use` from this point in the import resolution code.
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Jan 9, 2023
…=oli-obk

Fix bad import suggestion with nested `use` tree

Fixes rust-lang#105566
Fixes rust-lang#105373

Ideally, we'd find some way to turn these into structured suggestions -- perhaps on a separate line as a different `use` statement, but I have no idea how to access the span for the whole `use` from this point in the import resolution code.
@compiler-errors compiler-errors self-assigned this Dec 11, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants