-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
rustdoc: dep-info for standalone markdown inputs #154352
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
Open
notriddle
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
notriddle:emit-md
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,12 +70,14 @@ use std::io::{self, IsTerminal}; | |
| use std::path::Path; | ||
| use std::process::ExitCode; | ||
|
|
||
| use rustc_ast::ast; | ||
| use rustc_errors::DiagCtxtHandle; | ||
| use rustc_hir::def_id::LOCAL_CRATE; | ||
| use rustc_interface::interface; | ||
| use rustc_middle::ty::TyCtxt; | ||
| use rustc_session::config::{ErrorOutputType, RustcOptGroup, make_crate_type_option}; | ||
| use rustc_session::{EarlyDiagCtxt, getopts}; | ||
| use rustc_span::{BytePos, Span, SyntaxContext}; | ||
| use tracing::info; | ||
|
|
||
| use crate::clean::utils::DOC_RUST_LANG_ORG_VERSION; | ||
|
|
@@ -836,8 +838,39 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { | |
| // `run_compiler`. | ||
| return wrap_return( | ||
| dcx, | ||
| interface::run_compiler(config, |_compiler| { | ||
| markdown::render_and_write(&md_input, render_options, edition) | ||
| interface::run_compiler(config, |compiler| { | ||
| // construct a phony "crate" without actually running the parser | ||
| // allows us to use other compiler infrastructure like dep-info | ||
| let file = | ||
| compiler.sess.source_map().load_file(&md_input).map_err(|e| { | ||
fmease marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| format!("{md_input}: {e}", md_input = md_input.display()) | ||
| })?; | ||
| let inner_span = Span::new( | ||
| file.start_pos, | ||
| BytePos(file.start_pos.0 + file.normalized_source_len.0), | ||
| SyntaxContext::root(), | ||
| None, | ||
| ); | ||
| let krate = ast::Crate { | ||
| attrs: Default::default(), | ||
| items: Default::default(), | ||
| spans: ast::ModSpans { inner_span, ..Default::default() }, | ||
| id: ast::DUMMY_NODE_ID, | ||
| is_placeholder: false, | ||
| }; | ||
| rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| { | ||
| let has_dep_info = render_options.dep_info().is_some(); | ||
| markdown::render_and_write(file, render_options, edition)?; | ||
| if has_dep_info { | ||
| // Register the loaded external files in the source map so they show up in depinfo. | ||
| // We can't load them via the source map because it gets created after we process the options. | ||
| for external_path in &loaded_paths { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flags like |
||
| let _ = compiler.sess.source_map().load_binary_file(external_path); | ||
| } | ||
| rustc_interface::passes::write_dep_info(tcx); | ||
| } | ||
| Ok(()) | ||
| }) | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| % My Example | ||
|
|
||
| First and only paragraph. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| % Index page | ||
|
|
||
| Index page |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 have tested your patch locally and ran
rustdoc test.md --index-page my-index-page.md --emit=dep-info(with the appropriate source files) butmy-index-page.mdwasn't listed in the resulting dep info (for comparison,--html-after-contentdid obv work as the tests also confirm); I might've overlooked something tho.Note that the custom index page isn't properly tracked in "normal mode" either (where the source file is Rust), neither on main nor on your branch AFAICT.
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 see.
I notice that
write_dep_infois run before the renderer is run. To fix this, I either need to add the file to the source map separately (which can be done the same way--html-before-contentand related options are done), or move when the renderer runs.The less risky option, at least in the short term, is adding the file separately.