X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustdoc%2Fclean%2Fmod.rs;h=9865601da5fc7f5b9aca672a0accebe0549507d2;hb=9e197b75f0e5ad17dc1bb1431853bd4df7cff408;hp=d6260b8ca06e48f0082982a905b40b4a43c2a3e2;hpb=e423a6f5f01c362ac7aacaaa86b12bd52f52d512;p=rust.git diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d6260b8ca06..9865601da5f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -57,11 +57,43 @@ fn clean(&self, cx: &mut DocContext<'tcx>) -> Item { .map(|(item, renamed)| clean_maybe_renamed_foreign_item(cx, item, *renamed)), ); items.extend(self.mods.iter().map(|x| x.clean(cx))); - items.extend( - self.items - .iter() - .flat_map(|(item, renamed)| clean_maybe_renamed_item(cx, item, *renamed)), - ); + + // Split up imports from all other items. + // + // This covers the case where somebody does an import which should pull in an item, + // but there's already an item with the same namespace and same name. Rust gives + // priority to the not-imported one, so we should, too. + let mut inserted = FxHashSet::default(); + items.extend(self.items.iter().flat_map(|(item, renamed)| { + // First, lower everything other than imports. + if matches!(item.kind, hir::ItemKind::Use(..)) { + return Vec::new(); + } + let v = clean_maybe_renamed_item(cx, item, *renamed); + for item in &v { + if let Some(name) = item.name { + inserted.insert((item.type_(), name)); + } + } + v + })); + items.extend(self.items.iter().flat_map(|(item, renamed)| { + // Now we actually lower the imports, skipping everything else. + if !matches!(item.kind, hir::ItemKind::Use(..)) { + return Vec::new(); + } + let mut v = clean_maybe_renamed_item(cx, item, *renamed); + v.drain_filter(|item| { + if let Some(name) = item.name { + // If an item with the same type and name already exists, + // it takes priority over the inlined stuff. + !inserted.insert((item.type_(), name)) + } else { + false + } + }); + v + })); // determine if we should display the inner contents or // the outer `mod` item for the source code. @@ -2005,8 +2037,8 @@ fn clean_impl<'tcx>( for_, items, polarity: tcx.impl_polarity(def_id), - kind: if utils::has_doc_flag(tcx, def_id.to_def_id(), sym::tuple_variadic) { - ImplKind::TupleVaradic + kind: if utils::has_doc_flag(tcx, def_id.to_def_id(), sym::fake_variadic) { + ImplKind::FakeVaradic } else { ImplKind::Normal },