Skip to content

rustdoc: strip trait impls of stripped types #12195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 61 additions & 21 deletions src/librustdoc/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,62 @@ use fold::DocFolder;

/// Strip items marked `#[doc(hidden)]`
pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
struct Stripper;
impl fold::DocFolder for Stripper {
fn fold_item(&mut self, i: Item) -> Option<Item> {
for attr in i.attrs.iter() {
match attr {
&clean::List(~"doc", ref l) => {
for innerattr in l.iter() {
match innerattr {
&clean::Word(ref s) if "hidden" == *s => {
debug!("found one in strip_hidden; removing");
return None;
},
_ => (),
let mut stripped = HashSet::new();

// strip all #[doc(hidden)] items
let krate = {
struct Stripper<'a> {
stripped: &'a mut HashSet<ast::NodeId>
};
impl<'a> fold::DocFolder for Stripper<'a> {
fn fold_item(&mut self, i: Item) -> Option<Item> {
for attr in i.attrs.iter() {
match attr {
&clean::List(~"doc", ref l) => {
for innerattr in l.iter() {
match innerattr {
&clean::Word(ref s) if "hidden" == *s => {
debug!("found one in strip_hidden; removing");
self.stripped.insert(i.id);
return None;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a crazy amount of nesting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but it's pre-existing. I only added a single level to deal with the re-borrowing of stripped.

},
_ => (),
}
}
},
_ => ()
}
}
self.fold_item_recur(i)
}
}
let mut stripper = Stripper{ stripped: &mut stripped };
stripper.fold_crate(krate)
};

// strip any traits implemented on stripped items
let krate = {
struct ImplStripper<'a> {
stripped: &'a mut HashSet<ast::NodeId>
};
impl<'a> fold::DocFolder for ImplStripper<'a> {
fn fold_item(&mut self, i: Item) -> Option<Item> {
match i.inner {
clean::ImplItem(clean::Impl{ for_: clean::ResolvedPath{ id: for_id, .. },
.. }) => {
if self.stripped.contains(&for_id) {
return None;
}
},
_ => ()
}
_ => {}
}
self.fold_item_recur(i)
}
self.fold_item_recur(i)
}
}
let mut stripper = Stripper;
let krate = stripper.fold_crate(krate);
let mut stripper = ImplStripper{ stripped: &mut stripped };
stripper.fold_crate(krate)
};

(krate, None)
}

Expand Down Expand Up @@ -110,8 +142,16 @@ impl<'a> fold::DocFolder for Stripper<'a> {
// handled below
clean::ModuleItem(..) => {}

// impls/tymethods have no control over privacy
clean::ImplItem(..) | clean::TyMethodItem(..) => {}
// trait impls for private items should be stripped
clean::ImplItem(clean::Impl{ for_: clean::ResolvedPath{ id: ref for_id, .. }, .. }) => {
if !self.exported_items.contains(for_id) {
return None;
}
}
clean::ImplItem(..) => {}

// tymethods have no control over privacy
clean::TyMethodItem(..) => {}
}

let fastreturn = match i.inner {
Expand Down