-
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
Resolve items for cross-crate imports relative to the original module #73101
Conversation
r? @ollie27 (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It looks like the issue is I always give the parent of a |
aabf432
to
578a68f
Compare
Current error:
This seems to be because of #71820. Backtrace
|
This can't be fixed in rustdoc, all I'm doing is calling
It looks like it will need to be fixed in rustc (possibly by #72088?) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
2dd29d4
to
f618005
Compare
I may have finally figured out how serialization is related. Currently, this requires you to document all dependencies at the same time - if you pass |
Since
The only difference is whether it documented
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
☔ The latest upstream changes (presumably #73115) made this pull request unmergeable. Please resolve the merge conflicts. |
d525650
to
1cd5eda
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
a583735
to
0de2c80
Compare
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.
The approach seems overall good. It seems like the exportmap contained all the metadata for this already, just in a somewhat hidden way!
_ => None, | ||
use rustc_middle::ty::DefIdTree; | ||
let parent_node = if item.is_fake() { | ||
// FIXME: is this correct? |
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 suspect we'll never hit this case, it's only for auto traits and blanket impls, which don't get docs resolved on the local scope anyway.
What happens if you panic here? Especially if you try and document a blanket impl that uses intra doc links?
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.
Rustdoc panics if I don't check this (with or without an explicit panic):
thread 'rustc' panicked at 'index out of bounds: the len is 38899 but the index is 38905', /home/joshua/src/rust/src/librustc_hir/definitions.rs:53:9
18: rustc_hir::definitions::DefPathTable::def_key
at /home/joshua/src/rust/src/librustc_hir/definitions.rs:53
19: rustc_metadata::rmeta::decoder::<impl rustc_metadata::creader::CrateMetadataRef>::def_key
at src/librustc_metadata/rmeta/decoder.rs:1411
20: rustc_metadata::rmeta::decoder::cstore_impl::<impl rustc_middle::middle::cstore::CrateStore for rustc_metadata::creader::CStore>::def_key
at src/librustc_metadata/rmeta/decoder/cstore_impl.rs:484
21: rustc_middle::ty::context::TyCtxt::def_key
at src/librustc_middle/ty/context.rs:1188
22: <rustc_middle::ty::context::TyCtxt as rustc_middle::ty::DefIdTree>::parent
at src/librustc_middle/ty/mod.rs:358
23: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::fold::DocFolder>::fold_item
at src/librustdoc/passes/collect_intra_doc_links.rs:482
This was the motivation for #73098.
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.
And actually it will panic on any file, including empty files.
I cherry-picked the commits from #73103 and confirmed that they fix the test failure. |
I figured out the issue here: in |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@jyn514 yeah iirc in other places where |
One small issue I found: rustdoc will not warn if resolution fails on a re-export, even if there is additional documentation that wasn't in the original crate. $ cat src/lib.rs
#![warn(intra_doc_resolution_failure)]
extern crate a;
/// Link to [`NotHere`]
pub use a::Bar;
$ cat ../a/src/lib.rs
// crate a:
pub struct Foo;
/// Link to [Food]
pub struct Bar;
$ cargo +stage1 doc
Documenting a v0.1.0 (/home/joshua/src/test-rustdoc/a)
Checking a v0.1.0 (/home/joshua/src/test-rustdoc/a)
warning: `[Food]` cannot be resolved, ignoring it.
--> /home/joshua/src/test-rustdoc/a/src/lib.rs:4:14
|
4 | /// Link to [Food]
| ^^^^ cannot be resolved, ignoring
|
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
warning: 1 warning emitted
Documenting b v0.1.0 (/home/joshua/src/test-rustdoc/b)
Finished dev [unoptimized + debuginfo] target(s) in 1.43s I'm having trouble adding automated tests for this because |
…anishearth Resolve items for cross-crate imports relative to the original module ~~Blocked on rust-lang#73103 and rust-lang#73566 Closes rust-lang#65983. I tested on the following code (as mentioned in rust-lang#65983 (comment)): ``` pub use rand::Rng; ``` and rustdoc generated the following link: https://rust-random.github.io/rand/rand_core/trait.RngCore.html
…anishearth Resolve items for cross-crate imports relative to the original module ~~Blocked on rust-lang#73103 and rust-lang#73566 Closes rust-lang#65983. I tested on the following code (as mentioned in rust-lang#65983 (comment)): ``` pub use rand::Rng; ``` and rustdoc generated the following link: https://rust-random.github.io/rand/rand_core/trait.RngCore.html
…arth Rollup of 8 pull requests Successful merges: - rust-lang#73101 (Resolve items for cross-crate imports relative to the original module) - rust-lang#73269 (Enable some timeouts in SGX platform) - rust-lang#74033 (Add build support for Cargo's build-std feature.) - rust-lang#74351 (Do not render unstable items for rustc doc) - rust-lang#74357 (Some `Symbol` related improvements) - rust-lang#74371 (Improve ayu rustdoc theme) - rust-lang#74386 (Add RISC-V GNU/Linux to src/tools/build-manifest as a host platform) - rust-lang#74398 (Clean up E0723 explanation) Failed merges: r? @ghost
### x.py build/test: stage 1 I've seen very few people who actually use full stage 2 builds on purpose. These compile rustc and libstd twice and don't give you much more information than a stage 1 build (except in rare cases like rust-lang#68692 (comment)). For new contributors, this makes the build process even more daunting than it already is. As long as CI is changed to use `--stage 2` I see no downside here. ### x.py bench/dist/install: stage 2 These commands have to do with a finished, optimized version of rustc. It seems very rare to want to use these with a stage 1 build. ### x.py doc: stage 0 Normally when you document things you're just fixing a typo. In this case there is no need to build the whole rust compiler, since the documentation will usually be the same when generated with the beta compiler or with stage 1. Note that for this release cycle only there will be a significant different between stage0 and stage1 docs: rust-lang#73101. However most of the time this will not be the case.
} | ||
|
||
let current_item = match item.inner { | ||
ModuleItem(..) => { | ||
if item.attrs.inner_docs { | ||
if item_hir_id.unwrap() != hir::CRATE_HIR_ID { item.name.clone() } else { None } | ||
if item.def_id.is_top_level_module() { item.name.clone() } else { None } |
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.
This is a bug, there should be a !
in front.
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.
This bit is getting removed altogether in #76467, so I don't think there's much point in fixing it.
Update intra-doc link documentation to match the implementation r? `@Manishearth` cc `@camelid` `@m-ou-se` Relevant PRs: - rust-lang#74489 - rust-lang#80181 - rust-lang#76078 - rust-lang#77519 - rust-lang#73101 Relevant issues: - rust-lang#78800 - rust-lang#77200 - rust-lang#77199 / rust-lang#54191 I haven't documented things that I consider 'just bugs', like rust-lang#77732, but I have documented features that aren't implemented, like rust-lang#78800.
Blocked on #73103 and #73566Closes #65983.
I tested on the following code (as mentioned in #65983 (comment)):
and rustdoc generated the following link: https://rust-random.github.io/rand/rand_core/trait.RngCore.html