Skip to content

Rustdoc: Add unstable --no-html-source flag #115135

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

Merged
merged 3 commits into from
Aug 23, 2023
Merged
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
4 changes: 4 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ pub(crate) struct RenderOptions {
pub(crate) call_locations: AllCallLocations,
/// If `true`, Context::init will not emit shared files.
pub(crate) no_emit_shared: bool,
/// If `true`, HTML source code pages won't be generated.
pub(crate) html_no_source: bool,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -686,6 +688,7 @@ impl Options {
let generate_link_to_definition = matches.opt_present("generate-link-to-definition");
let extern_html_root_takes_precedence =
matches.opt_present("extern-html-root-takes-precedence");
let html_no_source = matches.opt_present("html-no-source");

if generate_link_to_definition && (show_coverage || output_format != OutputFormat::Html) {
diag.struct_err(
Expand Down Expand Up @@ -769,6 +772,7 @@ impl Options {
generate_link_to_definition,
call_locations,
no_emit_shared: false,
html_no_source,
};
Ok((options, render_options))
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
generate_link_to_definition,
call_locations,
no_emit_shared,
html_no_source,
..
} = options;

Expand All @@ -488,7 +489,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
scrape_examples_extension: !call_locations.is_empty(),
};
let mut issue_tracker_base_url = None;
let mut include_sources = true;
let mut include_sources = !html_no_source;

// Crawl the crate attributes looking for attributes which control how we're
// going to emit HTML
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ fn opts() -> Vec<RustcOptGroup> {
"[rust]",
)
}),
unstable("html-no-source", |o| {
o.optflag("", "html-no-source", "Disable HTML source code pages generation")
}),
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ Options:
removed, see issue #44136
<https://github.com/rust-lang/rust/issues/44136> for
more information
--html-no-source
Disable HTML source code pages generation

@path Read newline separated options from `path`

Expand Down
30 changes: 30 additions & 0 deletions tests/rustdoc/html-no-source.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// compile-flags: -Zunstable-options --html-no-source

// This test ensures that the `--html-no-source` flag disables
// the creation of the `src` folder.

#![feature(staged_api)]
#![stable(feature = "bar", since = "1.0")]
#![crate_name = "foo"]

// Ensures that there is no items in the corresponding "src" folder.
// @files 'src/foo' '[]'

// @has foo/fn.foo.html
// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · '
// @!has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source · '
#[stable(feature = "bar", since = "1.0")]
pub fn foo() {}

// @has foo/struct.Bar.html
// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · '
// @!has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source · '
#[stable(feature = "bar", since = "1.0")]
pub struct Bar;

impl Bar {
// @has - '//*[@id="method.bar"]/*[@class="since rightside"]' '2.0'
// @!has - '//*[@id="method.bar"]/*[@class="rightside"]' '2.0 ·'
#[stable(feature = "foobar", since = "2.0")]
pub fn bar() {}
}