Skip to content

Commit

Permalink
Rollup merge of rust-lang#84461 - jyn514:remove-strip-item, r=Guillau…
Browse files Browse the repository at this point in the history
…meGomez

rustdoc: Remove unnecessary `StripItem` wrapper
  • Loading branch information
GuillaumeGomez authored May 15, 2021
2 parents c6dd87a + 0aa2844 commit b567b20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
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

0 comments on commit b567b20

Please sign in to comment.