-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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: Cleanup handling of associated items for intra-doc links #83849
Conversation
c561013
to
2f0f22b
Compare
This comment has been minimized.
This comment has been minimized.
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.
I'm not quite sure how the cleanup helps with the particular issue, but it looks good overall - except for the failing test. I have some questions, though.
@@ -534,29 +531,39 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { | |||
} | |||
})?; | |||
|
|||
// FIXME: are these both necessary? | |||
let ty_res = if let Some(ty_res) = resolve_primitive(&path_root, TypeNS) |
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.
I guess the error shows why this resolve_primitive
might be necessary?
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.
I'm bisecting this now - I think it's unlikely this is the cause, but it's possible.
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.
Oh! I figured it out - resolve_path
gives precedence to modules over primitives, this does the reverse.
| ^^^^^^^^^ no item named `MAX` in module `usize`
The issue is that both mod usize
and the primitive usize are in scope. I think this might actually be a bug even before - rustdoc should give an error if the base res is ambiguous, but it doesn't:
$ cat primitive-ambiguous.rs
//! [usize::MAX]
mod usize {
const MAX: usize = 1;
}
$ rustdoc primitive-ambiguous.rs
$
For this specific test case, I think we could fix it by not giving an ambiguity error if the module has doc(primitive)
on it?
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.
I don't think I'm qualified to have a say in this :)
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.
cc @Manishearth - do you have an opinion here? For context, the original test case was
//! [usize::MAX]
#[doc(primitive = "usize")]
mod usize {}
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.
Actually I think I'm going to wait to fix this for a follow-up PR, it's a change in behavior and shouldn't be mixed with the cleanups. Opened #83862.
This comment has been minimized.
This comment has been minimized.
7e2e4eb
to
35de890
Compare
This comment has been minimized.
This comment has been minimized.
35de890
to
ed00d7e
Compare
This comment has been minimized.
This comment has been minimized.
ed00d7e
to
750cffa
Compare
This comment has been minimized.
This comment has been minimized.
750cffa
to
89a63ef
Compare
I'm not sure the third commit message ("Greatly simplify") applies at this point :) Otherwise LGTM. |
89a63ef
to
3611a64
Compare
@bors r=bugadani |
📌 Commit 3611a64 has been approved by |
Oh sorry I forgot to answer this: the early collector won't be able to use a TyCtxt at all. By separating this into "functions that use TyCtxt" and "functions that use resolver", it will be a lot easier to just cut and paste them to a new file. |
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? `@bugadani` maybe? Feel free to reassign :)
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? ``@bugadani`` maybe? Feel free to reassign :)
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? ```@bugadani``` maybe? Feel free to reassign :)
The warning is correct, |
Previously, the types looked like this: - None means this is not an associated item (but may be a variant field) - Some(Err) means this is known to be an error. I think the only way that can happen is if it resolved and but you had your own anchor. - Some(Ok(_, None)) was impossible. Now, this returns a nested Option and does the error handling and fiddling with the side channel in the caller. As a side-effect, it also removes duplicate error handling. This has one small change in behavior, which is that `resolve_primitive_associated_item` now goes through `variant_field` if it fails to resolve something. This is not ideal, but since it will be quickly rejected anyway, I think the performance hit is worth the cleanup. This also fixes a bug where struct fields would forget to set the side channel, adds a test for the bug, and ignores `private_intra_doc_links` in rustc_resolve (since it's always documented with --document-private-items).
3611a64
to
3b7e654
Compare
@bors r=bugadani |
📌 Commit 3b7e654 has been approved by |
⌛ Testing commit 3b7e654 with merge 3313e25dc6b7d8ae459b6340818d62b46c6da2c4... |
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? `@bugadani` maybe? Feel free to reassign :)
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? ``@bugadani`` maybe? Feel free to reassign :)
Rollup of 8 pull requests Successful merges: - rust-lang#83370 (Add `x.py setup tools` which enables `download-rustc` by default) - rust-lang#83489 (Properly suggest deref in else block) - rust-lang#83734 (Catch a bad placeholder type error for statics in `extern`s) - rust-lang#83814 (expand: Do not ICE when a legacy AST-based macro attribute produces and empty expression) - rust-lang#83835 (rustdoc: sort search index items for compression) - rust-lang#83849 (rustdoc: Cleanup handling of associated items for intra-doc links) - rust-lang#83881 (:arrow_up: rust-analyzer) - rust-lang#83885 (Document compiler/ with -Aprivate-intra-doc-links) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Helps with #83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time.
r? @bugadani maybe? Feel free to reassign :)