Skip to content
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

Merged
merged 3 commits into from
Apr 6, 2021

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Apr 4, 2021

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 :)

@jyn514 jyn514 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 4, 2021
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@bugadani bugadani left a 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)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Contributor

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 :)

Copy link
Member Author

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 {}

Copy link
Member Author

@jyn514 jyn514 Apr 4, 2021

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.

src/librustdoc/passes/collect_intra_doc_links.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/collect_intra_doc_links.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/collect_intra_doc_links.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/collect_intra_doc_links.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/collect_intra_doc_links.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bugadani
Copy link
Contributor

bugadani commented Apr 5, 2021

I'm not sure the third commit message ("Greatly simplify") applies at this point :) Otherwise LGTM.

@jyn514
Copy link
Member Author

jyn514 commented Apr 5, 2021

@bors r=bugadani

@bors
Copy link
Contributor

bors commented Apr 5, 2021

📌 Commit 3611a64 has been approved by bugadani

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 5, 2021
@jyn514
Copy link
Member Author

jyn514 commented Apr 5, 2021

I'm not quite sure how the cleanup helps with the particular issue

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.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 5, 2021
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 :)
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 5, 2021
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 :)
jyn514 pushed a commit to jyn514/rust that referenced this pull request Apr 5, 2021
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 :)
@Dylan-DPC-zz
Copy link

failed in rollup

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 5, 2021
@jyn514
Copy link
Member Author

jyn514 commented Apr 5, 2021

The warning is correct, ModuleData is public and the kind field is private. It must not have been caught before because kind_side_channel wasn't set. I'll ignore the lint and add a test.

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).
@jyn514
Copy link
Member Author

jyn514 commented Apr 5, 2021

@bors r=bugadani

@bors
Copy link
Contributor

bors commented Apr 5, 2021

📌 Commit 3b7e654 has been approved by bugadani

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 5, 2021
@bors
Copy link
Contributor

bors commented Apr 5, 2021

⌛ Testing commit 3b7e654 with merge 3313e25dc6b7d8ae459b6340818d62b46c6da2c4...

@jyn514
Copy link
Member Author

jyn514 commented Apr 5, 2021

@bors retry yield to #83890 (in particular #83878 fixes spurious failures)

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 5, 2021
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 :)
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 5, 2021
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 :)
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 5, 2021
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
@bors bors merged commit f93412f into rust-lang:master Apr 6, 2021
@rustbot rustbot added this to the 1.53.0 milestone Apr 6, 2021
@jyn514 jyn514 deleted the intra-doc-cleanup branch April 6, 2021 03:02
@jyn514 jyn514 mentioned this pull request Apr 11, 2021
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants