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

Add support for macro expansion in rustdoc source code pages #137229

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.20.3
0.20.5
4 changes: 4 additions & 0 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -830,3 +830,7 @@ will be split as follows:
"you today?",
]
```

## `--generate-macro-expansion`: Generate macros expansion toggles in source code

This flag enables the generation of toggles to expand macros in the HTML source code pages,
11 changes: 11 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ pub(crate) struct RenderOptions {
pub(crate) parts_out_dir: Option<PathToParts>,
/// disable minification of CSS/JS
pub(crate) disable_minification: bool,
/// If `true`, HTML source pages will generate the possibility to expand macros.
pub(crate) generate_macro_expansion: bool,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -775,6 +777,7 @@ impl Options {
let show_type_layout = matches.opt_present("show-type-layout");
let nocapture = matches.opt_present("nocapture");
let generate_link_to_definition = matches.opt_present("generate-link-to-definition");
let generate_macro_expansion = matches.opt_present("generate-macro-expansion");
let extern_html_root_takes_precedence =
matches.opt_present("extern-html-root-takes-precedence");
let html_no_source = matches.opt_present("html-no-source");
Expand All @@ -790,6 +793,13 @@ impl Options {
.with_note("`--generate-link-to-definition` option will be ignored")
.emit();
}
if generate_macro_expansion && (show_coverage || output_format != OutputFormat::Html) {
dcx.struct_warn(
"`--generate-macro-expansion` option can only be used with HTML output format",
)
.with_note("`--generate-macro-expansion` option will be ignored")
.emit();
}

let scrape_examples_options = ScrapeExamplesOptions::new(matches, dcx);
let with_examples = matches.opt_strs("with-examples");
Expand Down Expand Up @@ -870,6 +880,7 @@ impl Options {
unstable_features,
emit,
generate_link_to_definition,
generate_macro_expansion,
call_locations,
no_emit_shared: false,
html_no_source,
Expand Down
Loading
Loading