Skip to content

Commit c112ed4

Browse files
committed
restored librustdoc to upstream version
1 parent b70cf36 commit c112ed4

File tree

11 files changed

+766
-1734
lines changed

11 files changed

+766
-1734
lines changed

src/librustdoc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ minifier = "0.3.0"
1616
pulldown-cmark-old = { version = "0.9.6", package = "pulldown-cmark", default-features = false }
1717
regex = "1"
1818
rustdoc-json-types = { path = "../rustdoc-json-types" }
19-
serde_json = { version = "1.0", features = ["preserve_order"] }
19+
serde_json = "1.0"
2020
serde = { version = "1.0", features = ["derive"] }
2121
smallvec = "1.8.1"
2222
tempfile = "3"

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub(crate) struct ExternalCrate {
133133
}
134134

135135
impl ExternalCrate {
136-
pub(crate) const LOCAL: Self = Self { crate_num: LOCAL_CRATE };
136+
const LOCAL: Self = Self { crate_num: LOCAL_CRATE };
137137

138138
#[inline]
139139
pub(crate) fn def_id(&self) -> DefId {

src/librustdoc/config.rs

-65
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,6 @@ pub(crate) struct RenderOptions {
292292
pub(crate) no_emit_shared: bool,
293293
/// If `true`, HTML source code pages won't be generated.
294294
pub(crate) html_no_source: bool,
295-
/// If `true` (default) read the shared cross-crate information from the doc root for output
296-
pub(crate) read_rendered_cci: bool,
297-
/// If `true` (default) write the shared cross-crate information to the doc root
298-
pub(crate) write_rendered_cci: bool,
299-
/// Copies these externally documented crates into our doc root.
300-
pub(crate) include_rendered_docs: Vec<PathToDocRoot>,
301-
/// Path to crate-info.json for external crates.
302-
pub(crate) parts_paths: Vec<PathToParts>,
303-
/// Where to write crate-info.json.
304-
pub(crate) parts_out_dir: Option<PathToParts>,
305295
}
306296

307297
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -506,17 +496,6 @@ impl Options {
506496
Err(err) => dcx.fatal(err),
507497
};
508498

509-
let include_rendered_docs = matches
510-
.opt_strs("include-rendered-docs")
511-
.into_iter()
512-
.map(|p| PathToDocRoot(PathBuf::from(p)))
513-
.collect();
514-
let parts_paths = matches
515-
.opt_strs("include-info-json")
516-
.into_iter()
517-
.map(|path| PathToParts(PathBuf::from(path)))
518-
.collect();
519-
520499
let default_settings: Vec<Vec<(String, String)>> = vec![
521500
matches
522501
.opt_str("default-theme")
@@ -757,12 +736,6 @@ impl Options {
757736
let extern_html_root_takes_precedence =
758737
matches.opt_present("extern-html-root-takes-precedence");
759738
let html_no_source = matches.opt_present("html-no-source");
760-
let ShouldMerge { read_rendered_cci, write_rendered_cci } = match parse_merge(matches) {
761-
Ok(result) => result,
762-
Err(e) => dcx.fatal(format!("could not parse --merge: {e}")),
763-
};
764-
let parts_out_dir =
765-
matches.opt_str("write-info-json").map(|p| PathToParts(PathBuf::from(p)));
766739

767740
if generate_link_to_definition && (show_coverage || output_format != OutputFormat::Html) {
768741
dcx.fatal(
@@ -848,11 +821,6 @@ impl Options {
848821
call_locations,
849822
no_emit_shared: false,
850823
html_no_source,
851-
read_rendered_cci,
852-
write_rendered_cci,
853-
parts_paths,
854-
include_rendered_docs,
855-
parts_out_dir,
856824
};
857825
Some((options, render_options))
858826
}
@@ -930,36 +898,3 @@ fn parse_extern_html_roots(
930898
}
931899
Ok(externs)
932900
}
933-
934-
/// Path to the doc root for a specific crate, for example `target/doc/serde_json`.
935-
#[derive(Clone, Debug)]
936-
pub(crate) struct PathToDocRoot(pub PathBuf);
937-
938-
/// Path to crate-info.json
939-
///
940-
/// For example, `/home/user/project/target/doc.parts/<crate>/crate-info.json`.
941-
#[derive(Clone, Debug)]
942-
pub(crate) struct PathToParts(pub(crate) PathBuf);
943-
944-
/// Controls merging of cross-crate information
945-
struct ShouldMerge {
946-
/// Should we append to existing cci in the doc root
947-
read_rendered_cci: bool,
948-
/// Should we write cci to the doc root
949-
write_rendered_cci: bool,
950-
}
951-
952-
/// Extracts read_rendered_cci and write_rendered_cci from command line arguments, or
953-
/// reports an error.
954-
fn parse_merge(matches: &getopts::Matches) -> Result<ShouldMerge, &'static str> {
955-
match matches.opt_str("merge").as_deref() {
956-
// default = read-write
957-
None => Ok(ShouldMerge { read_rendered_cci: true, write_rendered_cci: true }),
958-
Some("read-write") => Ok(ShouldMerge { read_rendered_cci: true, write_rendered_cci: true }),
959-
Some("none") => Ok(ShouldMerge { read_rendered_cci: false, write_rendered_cci: false }),
960-
Some("write-only") => {
961-
Ok(ShouldMerge { read_rendered_cci: false, write_rendered_cci: true })
962-
}
963-
Some(_) => Err("argument to --merge must be `read-write`, `none`, or `write-only`"),
964-
}
965-
}

src/librustdoc/html/render/context.rs

+89-98
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use rustc_session::Session;
1212
use rustc_span::edition::Edition;
1313
use rustc_span::{sym, FileName, Symbol};
1414

15-
use super::copy_dir::copy_dir_all;
1615
use super::print_item::{full_path, item_path, print_item};
16+
use super::search_index::build_index;
1717
use super::write_shared::write_shared;
1818
use super::{
1919
collect_spans_and_sources, scrape_examples_help,
@@ -133,8 +133,6 @@ pub(crate) struct SharedContext<'tcx> {
133133
pub(crate) cache: Cache,
134134

135135
pub(crate) call_locations: AllCallLocations,
136-
/// Controls whether we write to the doc root. Default is true from cli.
137-
write_rendered_cci: bool,
138136
}
139137

140138
impl SharedContext<'_> {
@@ -471,7 +469,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
471469
call_locations,
472470
no_emit_shared,
473471
html_no_source,
474-
include_rendered_docs,
475472
..
476473
} = options;
477474

@@ -557,7 +554,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
557554
span_correspondence_map: matches,
558555
cache,
559556
call_locations,
560-
write_rendered_cci: options.write_rendered_cci,
561557
};
562558

563559
let dst = output;
@@ -575,16 +571,18 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
575571
is_inside_inlined_module: false,
576572
};
577573

