Skip to content

Commit

Permalink
[wip] try to process impl blocks in collect pass
Browse files Browse the repository at this point in the history
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

this is so curseeeeeeed

currently failing:
- rustdoc/doc-cfg-simplification.rs
- rustdoc/intra-doc-crate/self.rs
  • Loading branch information
jyn514 committed Mar 26, 2022
1 parent b9085ad commit 53d7f95
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ crate fn run_global_ctxt(
rustc_errors::FatalError.raise();
}

ctxt.cache.populate_impls(&krate);

(krate, ctxt.render_options, ctxt.cache)
}

Expand Down
19 changes: 17 additions & 2 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,17 @@ impl Cache {
}
}
}
// god what a mess
*krate.external_traits.borrow_mut() = mem::take(&mut cx.cache.traits);

krate
}

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

impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
Expand Down Expand Up @@ -462,7 +470,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
}
}
}
let impl_item = Impl { impl_item: item.clone() };
let impl_item = Impl { impl_item: item };
if impl_item.trait_did().map_or(true, |d| self.cache.traits.contains_key(&d)) {
for did in dids {
self.cache.impls.entry(did).or_insert_with(Vec::new).push(impl_item.clone());
Expand All @@ -472,7 +480,14 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item.clone()));
}
// TODO: stripping this from `Module` seems ... not great
Some(impl_item.impl_item)
// None
let item = impl_item.impl_item;
if item.def_id.is_local() {
debug!("propagating impl {:?}", item);
Some(item)
} else {
None
}
} else {
Some(item)
};
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/formats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ crate enum RenderMode {

/// Metadata about implementations for a type or trait.
#[derive(Clone, Debug)]
// TODO: this should not exist
crate struct Impl {
crate impl_item: clean::Item,
}
Expand Down
5 changes: 0 additions & 5 deletions src/librustdoc/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ crate trait DocVisitor: Sized {

fn visit_mod(&mut self, m: &Module) {
m.items.iter().for_each(|i| self.visit_item(i));
// for i in self.cache.impls {
// if m.def_id() == find_nearest_parent_module(self.tcx, i.def_id) {
// self.visit_item(i);
// }
// }
}

fn visit_crate(&mut self, c: &Crate) {
Expand Down
19 changes: 1 addition & 18 deletions src/test/rustdoc-ui/assoc-item-not-in-scope.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
warning: documentation for `f` links to item `S::fmt` which will not have documentation generated
--> $DIR/assoc-item-not-in-scope.rs:12:18
|
LL | /// Link to [`S::fmt`]
| ^^^^^^^^ this item is will not be documented
|
= note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
= note: `S::fmt` may be in a private module with all re-exports marked as `#[doc(no_inline)]`

warning: documentation for `f` links to item `S::fmt` which will not have documentation generated
--> $DIR/assoc-item-not-in-scope.rs:20:18
|
LL | /// Link to [`S::fmt`]
| ^^^^^^^^ this item is will not be documented
|
= note: `S::fmt` may be in a private module with all re-exports marked as `#[doc(no_inline)]`

error: unresolved link to `S::fmt`
--> $DIR/assoc-item-not-in-scope.rs:4:15
|
Expand All @@ -27,5 +10,5 @@ note: the lint level is defined here
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error; 2 warnings emitted
error: aborting due to previous error

1 change: 1 addition & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,7 @@ impl<'test> TestCx<'test> {
.arg(out_dir)
.arg("--deny")
.arg("warnings")
.arg("-Arustdoc::private-intra-doc-links")
.arg(&self.testpaths.file)
.args(&self.props.compile_flags);

Expand Down

0 comments on commit 53d7f95

Please sign in to comment.