Skip to content
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

rustdoc: Remove unnecessary StripItem wrapper #84461

Merged
merged 1 commit into from
May 15, 2021
Merged
Show file tree
Hide file tree
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
15 changes: 4 additions & 11 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
use crate::clean::*;

crate struct StripItem(pub Item);

impl StripItem {
crate fn strip(self) -> Item {
match self.0 {
Item { kind: box StrippedItem(..), .. } => self.0,
mut i => {
i.kind = box StrippedItem(i.kind);
i
}
}
crate fn strip_item(mut item: Item) -> Item {
if !matches!(*item.kind, StrippedItem(..)) {
item.kind = box StrippedItem(item.kind);
}
item
}

crate trait DocFolder: Sized {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/strip_hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::mem;
use crate::clean;
use crate::clean::{FakeDefIdSet, Item, NestedAttributesExt};
use crate::core::DocContext;
use crate::fold::{DocFolder, StripItem};
use crate::fold::{strip_item, DocFolder};
use crate::passes::{ImplStripper, Pass};

crate const STRIP_HIDDEN: Pass = Pass {
Expand Down Expand Up @@ -44,7 +44,7 @@ impl<'a> DocFolder for Stripper<'a> {
// strip things like impl methods but when doing so
// we must not add any items to the `retained` set.
let old = mem::replace(&mut self.update_retained, false);
let ret = StripItem(self.fold_item_recur(i)).strip();
let ret = strip_item(self.fold_item_recur(i));
self.update_retained = old;
return Some(ret);
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/passes/stripper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_middle::middle::privacy::AccessLevels;
use std::mem;

use crate::clean::{self, FakeDefIdSet, GetDefId, Item};
use crate::fold::{DocFolder, StripItem};
use crate::fold::{strip_item, DocFolder};

crate struct Stripper<'a> {
crate retained: &'a mut FakeDefIdSet,
Expand Down Expand Up @@ -51,15 +51,15 @@ impl<'a> DocFolder for Stripper<'a> {

clean::StructFieldItem(..) => {
if !i.visibility.is_public() {
return Some(StripItem(i).strip());
return Some(strip_item(i));
}
}

clean::ModuleItem(..) => {
if i.def_id.is_local() && !i.visibility.is_public() {
debug!("Stripper: stripping module {:?}", i.name);
let old = mem::replace(&mut self.update_retained, false);
let ret = StripItem(self.fold_item_recur(i)).strip();
let ret = strip_item(self.fold_item_recur(i));
self.update_retained = old;
return Some(ret);
}
Expand Down