Skip to content

Commit adc02e4

Browse files
Add --no-source option flag to rustdoc
1 parent ccd9975 commit adc02e4

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/librustdoc/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ crate struct RenderOptions {
268268
crate generate_redirect_map: bool,
269269
crate unstable_features: rustc_feature::UnstableFeatures,
270270
crate emit: Vec<EmitType>,
271+
/// Whether the source code should be rendered as HTML.
272+
pub no_source: bool,
271273
}
272274

273275
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -622,6 +624,7 @@ impl Options {
622624
let document_hidden = matches.opt_present("document-hidden-items");
623625
let run_check = matches.opt_present("check");
624626
let generate_redirect_map = matches.opt_present("generate-redirect-map");
627+
let no_source = matches.opt_present("no-source");
625628

626629
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
627630

@@ -684,6 +687,7 @@ impl Options {
684687
crate_name.as_deref(),
685688
),
686689
emit,
690+
no_source,
687691
},
688692
crate_name,
689693
output_format,

src/librustdoc/html/render/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
331331
generate_search_filter,
332332
};
333333
let mut issue_tracker_base_url = None;
334-
let mut include_sources = true;
334+
let mut include_sources = !options.no_source;
335335

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

src/librustdoc/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@ fn opts() -> Vec<RustcOptGroup> {
533533
"emit",
534534
"Comma separated list of types of output for rustdoc to emit",
535535
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
536+
stable("no-source", |o| {
537+
o.optflag(
538+
"",
539+
"no-source",
540+
"Prevent source code generation in HTML output format generation. \
541+
This is the same as using the `#![doc(html_no_source)]` attribute.",
536542
)
537543
}),
538544
]

0 commit comments

Comments
 (0)