From 7ab27c5ed5a3ed71056091f914ff84f98be1d753 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 23 Aug 2023 15:53:48 +0200 Subject: [PATCH 1/3] Add unstable `--no-html-source` rustdoc flag --- src/librustdoc/config.rs | 4 ++++ src/librustdoc/html/render/context.rs | 3 ++- src/librustdoc/lib.rs | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 81fb13f4166bc..1ce7efdfc20ee 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -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)] @@ -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( @@ -769,6 +772,7 @@ impl Options { generate_link_to_definition, call_locations, no_emit_shared: false, + html_no_source, }; Ok((options, render_options)) } diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index d7ff248a9bff5..bb1c186668cd6 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -463,6 +463,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { generate_link_to_definition, call_locations, no_emit_shared, + html_no_source, .. } = options; @@ -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 diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 8220df5d4f373..92e06f3ab0fd4 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -656,6 +656,9 @@ fn opts() -> Vec { "[rust]", ) }), + unstable("html-no-source", |o| { + o.optflag("", "html-no-source", "Disable HTML source code pages generation") + }), ] } From d3f35e96c17de681f091b980eabff49bbd8652dd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 23 Aug 2023 15:54:04 +0200 Subject: [PATCH 2/3] Add test for `--no-html-source` flag --- tests/rustdoc/html-no-source.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/rustdoc/html-no-source.rs diff --git a/tests/rustdoc/html-no-source.rs b/tests/rustdoc/html-no-source.rs new file mode 100644 index 0000000000000..25615a73c3f43 --- /dev/null +++ b/tests/rustdoc/html-no-source.rs @@ -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() {} +} From 73ccfc56832b1948f2656c867744be6438d5ac4b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 23 Aug 2023 16:33:07 +0200 Subject: [PATCH 3/3] Update run-make/issue-88756-default-output test --- tests/run-make/issue-88756-default-output/output-default.stdout | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/issue-88756-default-output/output-default.stdout b/tests/run-make/issue-88756-default-output/output-default.stdout index b280698230dd9..de8ff0e5f89f2 100644 --- a/tests/run-make/issue-88756-default-output/output-default.stdout +++ b/tests/run-make/issue-88756-default-output/output-default.stdout @@ -191,6 +191,8 @@ Options: removed, see issue #44136 for more information + --html-no-source + Disable HTML source code pages generation @path Read newline separated options from `path`