]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #86887 - jyn514:cleanup-clean, r=CraftSpider
authorYuki Okushi <jtitor@2k36.org>
Mon, 12 Jul 2021 23:54:31 +0000 (08:54 +0900)
committerGitHub <noreply@github.com>
Mon, 12 Jul 2021 23:54:31 +0000 (08:54 +0900)
rustdoc: remove dead code in `clean`

Builds on https://github.com/rust-lang/rust/pull/86886 and should not be merged before.

1  2 
src/librustdoc/clean/blanket_impl.rs
src/librustdoc/clean/mod.rs

index c257d362694feffdb4d225a591fa0f7c1c5f702c,dc60b5a1d58e1624604c15079a20d7354be46b4b..8f74a48547d8833c0f88a12e6ec8ac111cda1af4
@@@ -96,9 -96,9 +96,9 @@@ impl<'a, 'tcx> BlanketImplFinder<'a, 't
                      name: None,
                      attrs: Default::default(),
                      visibility: Inherited,
 -                    def_id: FakeDefId::new_fake(item_def_id.krate),
 +                    def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
                      kind: box ImplItem(Impl {
-                         span: self.cx.tcx.def_span(impl_def_id).clean(self.cx),
+                         span: Span::from_rustc_span(self.cx.tcx.def_span(impl_def_id)),
                          unsafety: hir::Unsafety::Normal,
                          generics: (
                              self.cx.tcx.generics_of(impl_def_id),
index 0ff708d01f5e740c77639a35452414c7971303bf,767b14135bdfa550e558dbeea04c8b062141e3dd..80aaae1580114752da8ebe3a610719c814ce5624
@@@ -227,20 -227,6 +227,6 @@@ impl<'tcx> Clean<GenericBound> for ty::
      }
  }
  
- impl<'tcx> Clean<Option<Vec<GenericBound>>> for InternalSubsts<'tcx> {
-     fn clean(&self, cx: &mut DocContext<'_>) -> Option<Vec<GenericBound>> {
-         let mut v = Vec::new();
-         v.extend(self.regions().filter_map(|r| r.clean(cx)).map(GenericBound::Outlives));
-         v.extend(self.types().map(|t| {
-             GenericBound::TraitBound(
-                 PolyTrait { trait_: t.clean(cx), generic_params: Vec::new() },
-                 hir::TraitBoundModifier::None,
-             )
-         }));
-         if !v.is_empty() { Some(v) } else { None }
-     }
- }
  impl Clean<Lifetime> for hir::Lifetime {
      fn clean(&self, cx: &mut DocContext<'_>) -> Lifetime {
          let def = cx.tcx.named_region(self.hir_id);
@@@ -296,12 -282,6 +282,6 @@@ impl Clean<Constant> for hir::ConstArg 
      }
  }
  
- impl Clean<Lifetime> for ty::GenericParamDef {
-     fn clean(&self, _cx: &mut DocContext<'_>) -> Lifetime {
-         Lifetime(self.name)
-     }
- }
  impl Clean<Option<Lifetime>> for ty::RegionKind {
      fn clean(&self, _cx: &mut DocContext<'_>) -> Option<Lifetime> {
          match *self {
@@@ -1764,12 -1744,6 +1744,6 @@@ impl Clean<Variant> for hir::VariantDat
      }
  }
  
- impl Clean<Span> for rustc_span::Span {
-     fn clean(&self, _cx: &mut DocContext<'_>) -> Span {
-         Span::from_rustc_span(*self)
-     }
- }
  impl Clean<Path> for hir::Path<'_> {
      fn clean(&self, cx: &mut DocContext<'_>) -> Path {
          Path {
@@@ -1997,7 -1971,6 +1971,7 @@@ fn clean_extern_crate
          if let Some(items) = inline::try_inline(
              cx,
              cx.tcx.parent_module(krate.hir_id()).to_def_id(),
 +            Some(krate.def_id.to_def_id()),
              res,
              name,
              Some(attrs),
@@@ -2053,8 -2026,7 +2027,8 @@@ fn clean_use_statement
      // forcefully don't inline if this is not public or if the
      // #[doc(no_inline)] attribute is present.
      // Don't inline doc(hidden) imports so they can be stripped at a later stage.
 -    let mut denied = !import.vis.node.is_pub()
 +    let mut denied = !(import.vis.node.is_pub()
 +        || (cx.render_options.document_private && import.vis.node.is_pub_restricted()))
          || pub_underscore
          || attrs.iter().any(|a| {
              a.has_name(sym::doc)
          }
          if !denied {
              let mut visited = FxHashSet::default();
 +            let import_def_id = import.def_id.to_def_id();
  
              if let Some(mut items) = inline::try_inline(
                  cx,
                  cx.tcx.parent_module(import.hir_id()).to_def_id(),
 +                Some(import_def_id),
                  path.res,
                  name,
                  Some(attrs),
                  &mut visited,
              ) {
                  items.push(Item::from_def_id_and_parts(
 -                    import.def_id.to_def_id(),
 +                    import_def_id,
                      None,
                      ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)),
                      cx,
@@@ -2161,15 -2131,37 +2135,15 @@@ impl Clean<Item> for (&hir::MacroDef<'_
      fn clean(&self, cx: &mut DocContext<'_>) -> Item {
          let (item, renamed) = self;
          let name = renamed.unwrap_or(item.ident.name);
 -        let tts = item.ast.body.inner_tokens().trees().collect::<Vec<_>>();
 -        // Extract the macro's matchers. They represent the "interface" of the macro.
 -        let matchers = tts.chunks(4).map(|arm| &arm[0]);
 -
 -        let source = if item.ast.macro_rules {
 -            format!("macro_rules! {} {{\n{}}}", name, render_macro_arms(matchers, ";"))
 -        } else {
 -            let vis = item.vis.clean(cx);
 -            let def_id = item.def_id.to_def_id();
 -
 -            if matchers.len() <= 1 {
 -                format!(
 -                    "{}macro {}{} {{\n    ...\n}}",
 -                    vis.to_src_with_space(cx.tcx, def_id),
 -                    name,
 -                    matchers.map(render_macro_matcher).collect::<String>(),
 -                )
 -            } else {
 -                format!(
 -                    "{}macro {} {{\n{}}}",
 -                    vis.to_src_with_space(cx.tcx, def_id),
 -                    name,
 -                    render_macro_arms(matchers, ","),
 -                )
 -            }
 -        };
 +        let def_id = item.def_id.to_def_id();
  
          Item::from_hir_id_and_parts(
              item.hir_id(),
              Some(name),
 -            MacroItem(Macro { source, imported_from: None }),
 +            MacroItem(Macro {
 +                source: display_macro_source(cx, name, &item.ast, def_id, &item.vis),
 +                imported_from: None,
 +            }),
              cx,
          )
      }
@@@ -2193,22 -2185,3 +2167,3 @@@ impl Clean<TypeBindingKind> for hir::Ty
          }
      }
  }
- enum SimpleBound {
-     TraitBound(Vec<PathSegment>, Vec<SimpleBound>, Vec<GenericParamDef>, hir::TraitBoundModifier),
-     Outlives(Lifetime),
- }
- impl From<GenericBound> for SimpleBound {
-     fn from(bound: GenericBound) -> Self {
-         match bound.clone() {
-             GenericBound::Outlives(l) => SimpleBound::Outlives(l),
-             GenericBound::TraitBound(t, mod_) => match t.trait_ {
-                 Type::ResolvedPath { path, .. } => {
-                     SimpleBound::TraitBound(path.segments, Vec::new(), t.generic_params, mod_)
-                 }
-                 _ => panic!("Unexpected bound {:?}", bound),
-             },
-         }
-     }
- }