-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
suggestion for typoed crate or module #89347
Conversation
r? @wesleywiser (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@wesleywiser What I want to solve is: In Zulip In test/ui/hygiene/extern-prelude-from-opaque-fail.rs, a decl_macro
|
r? @estebank |
I think to fully solve that issue, you'll need to do something very similar to what the identifier resolution does and traverse the scope to see what modules are currently in scope (see https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_resolve/lib.rs.html#1729-1740 which is probably what you need to call). That seems very messy though. @estebank do you know of a better way? |
@wesleywiser I think that you are right that that is the "principled" approach, but I think we should land this PR as is as a stopgap (without closing the original report so we can clean this up later). What do you think? |
Oh, yes absolutely! This seems like an obvious improvement over the status quo even if there are some edge cases. |
@estebank @wesleywiser Thank you for your advice! |
@estebank So should I open a new issue about that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should I open a new issue about that?
Please do.
compiler/rustc_resolve/src/lib.rs
Outdated
.map(|sugg| { | ||
( | ||
vec![(ident.span, sugg.to_string())], | ||
String::from("a similar crate or module exists"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String::from("a similar crate or module exists"), | |
String::from("there is a crate or module with a similar name"), |
Ideally we would get the type of what the ident
is from find_similarly_named_module_or_crate
so we can be more specific in the message. We can do that later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'll do it in a new PR.
This comment has been minimized.
This comment has been minimized.
14f7465
to
963ffec
Compare
This comment has been minimized.
This comment has been minimized.
963ffec
to
3bd051d
Compare
This comment has been minimized.
This comment has been minimized.
925beb4
to
55eb57a
Compare
There are three tests that are failing with the same ICE:
This can likely be prevented by looking at the module kind before calling |
I understand this when we are talking about high-priority bugfixes, but with diagnostics this approach already turned |
@estebank @petrochenkov |
If this is a temporary state of affairs, I'm ok landing this as is. @petrochenkov The "principled" approach will complicate @TaKO8Ki can you please commit to follow up on this soon? @bors r+ |
📌 Commit f0a611b6b08397f41505fc0085e11f8cb0943fe6 has been approved by |
Could we squash commits first, please? There's a few typo fixes and similar that seem like they would be nice to squash away. @bors r- |
avoid suggesting the same name sort candidates fix a message use `opt_def_id` instead of `def_id` move `find_similarly_named_module_or_crate` to rustc_resolve/src/diagnostics.rs
f0a611b
to
f819e6d
Compare
Yes. |
@bors r+ |
📌 Commit f819e6d has been approved by |
…ebank suggestion for typoed crate or module Previously, the compiler didn't suggest similarly named crates or modules. This pull request adds a suggestion for typoed crates or modules. rust-lang#76208 before: ``` error[E0433]: failed to resolve: use of undeclared type or module `chono` --> src/main.rs:2:5 | 2 | use chono::prelude::*; | ^^^^^ use of undeclared type or module `chono` ``` after: ``` error[E0433]: failed to resolve: use of undeclared type or module `chono` --> src/main.rs:2:5 | 2 | use chono::prelude::*; | ^^^^^ | | | use of undeclared crate or module `chono` | help: a similar crate or module exists: `chrono` ```
…askrgr Rollup of 6 pull requests Successful merges: - rust-lang#89347 (suggestion for typoed crate or module) - rust-lang#89670 (Improve `std::thread::available_parallelism` docs) - rust-lang#89757 (Use shallow clones for submodules) - rust-lang#89759 (Assemble the compiler when running `x.py build`) - rust-lang#89846 (Add `riscv32imc-esp-espidf` to 1.56 changelog) - rust-lang#89853 (Update the 1.56.0 release header for consistency) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Previously, the compiler didn't suggest similarly named crates or modules. This pull request adds a suggestion for typoed crates or modules.
#76208
before:
after: