]> git.lizzy.rs Git - rust.git/commitdiff
Add an option for the source code link generation
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 13 Apr 2021 13:52:41 +0000 (15:52 +0200)
committerGuillaume Gomez <guillaume.gomez@huawei.com>
Thu, 5 Aug 2021 21:08:28 +0000 (23:08 +0200)
src/librustdoc/config.rs
src/librustdoc/html/render/context.rs
src/librustdoc/html/render/span_map.rs
src/librustdoc/lib.rs

index abd1fd2bf39a29c13702beaf484680ae232f53f8..99d2039b183afd610f9a8f5e5772d8a3a1639375 100644 (file)
@@ -276,6 +276,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     crate show_type_layout: bool,
     crate unstable_features: rustc_feature::UnstableFeatures,
     crate emit: Vec<EmitType>,
+    /// If `true`, HTML source pages will generate links for items to their definition.
+    crate generate_link_to_definition: bool,
 }
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -655,6 +657,7 @@ fn println_condition(condition: Condition) {
         let generate_redirect_map = matches.opt_present("generate-redirect-map");
         let show_type_layout = matches.opt_present("show-type-layout");
         let nocapture = matches.opt_present("nocapture");
+        let generate_link_to_definition = matches.opt_present("generate-link-to-definition");
 
         let (lint_opts, describe_lints, lint_cap) =
             get_cmd_lint_options(matches, error_format, &debugging_opts);
@@ -721,6 +724,7 @@ fn println_condition(condition: Condition) {
                     crate_name.as_deref(),
                 ),
                 emit,
+                generate_link_to_definition,
             },
             crate_name,
             output_format,
index 33b10db1f881d346b42edd8c076b0a044b3d81b7..c0668fcce999f8b347826ce8b1f83b83d9b59238 100644 (file)
@@ -396,6 +396,7 @@ fn init(
             unstable_features,
             generate_redirect_map,
             show_type_layout,
+            generate_link_to_definition,
             ..
         } = options;
 
@@ -456,8 +457,13 @@ fn init(
             }
         }
 
-        let (mut krate, local_sources, matches) =
-            collect_spans_and_sources(tcx, krate, &src_root, include_sources);
+        let (mut krate, local_sources, matches) = collect_spans_and_sources(
+            tcx,
+            krate,
+            &src_root,
+            include_sources,
+            generate_link_to_definition,
+        );
 
         let (sender, receiver) = channel();
         let mut scx = SharedContext {
index c7c8fa7cc45cd257e2d70a4ab0472683c84331e3..fa1f8954a158613390323edcb2b00a5dd3320f70 100644 (file)
     krate: clean::Crate,
     src_root: &std::path::Path,
     include_sources: bool,
+    generate_link_to_definition: bool,
 ) -> (clean::Crate, FxHashMap<std::path::PathBuf, String>, FxHashMap<(u32, u32), LinkFromSrc>) {
     let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };
 
     if include_sources {
-        intravisit::walk_crate(&mut visitor, tcx.hir().krate());
+        if generate_link_to_definition {
+            intravisit::walk_crate(&mut visitor, tcx.hir().krate());
+        }
         let (krate, sources) = sources::collect_local_sources(tcx, src_root, krate);
         (krate, sources, visitor.matches)
     } else {
index fa755777584f3cdacb58abe4cc4aa6722ce4d7e9..a98725e683cb6d678052602bf490dfc5b0fec64d 100644 (file)
@@ -607,6 +607,13 @@ fn opts() -> Vec<RustcOptGroup> {
         unstable("nocapture", |o| {
             o.optflag("", "nocapture", "Don't capture stdout and stderr of tests")
         }),
+        unstable("generate-link-to-definition", |o| {
+            o.optflag(
+                "",
+                "generate-link-to-definition",
+                "Make the identifiers in the HTML source code pages navigable",
+            )
+        }),
     ]
 }