Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2104bf2

Browse files
Add an option for the source code link generation
1 parent 023231a commit 2104bf2

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/librustdoc/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ crate struct RenderOptions {
276276
crate show_type_layout: bool,
277277
crate unstable_features: rustc_feature::UnstableFeatures,
278278
crate emit: Vec<EmitType>,
279+
/// If `true`, HTML source pages will generate links for items to their definition.
280+
crate generate_link_to_definition: bool,
279281
}
280282

281283
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -655,6 +657,7 @@ impl Options {
655657
let generate_redirect_map = matches.opt_present("generate-redirect-map");
656658
let show_type_layout = matches.opt_present("show-type-layout");
657659
let nocapture = matches.opt_present("nocapture");
660+
let generate_link_to_definition = matches.opt_present("generate-link-to-definition");
658661

659662
let (lint_opts, describe_lints, lint_cap) =
660663
get_cmd_lint_options(matches, error_format, &debugging_opts);
@@ -721,6 +724,7 @@ impl Options {
721724
crate_name.as_deref(),
722725
),
723726
emit,
727+
generate_link_to_definition,
724728
},
725729
crate_name,
726730
output_format,

src/librustdoc/html/render/context.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
396396
unstable_features,
397397
generate_redirect_map,
398398
show_type_layout,
399+
generate_link_to_definition,
399400
..
400401
} = options;
401402

@@ -456,8 +457,13 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
456457
}
457458
}
458459

459-
let (mut krate, local_sources, matches) =
460-
collect_spans_and_sources(tcx, krate, &src_root, include_sources);
460+
let (mut krate, local_sources, matches) = collect_spans_and_sources(
461+
tcx,
462+
krate,
463+
&src_root,
464+
include_sources,
465+
generate_link_to_definition,
466+
);
461467

462468
let (sender, receiver) = channel();
463469
let mut scx = SharedContext {

src/librustdoc/html/render/span_map.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ crate fn collect_spans_and_sources(
2020
krate: clean::Crate,
2121
src_root: &std::path::Path,
2222
include_sources: bool,
23+
generate_link_to_definition: bool,
2324
) -> (clean::Crate, FxHashMap<std::path::PathBuf, String>, FxHashMap<(u32, u32), LinkFromSrc>) {
2425
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };
2526

2627
if include_sources {
27-
intravisit::walk_crate(&mut visitor, tcx.hir().krate());
28+
if generate_link_to_definition {
29+
intravisit::walk_crate(&mut visitor, tcx.hir().krate());
30+
}
2831
let (krate, sources) = sources::collect_local_sources(tcx, src_root, krate);
2932
(krate, sources, visitor.matches)
3033
} else {

src/librustdoc/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,13 @@ fn opts() -> Vec<RustcOptGroup> {
607607
unstable("nocapture", |o| {
608608
o.optflag("", "nocapture", "Don't capture stdout and stderr of tests")
609609
}),
610+
unstable("generate-link-to-definition", |o| {
611+
o.optflag(
612+
"",
613+
"generate-link-to-definition",
614+
"Make the identifiers in the HTML source code pages navigable",
615+
)
616+
}),
610617
]
611618
}
612619

0 commit comments

Comments
 (0)