Skip to content

Commit 5cbc00f

Browse files
Rollup merge of rust-lang#115135 - GuillaumeGomez:no-html-source-flag, r=notriddle
Rustdoc: Add unstable --no-html-source flag Fixes rust-lang#115060. This is the equivalent of `#![doc(no_html_source)]` but on the command-line. It disables the generation of the source pages (and of the links pointing to them as well). The motivation behind this is to enable to reduce documentation size when generating it in some locations without enforcing this to end users or adding a new feature to enable/disable the crate attribute. r? `@notriddle`
2 parents b88610f + 73ccfc5 commit 5cbc00f

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

src/librustdoc/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ pub(crate) struct RenderOptions {
273273
pub(crate) call_locations: AllCallLocations,
274274
/// If `true`, Context::init will not emit shared files.
275275
pub(crate) no_emit_shared: bool,
276+
/// If `true`, HTML source code pages won't be generated.
277+
pub(crate) html_no_source: bool,
276278
}
277279

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

690693
if generate_link_to_definition && (show_coverage || output_format != OutputFormat::Html) {
691694
diag.struct_err(
@@ -769,6 +772,7 @@ impl Options {
769772
generate_link_to_definition,
770773
call_locations,
771774
no_emit_shared: false,
775+
html_no_source,
772776
};
773777
Ok((options, render_options))
774778
}

src/librustdoc/html/render/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
463463
generate_link_to_definition,
464464
call_locations,
465465
no_emit_shared,
466+
html_no_source,
466467
..
467468
} = options;
468469

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

493494
// Crawl the crate attributes looking for attributes which control how we're
494495
// going to emit HTML

src/librustdoc/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ fn opts() -> Vec<RustcOptGroup> {
656656
"[rust]",
657657
)
658658
}),
659+
unstable("html-no-source", |o| {
660+
o.optflag("", "html-no-source", "Disable HTML source code pages generation")
661+
}),
659662
]
660663
}
661664

tests/run-make/issue-88756-default-output/output-default.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ Options:
191191
removed, see issue #44136
192192
<https://github.com/rust-lang/rust/issues/44136> for
193193
more information
194+
--html-no-source
195+
Disable HTML source code pages generation
194196

195197
@path Read newline separated options from `path`
196198

tests/rustdoc/html-no-source.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// compile-flags: -Zunstable-options --html-no-source
2+
3+
// This test ensures that the `--html-no-source` flag disables
4+
// the creation of the `src` folder.
5+
6+
#![feature(staged_api)]
7+
#![stable(feature = "bar", since = "1.0")]
8+
#![crate_name = "foo"]
9+
10+
// Ensures that there is no items in the corresponding "src" folder.
11+
// @files 'src/foo' '[]'
12+
13+
// @has foo/fn.foo.html
14+
// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · '
15+
// @!has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source · '
16+
#[stable(feature = "bar", since = "1.0")]
17+
pub fn foo() {}
18+
19+
// @has foo/struct.Bar.html
20+
// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · '
21+
// @!has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source · '
22+
#[stable(feature = "bar", since = "1.0")]
23+
pub struct Bar;
24+
25+
impl Bar {
26+
// @has - '//*[@id="method.bar"]/*[@class="since rightside"]' '2.0'
27+
// @!has - '//*[@id="method.bar"]/*[@class="rightside"]' '2.0 ·'
28+
#[stable(feature = "foobar", since = "2.0")]
29+
pub fn bar() {}
30+
}

0 commit comments

Comments
 (0)