Repository navigation
resolve: use #[doc(alias)] to improve function resolution diagnostics - #154833
Unique-Usman wants to merge 1 commit into
Conversation
Parse `#[doc(alias)]` attributes for local functions and store them in the resolver. Use these aliases during name resolution diagnostics to suggest the original function when an alias is used in its place. This enables cases like calling `bar()` to suggest `foo()` when `foo` is annotated with `#[doc(alias = "bar")]`. Includes UI tests for function and method cases(which has already being supported). Helped-by: Esteban Küber <esteban@kuber.com.ar> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
|
r? @davidtwco rustbot has assigned @davidtwco. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? estebank |
|
I don't think we should do this. So it's a low value diagnostic change, but it requires keeping a new global mutable resolver state and doing extra work on a good path -> doesn't pull its weight. |
Valid point. Not entirely true though, because, doc alias is actually used initially before this pr in the same crate for method and associated functions for diagnostics. Also, the comment was actually also a little bit misleading, after investigating it, the lookup_doc_alias_name was using
This is true, but, looking at my reason above, do you think this stills stands ? |
|
This also works for methods and associated function in a trait for the same crates for diagnosis. So, I believe not working for function is more of the hacking that needs to be done to supportting it. |
Yeah, because there (in
That's an (ideological) issue with the new attribute parsing infra design, parsed attributes are not HIR, and are often used before HIR is built (like in rustc_resolve), but the new infra uses HIR for naming and puts itself into HIR modules. |
Do note that in some cases, the crate's author is a collection of people of different levels of expertise with the codebase. Think large commercial projects with high turn-over. Those would likely want to be able to leverage existing mechanisms for onboarding new engineers. Realistically, it's true that a lot of these projects would already be relying on workspaces and splitting their projects in multiple crates, but that is not necessarily a given.
I highly suspect that the order in which the thought process went was "we don't get this for free" -> "we don't need it anyways", which is perfectly defensible! But the comment should likely have included both points :)
Agreed on the additional cost to
The lack of consistency is a minor papercut that might confuse people by not matching their expectations. I agree it is not too important to address, but I'd like to minimize divergences as much as possible. Otherwise, we'd want a lint on |
|
@petrochenkov - you might want to take a look at the last comment. |
|
☔ The latest upstream changes (presumably #156305) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Visited during compiler triage. |
| if !item.attrs.is_empty() { | ||
| // for better error reporting in doc alias for function | ||
| let aliases = self.parse_doc_aliases(&item.attrs); | ||
| self.r.doc_aliases.insert(local_def_id, aliases); | ||
| } |
There was a problem hiding this comment.
This small tweak should keep the additional memory consumption of this change to a minimum, by only keeping entries in the hash map for items that do have aliases (minor thing).
| if !item.attrs.is_empty() { | |
| // for better error reporting in doc alias for function | |
| let aliases = self.parse_doc_aliases(&item.attrs); | |
| self.r.doc_aliases.insert(local_def_id, aliases); | |
| } | |
| if !item.attrs.is_empty() | |
| // for better error reporting in doc alias for function | |
| && let aliases = self.parse_doc_aliases(&item.attrs) | |
| && !aliases.is_empty() | |
| { | |
| self.r.doc_aliases.insert(local_def_id, aliases); | |
| } |
I'm still against merging this, and would just close the PR. |
|
@petrochenkov whenever you have a few minutes, please take a look at the discussion above, if you could clarify your position on this PR. Looking at the changes, I am still for landing this. Of the points I raised in my last comment, the one that I am quite concerned about is the lack of consistency in behavior between local and foreign crates, which can lead to people not ever learning about the feature, or expect it to work and being confused why it doesn't trigger (and if we collectively decide not to make it consistent, then we should have a lint catching this on private items). |
Parse
#[doc(alias)]attributes for local functions and store them in the resolver. Use these aliases during name resolution diagnostics to suggest the original function when an alias is used in its place.This enables cases like calling
bar()to suggestfoo()whenfoois annotated with#[doc(alias = "bar")].Includes UI tests for function and method cases(which has already being supported).