578-
for extern_docs in include_rendered_docs.iter() {
579-
try_err!(copy_dir_all(&extern_docs.0, &cx.dst), &extern_docs.0);
580-
}
581-
582574
if emit_crate {
583575
sources::render(&mut cx, &krate)?;
584576
}
585577

586578
if !no_emit_shared {
587-
write_shared(&mut cx, &krate, &md_opts, tcx)?;
579+
// Build our search index
580+
let index = build_index(&krate, &mut Rc::get_mut(&mut cx.shared).unwrap().cache, tcx);
581+
582+
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
583+
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true);
584+
write_shared(&mut cx, &krate, index, &md_opts)?;
585+
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false);
588586
}
589587

590588
Ok((cx, krate))
@@ -649,99 +647,92 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
649647
);
650648
shared.fs.write(final_file, v)?;
651649

652-
// if to avoid writing files to doc root unless we're on the final invocation
653-
if shared.write_rendered_cci {
654-
// Generating settings page.
655-
page.title = "Settings";
656-
page.description = "Settings of Rustdoc";
657-
page.root_path = "./";
658-
page.rust_logo = true;
650+
// Generating settings page.
651+
page.title = "Settings";
652+
page.description = "Settings of Rustdoc";
653+
page.root_path = "./";
654+
page.rust_logo = true;
659655

660-
let sidebar = "<h2 class=\"location\">Settings</h2><div class=\"sidebar-elems\"></div>";
661-
let v = layout::render(
662-
&shared.layout,
663-
&page,
664-
sidebar,
665-
|buf: &mut Buffer| {
666-
write!(
667-
buf,
668-
"<div class=\"main-heading\">\
669-
<h1>Rustdoc settings</h1>\
670-
<span class=\"out-of-band\">\
671-
<a id=\"back\" href=\"javascript:void(0)\" onclick=\"history.back();\">\
672-
Back\
673-
</a>\
674-
</span>\
675-
</div>\
676-
<noscript>\
677-
<section>\
678-
You need to enable JavaScript be able to update your settings.\
679-
</section>\
680-
</noscript>\
681-
<script defer src=\"{static_root_path}{settings_js}\"></script>",
682-
static_root_path = page.get_static_root_path(),
683-
settings_js = static_files::STATIC_FILES.settings_js,
684-
);
685-
// Pre-load all theme CSS files, so that switching feels seamless.
686-
//
687-
// When loading settings.html as a popover, the equivalent HTML is
688-
// generated in main.js.
689-
for file in &shared.style_files {
690-
if let Ok(theme) = file.basename() {
691-
write!(
692-
buf,
693-
"<link rel=\"preload\" href=\"{root_path}{theme}{suffix}.css\" \
694-
as=\"style\">",
695-
root_path = page.static_root_path.unwrap_or(""),
696-
suffix = page.resource_suffix,
697-
);
698-
}
656+
let sidebar = "<h2 class=\"location\">Settings</h2><div class=\"sidebar-elems\"></div>";
657+
let v = layout::render(
658+
&shared.layout,
659+
&page,
660+
sidebar,
661+
|buf: &mut Buffer| {
662+
write!(
663+
buf,
664+
"<div class=\"main-heading\">\
665+
<h1>Rustdoc settings</h1>\
666+
<span class=\"out-of-band\">\
667+
<a id=\"back\" href=\"javascript:void(0)\" onclick=\"history.back();\">\
668+
Back\
669+
</a>\
670+
</span>\
671+
</div>\
672+
<noscript>\
673+
<section>\
674+
You need to enable JavaScript be able to update your settings.\
675+
</section>\
676+
</noscript>\
677+
<script defer src=\"{static_root_path}{settings_js}\"></script>",
678+
static_root_path = page.get_static_root_path(),
679+
settings_js = static_files::STATIC_FILES.settings_js,
680+
);
681+
// Pre-load all theme CSS files, so that switching feels seamless.
682+
//
683+
// When loading settings.html as a popover, the equivalent HTML is
684+
// generated in main.js.
685+
for file in &shared.style_files {
686+
if let Ok(theme) = file.basename() {
687+
write!(
688+
buf,
689+
"<link rel=\"preload\" href=\"{root_path}{theme}{suffix}.css\" \
690+
as=\"style\">",
691+
root_path = page.static_root_path.unwrap_or(""),
692+
suffix = page.resource_suffix,
693+
);
699694
}
700-
},
701-
&shared.style_files,
702-
);
703-
shared.fs.write(settings_file, v)?;
704-
}
695+
}
696+
},
697+
&shared.style_files,
698+
);
699+
shared.fs.write(settings_file, v)?;
705700

706-
// if to avoid writing files to doc root unless we're on the final invocation
707-
if shared.write_rendered_cci {
708-
// Generating help page.
709-
page.title = "Help";
710-
page.description = "Documentation for Rustdoc";
711-
page.root_path = "./";
712-
page.rust_logo = true;
701+
// Generating help page.
702+
page.title = "Help";
703+
page.description = "Documentation for Rustdoc";
704+
page.root_path = "./";
705+
page.rust_logo = true;
713706

714-
let sidebar = "<h2 class=\"location\">Help</h2><div class=\"sidebar-elems\"></div>";
715-
let v = layout::render(
716-
&shared.layout,
717-
&page,
718-
sidebar,
719-
|buf: &mut Buffer| {
720-
write!(
721-
buf,
722-
"<div class=\"main-heading\">\
723-
<h1>Rustdoc help</h1>\
724-
<span class=\"out-of-band\">\
725-
<a id=\"back\" href=\"javascript:void(0)\" onclick=\"history.back();\">\
726-
Back\
727-
</a>\
728-
</span>\
729-
</div>\
730-
<noscript>\
731-
<section>\
732-
<p>You need to enable JavaScript to use keyboard commands or search.</p>\
733-
<p>For more information, browse the <a href=\"https://doc.rust-lang.org/rustdoc/\">rustdoc handbook</a>.</p>\
734-
</section>\
735-
</noscript>",
736-
)
737-
},
738-
&shared.style_files,
739-
);
740-
shared.fs.write(help_file, v)?;
741-
}
707+
let sidebar = "<h2 class=\"location\">Help</h2><div class=\"sidebar-elems\"></div>";
708+
let v = layout::render(
709+
&shared.layout,
710+
&page,
711+
sidebar,
712+
|buf: &mut Buffer| {
713+
write!(
714+
buf,
715+
"<div class=\"main-heading\">\
716+
<h1>Rustdoc help</h1>\
717+
<span class=\"out-of-band\">\
718+
<a id=\"back\" href=\"javascript:void(0)\" onclick=\"history.back();\">\
719+
Back\
720+
</a>\
721+
</span>\
722+
</div>\
723+
<noscript>\
724+
<section>\
725+
<p>You need to enable JavaScript to use keyboard commands or search.</p>\
726+
<p>For more information, browse the <a href=\"https://doc.rust-lang.org/rustdoc/\">rustdoc handbook</a>.</p>\
727+
</section>\
728+
</noscript>",
729+
)
730+
},
731+
&shared.style_files,
732+
);
733+
shared.fs.write(help_file, v)?;
742734

743-
// if to avoid writing files to doc root unless we're on the final invocation
744-
if shared.layout.scrape_examples_extension && shared.write_rendered_cci {
735+
if shared.layout.scrape_examples_extension {
745736
page.title = "About scraped examples";
746737
page.description = "How the scraped examples feature works in Rustdoc";
747738
let v = layout::render(

0 commit comments

Comments
 (0)