-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rustdoc: Unify macro intra-doc link resolution with type and value resolution #91427
Conversation
rustdoc should already have error-ed out for conflicting anchors, and it doesn't make sense to do this for only one namespace anyway.
Some changes occurred in intra-doc-links. cc @jyn514 |
Oh, this can probably remove the |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Hmm, it looks like |
MCVE: #[macro_export]
macro_rules! foo {
() => {};
}
pub mod bar {
/// [foo!]
pub fn baz() {
foo!();
}
} Rustc compiles the |
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.
sweet, i always disliked this setup
self.cx.enter_resolver(|resolver| { | ||
// FIXME(jynelson): does this really need 3 separate lookups? |
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.
turns out, no 😆
None, | ||
&ParentScope::module(resolver.graph_root(), resolver), | ||
false, | ||
false, |
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.
perhaps we should also add tests that ensure that macros can still be linked to on both newer and older editions
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.
Ah, yeah, you noted a problem with #[macro_export]
above
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.
Yeah this code was like this to handle macro_export
/old-style macro resolution. Which still exists. But perhaps we can handle this a bit cleaner.
{
struct S;
macro_rules! mac { () => {} }
// `mac`'s scope starts here
/// `mac` <- `resolve_str_path_error` won't see this
struct Z;
//`mac`'s scope ends here
} As you can see So both using and not using |
This will be very easy to do for local This will be hard to do for links inlined from other crates, because we don't even keep the relevant information in metadata (although we may start keeping it due to macros 2.0). |
☔ The latest upstream changes (presumably #92601) made this pull request unmergeable. Please resolve the merge conflicts. |
merge conflicts + broken build. |
yes, I'm aware, that's why it's marked waiting-on-author. |
Any chance to get this landed with |
@petrochenkov I don't know when I'll get a chance to work on this. Feel free to take over the PR and have someone from the rustdoc team review. |
Ok I take it back, I can do this much:
Not sure how that's helpful for the resolver hackery, since it still requires access to the resolver in |
It removes the use of |
I'm not sure in what context you could document a non-modularized macro. Rustdoc doesn't document anything at function-scope, only at the module level. I don't understand why the macro in the MCVE (#91427 (comment)) isn't resolved according to the rules you explained. |
I may also have time later to do some rebasing and patchups here if necessary, but not any time soon. |
@Manishearth this requires more than patchups, someone needs to investigate why the MCVE doesn't work and then figure out how to change the resolver internals to make it work with |
…=petrochenkov rustdoc: Special-case macro lookups less Previously, rustdoc had 3 fallbacks it used: 1. `resolve_macro_path` 2. `all_macros` 3. `resolve_str_path_error` Ideally, it would only use `resolve_str_path_error`, to be consistent with other namespaces. Unfortunately, that doesn't consider macros that aren't defined at module scope; consider for instance ```rust { struct S; macro_rules! mac { () => {} } // `mac`'s scope starts here /// `mac` <- `resolve_str_path_error` won't see this struct Z; //`mac`'s scope ends here } ``` This changes it to only use `all_macros` and `resolve_str_path_error`, and gives `resolve_str_path_error` precedence over `all_macros` in case there are two macros with the same name in the same module. This is a smaller version of rust-lang#91427. r? `@petrochenkov`
Not planning to look into this. Happy for someone else to pick it up. |
Fixes #81633 and also cleans up quite a lot of code.
r? @Manishearth