Skip to content

Commit 86ceab4

Browse files
Rollup merge of #63453 - Mark-Simulacrum:rustdoc-clean-2, r=GuillaumeGomez
rustdoc: general cleanup Almost all commits stand alone; but all commits can be reviewed individually.
2 parents e16b12f + 3b8a24d commit 86ceab4

20 files changed

+322
-348
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3252,7 +3252,6 @@ name = "rustdoc"
32523252
version = "0.0.0"
32533253
dependencies = [
32543254
"minifier 0.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
3255-
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
32563255
"pulldown-cmark 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
32573256
"rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
32583257
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",

src/librustdoc/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ pulldown-cmark = { version = "0.5.3", default-features = false }
1313
minifier = "0.0.33"
1414
rayon = { version = "0.2.0", package = "rustc-rayon" }
1515
tempfile = "3"
16-
parking_lot = "0.7"

src/librustdoc/clean/blanket_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc::traits;
33
use rustc::ty::ToPredicate;
44
use rustc::ty::subst::Subst;
55
use rustc::infer::InferOk;
6+
use rustc::hir::def_id::LOCAL_CRATE;
67
use syntax_pos::DUMMY_SP;
78

89
use super::*;
@@ -27,7 +28,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
2728

2829
debug!("get_blanket_impls({:?})", ty);
2930
let mut impls = Vec::new();
30-
for &trait_def_id in self.cx.all_traits.iter() {
31+
for &trait_def_id in self.cx.tcx.all_traits(LOCAL_CRATE).iter() {
3132
if !self.cx.renderinfo.borrow().access_levels.is_public(trait_def_id) ||
3233
self.cx.generated_synthetics
3334
.borrow_mut()

src/librustdoc/clean/inline.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ pub fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> Attrs<'hir> {
163163
/// These names are used later on by HTML rendering to generate things like
164164
/// source links back to the original item.
165165
pub fn record_extern_fqn(cx: &DocContext<'_>, did: DefId, kind: clean::TypeKind) {
166-
let mut crate_name = cx.tcx.crate_name(did.krate).to_string();
167-
if did.is_local() {
168-
crate_name = cx.crate_name.clone().unwrap_or(crate_name);
169-
}
166+
let crate_name = cx.tcx.crate_name(did.krate).to_string();
170167

171168
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
172169
// extern blocks have an empty name
@@ -577,22 +574,18 @@ pub fn record_extern_trait(cx: &DocContext<'_>, did: DefId) {
577574
}
578575

579576
{
580-
let external_traits = cx.external_traits.lock();
581-
if external_traits.borrow().contains_key(&did) ||
577+
if cx.external_traits.borrow().contains_key(&did) ||
582578
cx.active_extern_traits.borrow().contains(&did)
583579
{
584580
return;
585581
}
586582
}
587583

588-
cx.active_extern_traits.borrow_mut().push(did);
584+
cx.active_extern_traits.borrow_mut().insert(did);
589585

590586
debug!("record_extern_trait: {:?}", did);
591587
let trait_ = build_external_trait(cx, did);
592588

593-
{
594-
let external_traits = cx.external_traits.lock();
595-
external_traits.borrow_mut().insert(did, trait_);
596-
}
597-
cx.active_extern_traits.borrow_mut().remove_item(&did);
589+
cx.external_traits.borrow_mut().insert(did, trait_);
590+
cx.active_extern_traits.borrow_mut().remove(&did);
598591
}

src/librustdoc/clean/mod.rs

+4-22
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ use std::fmt;
3939
use std::hash::{Hash, Hasher};
4040
use std::default::Default;
4141
use std::{mem, slice, vec};
42-
use std::iter::{FromIterator, once};
42+
use std::iter::FromIterator;
4343
use std::rc::Rc;
4444
use std::cell::RefCell;
4545
use std::sync::Arc;
4646
use std::u32;
4747

48-
use parking_lot::ReentrantMutex;
49-
5048
use crate::core::{self, DocContext};
5149
use crate::doctree;
5250
use crate::html::render::{cache, ExternalLocation};
@@ -133,8 +131,9 @@ pub struct Crate {
133131
pub primitives: Vec<(DefId, PrimitiveType, Attributes)>,
134132
// These are later on moved into `CACHEKEY`, leaving the map empty.
135133
// Only here so that they can be filtered through the rustdoc passes.
136-
pub external_traits: Arc<ReentrantMutex<RefCell<FxHashMap<DefId, Trait>>>>,
134+
pub external_traits: Rc<RefCell<FxHashMap<DefId, Trait>>>,
137135
pub masked_crates: FxHashSet<CrateNum>,
136+
pub collapsed: bool,
138137
}
139138

140139
impl Clean<Crate> for hir::Crate {
@@ -223,6 +222,7 @@ impl Clean<Crate> for hir::Crate {
223222
primitives,
224223
external_traits: cx.external_traits.clone(),
225224
masked_crates,
225+
collapsed: false,
226226
}
227227
}
228228
}
@@ -4398,24 +4398,6 @@ impl Clean<TypeBindingKind> for hir::TypeBindingKind {
43984398
}
43994399
}
44004400

4401-
pub fn def_id_to_path(
4402-
cx: &DocContext<'_>,
4403-
did: DefId,
4404-
name: Option<String>
4405-
) -> Vec<String> {
4406-
let crate_name = name.unwrap_or_else(|| cx.tcx.crate_name(did.krate).to_string());
4407-
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
4408-
// extern blocks have an empty name
4409-
let s = elem.data.to_string();
4410-
if !s.is_empty() {
4411-
Some(s)
4412-
} else {
4413-
None
4414-
}
4415-
});
4416-
once(crate_name).chain(relative).collect()
4417-
}
4418-
44194401
pub fn enter_impl_trait<F, R>(cx: &DocContext<'_>, f: F) -> R
44204402
where
44214403
F: FnOnce() -> R,

src/librustdoc/config.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,22 @@ impl Options {
220220
println!("{:>20} - {}", pass.name, pass.description);
221221
}
222222
println!("\nDefault passes for rustdoc:");
223-
for &name in passes::DEFAULT_PASSES {
224-
println!("{:>20}", name);
223+
for pass in passes::DEFAULT_PASSES {
224+
println!("{:>20}", pass.name);
225225
}
226226
println!("\nPasses run with `--document-private-items`:");
227-
for &name in passes::DEFAULT_PRIVATE_PASSES {
228-
println!("{:>20}", name);
227+
for pass in passes::DEFAULT_PRIVATE_PASSES {
228+
println!("{:>20}", pass.name);
229229
}
230230

231231
if nightly_options::is_nightly_build() {
232232
println!("\nPasses run with `--show-coverage`:");
233-
for &name in passes::DEFAULT_COVERAGE_PASSES {
234-
println!("{:>20}", name);
233+
for pass in passes::DEFAULT_COVERAGE_PASSES {
234+
println!("{:>20}", pass.name);
235235
}
236236
println!("\nPasses run with `--show-coverage --document-private-items`:");
237-
for &name in passes::PRIVATE_COVERAGE_PASSES {
238-
println!("{:>20}", name);
237+
for pass in passes::PRIVATE_COVERAGE_PASSES {
238+
println!("{:>20}", pass.name);
239239
}
240240
}
241241

@@ -378,7 +378,7 @@ impl Options {
378378
&matches.opt_strs("html-after-content"),
379379
&matches.opt_strs("markdown-before-content"),
380380
&matches.opt_strs("markdown-after-content"),
381-
&diag, &mut id_map, edition) {
381+
&diag, &mut id_map, edition, &None) {
382382
Some(eh) => eh,
383383
None => return Err(3),
384384
};

src/librustdoc/core.rs

+20-27
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ use syntax::json::JsonEmitter;
2222
use syntax::symbol::sym;
2323
use errors;
2424
use errors::emitter::{Emitter, EmitterWriter};
25-
use parking_lot::ReentrantMutex;
2625

2726
use std::cell::RefCell;
2827
use std::mem;
2928
use rustc_data_structures::sync::{self, Lrc};
30-
use std::sync::Arc;
3129
use std::rc::Rc;
3230

3331
use crate::config::{Options as RustdocOptions, RenderOptions};
@@ -46,16 +44,14 @@ pub struct DocContext<'tcx> {
4644

4745
pub tcx: TyCtxt<'tcx>,
4846
pub resolver: Rc<RefCell<interface::BoxedResolver>>,
49-
/// The stack of module NodeIds up till this point
50-
pub crate_name: Option<String>,
5147
pub cstore: Lrc<CStore>,
5248
/// Later on moved into `html::render::CACHE_KEY`
5349
pub renderinfo: RefCell<RenderInfo>,
5450
/// Later on moved through `clean::Crate` into `html::render::CACHE_KEY`
55-
pub external_traits: Arc<ReentrantMutex<RefCell<FxHashMap<DefId, clean::Trait>>>>,
51+
pub external_traits: Rc<RefCell<FxHashMap<DefId, clean::Trait>>>,
5652
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
5753
/// the same time.
58-
pub active_extern_traits: RefCell<Vec<DefId>>,
54+
pub active_extern_traits: RefCell<FxHashSet<DefId>>,
5955
// The current set of type and lifetime substitutions,
6056
// for expanding type aliases at the HIR level:
6157

@@ -72,7 +68,6 @@ pub struct DocContext<'tcx> {
7268
/// Auto-trait or blanket impls processed so far, as `(self_ty, trait_def_id)`.
7369
// FIXME(eddyb) make this a `ty::TraitRef<'tcx>` set.
7470
pub generated_synthetics: RefCell<FxHashSet<(Ty<'tcx>, DefId)>>,
75-
pub all_traits: Vec<DefId>,
7671
pub auto_traits: Vec<DefId>,
7772
}
7873

@@ -227,7 +222,7 @@ pub fn new_handler(error_format: ErrorOutputType,
227222
)
228223
}
229224

230-
pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions, Vec<String>) {
225+
pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions) {
231226
// Parse, resolve, and typecheck the given crate.
232227

233228
let RustdocOptions {
@@ -332,7 +327,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
332327
file_loader: None,
333328
diagnostic_output: DiagnosticOutput::Default,
334329
stderr: None,
335-
crate_name: crate_name.clone(),
330+
crate_name,
336331
lint_caps,
337332
};
338333

@@ -368,11 +363,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
368363
let mut renderinfo = RenderInfo::default();
369364
renderinfo.access_levels = access_levels;
370365

371-
let all_traits = tcx.all_traits(LOCAL_CRATE).to_vec();
372366
let ctxt = DocContext {
373367
tcx,
374368
resolver,
375-
crate_name,
376369
cstore: compiler.cstore().clone(),
377370
external_traits: Default::default(),
378371
active_extern_traits: Default::default(),
@@ -384,10 +377,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
384377
fake_def_ids: Default::default(),
385378
all_fake_def_ids: Default::default(),
386379
generated_synthetics: Default::default(),
387-
auto_traits: all_traits.iter().cloned().filter(|trait_def_id| {
380+
auto_traits: tcx.all_traits(LOCAL_CRATE).iter().cloned().filter(|trait_def_id| {
388381
tcx.trait_is_auto(*trait_def_id)
389382
}).collect(),
390-
all_traits,
391383
};
392384
debug!("crate: {:?}", tcx.hir().krate());
393385

@@ -432,8 +424,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
432424
},
433425
_ => continue,
434426
};
435-
for p in value.as_str().split_whitespace() {
436-
sink.push(p.to_string());
427+
for name in value.as_str().split_whitespace() {
428+
sink.push(name.to_string());
437429
}
438430
}
439431

@@ -444,25 +436,26 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
444436
}
445437
}
446438

447-
let mut passes: Vec<String> =
448-
passes::defaults(default_passes).iter().map(|p| p.to_string()).collect();
449-
passes.extend(manual_passes);
439+
let passes = passes::defaults(default_passes).iter().chain(manual_passes.into_iter()
440+
.flat_map(|name| {
441+
if let Some(pass) = passes::find_pass(&name) {
442+
Some(pass)
443+
} else {
444+
error!("unknown pass {}, skipping", name);
445+
None
446+
}
447+
}));
450448

451449
info!("Executing passes");
452450

453-
for pass_name in &passes {
454-
match passes::find_pass(pass_name).map(|p| p.pass) {
455-
Some(pass) => {
456-
debug!("running pass {}", pass_name);
457-
krate = pass(krate, &ctxt);
458-
}
459-
None => error!("unknown pass {}, skipping", *pass_name),
460-
}
451+
for pass in passes {
452+
debug!("running pass {}", pass.name);
453+
krate = (pass.pass)(krate, &ctxt);
461454
}
462455

463456
ctxt.sess().abort_if_errors();
464457

465-
(krate, ctxt.renderinfo.into_inner(), render_options, passes)
458+
(krate, ctxt.renderinfo.into_inner(), render_options)
466459
})
467460
})
468461
}

0 commit comments

Comments
 (0)