diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index 37d11d4ed47c4..723792381ef09 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -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 { diff --git a/src/librustdoc/passes/strip_hidden.rs b/src/librustdoc/passes/strip_hidden.rs index e5910d081a5d0..87573e8e037a9 100644 --- a/src/librustdoc/passes/strip_hidden.rs +++ b/src/librustdoc/passes/strip_hidden.rs @@ -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 { @@ -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); } diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 87399256292a8..528518410aa06 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -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, @@ -51,7 +51,7 @@ impl<'a> DocFolder for Stripper<'a> { clean::StructFieldItem(..) => { if !i.visibility.is_public() { - return Some(StripItem(i).strip()); + return Some(strip_item(i)); } } @@ -59,7 +59,7 @@ impl<'a> DocFolder for Stripper<'a> { 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); }