From e3c3efe5abb2025fdc8a4937b22e76fbd8093dd5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 10 Oct 2020 15:31:14 +0200 Subject: [PATCH 1/2] Filter out imports added by the compiler --- src/librustdoc/clean/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 501891da573a6..4bbf5edeaf348 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -24,9 +24,9 @@ use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::{self, AdtKind, Lift, Ty, TyCtxt}; use rustc_mir::const_eval::{is_const_fn, is_min_const_fn, is_unstable_const_fn}; -use rustc_span::hygiene::MacroKind; +use rustc_span::hygiene::{AstPass, MacroKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; -use rustc_span::{self, Pos}; +use rustc_span::{self, ExpnKind, Pos}; use rustc_typeck::hir_ty_to_ty; use std::collections::hash_map::Entry; @@ -2232,6 +2232,13 @@ impl Clean> for doctree::ExternCrate<'_> { impl Clean> for doctree::Import<'_> { fn clean(&self, cx: &DocContext<'_>) -> Vec { + // We need this comparison because some imports (for std types for example) + // are "inserted" as well but directly by the compiler and they should not be + // taken into account. + if self.span.ctxt().outer_expn_data().kind == ExpnKind::AstPass(AstPass::StdImports) { + return Vec::new(); + } + // We consider inlining the documentation of `pub use` statements, but we // forcefully don't inline if this is not public or if the // #[doc(no_inline)] attribute is present. From 0faaa499ccc9fb4835251845cf457bae385f07f5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 10 Oct 2020 15:34:18 +0200 Subject: [PATCH 2/2] Add test for compiler reexports removal --- src/test/rustdoc/no-compiler-reexport.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/test/rustdoc/no-compiler-reexport.rs diff --git a/src/test/rustdoc/no-compiler-reexport.rs b/src/test/rustdoc/no-compiler-reexport.rs new file mode 100644 index 0000000000000..6d50325fed550 --- /dev/null +++ b/src/test/rustdoc/no-compiler-reexport.rs @@ -0,0 +1,7 @@ +// compile-flags: --no-defaults + +#![crate_name = "foo"] + +// @has 'foo/index.html' '//code' 'extern crate std;' +// @!has 'foo/index.html' '//code' 'use std::prelude::v1::*;' +pub struct Foo;