Skip to content

Commit 53d7f95

Browse files
committed
[wip] try to process impl blocks in collect pass
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh this is so curseeeeeeed currently failing: - rustdoc/doc-cfg-simplification.rs - rustdoc/intra-doc-crate/self.rs
1 parent b9085ad commit 53d7f95

File tree

6 files changed

+22
-25
lines changed

6 files changed

+22
-25
lines changed

src/librustdoc/core.rs

+2
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ crate fn run_global_ctxt(
467467
rustc_errors::FatalError.raise();
468468
}
469469

470+
ctxt.cache.populate_impls(&krate);
471+
470472
(krate, ctxt.render_options, ctxt.cache)
471473
}
472474

src/librustdoc/formats/cache.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,17 @@ impl Cache {
179179
}
180180
}
181181
}
182+
// god what a mess
183+
*krate.external_traits.borrow_mut() = mem::take(&mut cx.cache.traits);
182184

183185
krate
184186
}
187+
188+
/// `external_trats` / `cache.traits` is modified in various passes.
189+
/// Run this separate from the main `populate` call, since `impls` isn't used until later in the HTML formatter.
190+
crate fn populate_impls(&mut self, krate: &clean::Crate) {
191+
self.traits = krate.external_traits.take();
192+
}
185193
}
186194

187195
impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
@@ -462,7 +470,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
462470
}
463471
}
464472
}
465-
let impl_item = Impl { impl_item: item.clone() };
473+
let impl_item = Impl { impl_item: item };
466474
if impl_item.trait_did().map_or(true, |d| self.cache.traits.contains_key(&d)) {
467475
for did in dids {
468476
self.cache.impls.entry(did).or_insert_with(Vec::new).push(impl_item.clone());
@@ -472,7 +480,14 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
472480
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item.clone()));
473481
}
474482
// TODO: stripping this from `Module` seems ... not great
475-
Some(impl_item.impl_item)
483+
// None
484+
let item = impl_item.impl_item;
485+
if item.def_id.is_local() {
486+
debug!("propagating impl {:?}", item);
487+
Some(item)
488+
} else {
489+
None
490+
}
476491
} else {
477492
Some(item)
478493
};

src/librustdoc/formats/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ crate enum RenderMode {
2525

2626
/// Metadata about implementations for a type or trait.
2727
#[derive(Clone, Debug)]
28+
// TODO: this should not exist
2829
crate struct Impl {
2930
crate impl_item: clean::Item,
3031
}

src/librustdoc/visit.rs

-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ crate trait DocVisitor: Sized {
5656

5757
fn visit_mod(&mut self, m: &Module) {
5858
m.items.iter().for_each(|i| self.visit_item(i));
59-
// for i in self.cache.impls {
60-
// if m.def_id() == find_nearest_parent_module(self.tcx, i.def_id) {
61-
// self.visit_item(i);
62-
// }
63-
// }
6459
}
6560

6661
fn visit_crate(&mut self, c: &Crate) {
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
warning: documentation for `f` links to item `S::fmt` which will not have documentation generated
2-
--> $DIR/assoc-item-not-in-scope.rs:12:18
3-
|
4-
LL | /// Link to [`S::fmt`]
5-
| ^^^^^^^^ this item is will not be documented
6-
|
7-
= note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
8-
= note: `S::fmt` may be in a private module with all re-exports marked as `#[doc(no_inline)]`
9-
10-
warning: documentation for `f` links to item `S::fmt` which will not have documentation generated
11-
--> $DIR/assoc-item-not-in-scope.rs:20:18
12-
|
13-
LL | /// Link to [`S::fmt`]
14-
| ^^^^^^^^ this item is will not be documented
15-
|
16-
= note: `S::fmt` may be in a private module with all re-exports marked as `#[doc(no_inline)]`
17-
181
error: unresolved link to `S::fmt`
192
--> $DIR/assoc-item-not-in-scope.rs:4:15
203
|
@@ -27,5 +10,5 @@ note: the lint level is defined here
2710
LL | #![deny(rustdoc::broken_intra_doc_links)]
2811
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2912

30-
error: aborting due to previous error; 2 warnings emitted
13+
error: aborting due to previous error
3114

src/tools/compiletest/src/runtest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ impl<'test> TestCx<'test> {
14901490
.arg(out_dir)
14911491
.arg("--deny")
14921492
.arg("warnings")
1493+
.arg("-Arustdoc::private-intra-doc-links")
14931494
.arg(&self.testpaths.file)
14941495
.args(&self.props.compile_flags);
14951496

0 commit comments

Comments
 (0)