-
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
Do not suggest importing hash_map::HashMap or btree_map::BTreeMap #72642
Comments
@rustbot claim |
@ayushmishra2005 responding to your comment here rather than on the PR - here are some rough pointers of what I'd look into (not having dug much into this myself, I can't say exactly what will be the solution): So, let's start at the beginning - the suggestion that we see comes from this line: rust/src/librustc_resolve/diagnostics.rs Line 1498 in 0aa6751
You can find that yourself using grep or just search on GitHub for the wording used in the suggestion (or some subset of it - as you can see, a bunch of this particular message is format strings). It looks like it gets the suggestions to print from a That's in a function called rust/src/librustc_resolve/lib.rs Lines 2579 to 2591 in f6072ca
We can see that the candidates come from deconstructing a rust/src/librustc_resolve/late.rs Lines 1621 to 1629 in 91fb72a
Going even further back, we see that rust/src/librustc_resolve/late/diagnostics.rs Lines 213 to 223 in f93bb2a
A rough read of this function suggests that it starts at some arbitrary starting module, looks over every name defined in that module for names that match what the user wrote, and if the current name is itself a module, it adds that to the list of modules to search. I hope that you can see how this could start with something like I suspect that we could determine that both of these items are actually the same by comparing their rust/src/librustc_resolve/diagnostics.rs Lines 679 to 683 in 0aa6751
So what I'd probably end up doing is experimenting with how expensive it would be to iterate over each of the candidates before adding a new candidate (we know an error occurs at this point, so we've got some room to impact perf), and checking for duplicate suggestions; or maybe accumulating suggestions into a edit: oh, and check out the rustc-dev-guide for getting your local environment set-up and as a reference. |
@davidtwco Great Thanks. Let me work on it |
Update src/librustc_resolve/diagnostics.rs Co-authored-by: David Wood <[email protected]> Minor refactoring rust-lang#72642 Fixed failing test-cases
…tion, r=davidtwco Remove noisy suggestion Remove noisy suggestion rust-lang#72642
Update src/librustc_resolve/diagnostics.rs Co-authored-by: David Wood <[email protected]> Minor refactoring rust-lang#72642 Fixed failing test-cases remove trivial `mk_predicate`s Make `SourceMap` available for early debug-printing of `Span`s Normally, we debug-print `Spans` using the `SourceMap` retrieved from the global `TyCtxt`. However, we fall back to printing out the `Span`'s raw fields (instead of a file and line number) when we try to print a `Span` before a `TyCtxt` is available. This makes debugging early phases of the compile, such as parsing, much more difficult. This commit stores a `SourceMap` in `rustc_span::GlOBALS` as a fallback. When a `TyCtxt` is not available, we try to retrieve one from `GLOBALS` - only if this is not available do we fall back to the raw field output. I'm not sure how to write a test for this - however, this can be verified locally by setting `RUSTC_LOG="rustc_parse=debug"`, and verifying that the output contains filenames and line numbers. Add test for rust-lang#72554. rustc_target: Remove `pre_link_args_crt` Improve E0433, so that it suggests missing imports Fix a typo in `late.rs` Co-authored-by: Esteban Kuber <[email protected]> fix `AdtDef` docs Add Camelid Email from @camelid: > HI there, > > I’m a new contributor and I just looked at Rust Thanks and noticed that my contributions are listed under two different capitalizations of my name: “Camelid" and “camelid". Could you make them both “Camelid"? > > Thanks! > > Camelid save_analysis: work on HIR tree instead of AST Update `rls` submodule remove outdated fixme Hexagon libstd: fix typo for c_ulonglong Add more assert to Vec with_capacity docs Show assertion on len too to show them how adding new items will affect both the length and capacity, before and after. Add Kyle Strand to mailmap Fix missing word in RELEASES.md Update cargo Enable lld for Cargo tests on Windows. Fixed failing test-cases rust-lang#72642
Fixed failing test-cases
…tion, r=davidtwco Remove noisy suggestion of hash_map Remove noisy suggestion of hash_map rust-lang#72642 fixes rust-lang#72642
…tion, r=davidtwco Remove noisy suggestion of hash_map Remove noisy suggestion of hash_map rust-lang#72642 fixes rust-lang#72642
Fixed failing test-cases Remove noisy suggestion of hash_map rust-lang#72642 Fixed failing test-cases
The
std::collections::hash_map::HashMap
suggestion here is just noise, it's (almost?) never what we actually want the person to import.This issue has been assigned to @ayushmishra2005 via this comment.
The text was updated successfully, but these errors were encountered: