Rollup merge of #79264 - jyn514:less-doctree, r=GuillaumeGomez
Get rid of some doctree items They can be derived directly from the `hir::Item`, there's no special logic. - TypeDef - OpaqueTy - Constant - Static - TraitAlias - Enum - Union - Struct Part of #78082 (the easiest part, I'm still debugging some other changes). r? `@GuillaumeGomez`
This commit is contained in:
@@ -231,21 +231,14 @@ impl Clean<Item> for doctree::Module<'_> {
|
|||||||
let mut items: Vec<Item> = vec![];
|
let mut items: Vec<Item> = vec![];
|
||||||
items.extend(self.extern_crates.iter().flat_map(|x| x.clean(cx)));
|
items.extend(self.extern_crates.iter().flat_map(|x| x.clean(cx)));
|
||||||
items.extend(self.imports.iter().flat_map(|x| x.clean(cx)));
|
items.extend(self.imports.iter().flat_map(|x| x.clean(cx)));
|
||||||
items.extend(self.structs.iter().map(|x| x.clean(cx)));
|
|
||||||
items.extend(self.unions.iter().map(|x| x.clean(cx)));
|
|
||||||
items.extend(self.enums.iter().map(|x| x.clean(cx)));
|
|
||||||
items.extend(self.fns.iter().map(|x| x.clean(cx)));
|
items.extend(self.fns.iter().map(|x| x.clean(cx)));
|
||||||
items.extend(self.foreigns.iter().map(|x| x.clean(cx)));
|
items.extend(self.foreigns.iter().map(|x| x.clean(cx)));
|
||||||
items.extend(self.mods.iter().map(|x| x.clean(cx)));
|
items.extend(self.mods.iter().map(|x| x.clean(cx)));
|
||||||
items.extend(self.typedefs.iter().map(|x| x.clean(cx)));
|
items.extend(self.items.iter().map(|x| x.clean(cx)));
|
||||||
items.extend(self.opaque_tys.iter().map(|x| x.clean(cx)));
|
|
||||||
items.extend(self.statics.iter().map(|x| x.clean(cx)));
|
|
||||||
items.extend(self.constants.iter().map(|x| x.clean(cx)));
|
|
||||||
items.extend(self.traits.iter().map(|x| x.clean(cx)));
|
items.extend(self.traits.iter().map(|x| x.clean(cx)));
|
||||||
items.extend(self.impls.iter().flat_map(|x| x.clean(cx)));
|
items.extend(self.impls.iter().flat_map(|x| x.clean(cx)));
|
||||||
items.extend(self.macros.iter().map(|x| x.clean(cx)));
|
items.extend(self.macros.iter().map(|x| x.clean(cx)));
|
||||||
items.extend(self.proc_macros.iter().map(|x| x.clean(cx)));
|
items.extend(self.proc_macros.iter().map(|x| x.clean(cx)));
|
||||||
items.extend(self.trait_aliases.iter().map(|x| x.clean(cx)));
|
|
||||||
|
|
||||||
// determine if we should display the inner contents or
|
// determine if we should display the inner contents or
|
||||||
// the outer `mod` item for the source code.
|
// the outer `mod` item for the source code.
|
||||||
@@ -1020,20 +1013,6 @@ impl Clean<Item> for doctree::Trait<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for doctree::TraitAlias<'_> {
|
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
|
||||||
Item::from_hir_id_and_parts(
|
|
||||||
self.id,
|
|
||||||
Some(self.name),
|
|
||||||
TraitAliasItem(TraitAlias {
|
|
||||||
generics: self.generics.clean(cx),
|
|
||||||
bounds: self.bounds.clean(cx),
|
|
||||||
}),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clean<bool> for hir::IsAuto {
|
impl Clean<bool> for hir::IsAuto {
|
||||||
fn clean(&self, _: &DocContext<'_>) -> bool {
|
fn clean(&self, _: &DocContext<'_>) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
@@ -1777,38 +1756,6 @@ impl Clean<Visibility> for ty::Visibility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Struct<'_> {
|
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
|
||||||
Item::from_hir_id_and_parts(
|
|
||||||
self.id,
|
|
||||||
Some(self.name),
|
|
||||||
StructItem(Struct {
|
|
||||||
struct_type: self.struct_type,
|
|
||||||
generics: self.generics.clean(cx),
|
|
||||||
fields: self.fields.clean(cx),
|
|
||||||
fields_stripped: false,
|
|
||||||
}),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Union<'_> {
|
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
|
||||||
Item::from_hir_id_and_parts(
|
|
||||||
self.id,
|
|
||||||
Some(self.name),
|
|
||||||
UnionItem(Union {
|
|
||||||
struct_type: self.struct_type,
|
|
||||||
generics: self.generics.clean(cx),
|
|
||||||
fields: self.fields.clean(cx),
|
|
||||||
fields_stripped: false,
|
|
||||||
}),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
|
impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> VariantStruct {
|
fn clean(&self, cx: &DocContext<'_>) -> VariantStruct {
|
||||||
VariantStruct {
|
VariantStruct {
|
||||||
@@ -1819,21 +1766,6 @@ impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Enum<'_> {
|
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
|
||||||
Item::from_hir_id_and_parts(
|
|
||||||
self.id,
|
|
||||||
Some(self.name),
|
|
||||||
EnumItem(Enum {
|
|
||||||
variants: self.variants.iter().map(|v| v.clean(cx)).collect(),
|
|
||||||
generics: self.generics.clean(cx),
|
|
||||||
variants_stripped: false,
|
|
||||||
}),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Variant<'_> {
|
impl Clean<Item> for doctree::Variant<'_> {
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||||
let what_rustc_thinks = Item::from_hir_id_and_parts(
|
let what_rustc_thinks = Item::from_hir_id_and_parts(
|
||||||
@@ -1981,33 +1913,6 @@ impl Clean<String> for Symbol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Typedef<'_> {
|
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
|
||||||
let type_ = self.ty.clean(cx);
|
|
||||||
let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
|
|
||||||
Item::from_hir_id_and_parts(
|
|
||||||
self.id,
|
|
||||||
Some(self.name),
|
|
||||||
TypedefItem(Typedef { type_, generics: self.gen.clean(cx), item_type }, false),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clean<Item> for doctree::OpaqueTy<'_> {
|
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
|
||||||
Item::from_hir_id_and_parts(
|
|
||||||
self.id,
|
|
||||||
Some(self.name),
|
|
||||||
OpaqueTyItem(OpaqueTy {
|
|
||||||
bounds: self.opaque_ty.bounds.clean(cx),
|
|
||||||
generics: self.opaque_ty.generics.clean(cx),
|
|
||||||
}),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
|
impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> BareFunctionDecl {
|
fn clean(&self, cx: &DocContext<'_>) -> BareFunctionDecl {
|
||||||
let (generic_params, decl) = enter_impl_trait(cx, || {
|
let (generic_params, decl) = enter_impl_trait(cx, || {
|
||||||
@@ -2017,38 +1922,76 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Static<'_> {
|
impl Clean<Item> for (&hir::Item<'_>, Option<Ident>) {
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||||
debug!("cleaning static {}: {:?}", self.name.clean(cx), self);
|
use hir::ItemKind;
|
||||||
Item::from_hir_id_and_parts(
|
|
||||||
self.id,
|
let (item, renamed) = self;
|
||||||
Some(self.name),
|
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id();
|
||||||
StaticItem(Static {
|
let name = match renamed {
|
||||||
type_: self.type_.clean(cx),
|
Some(ident) => ident.name,
|
||||||
mutability: self.mutability,
|
None => cx.tcx.hir().name(item.hir_id),
|
||||||
expr: print_const_expr(cx, self.expr),
|
};
|
||||||
|
let kind = match item.kind {
|
||||||
|
ItemKind::Static(ty, mutability, body_id) => StaticItem(Static {
|
||||||
|
type_: ty.clean(cx),
|
||||||
|
mutability,
|
||||||
|
expr: print_const_expr(cx, body_id),
|
||||||
}),
|
}),
|
||||||
cx,
|
ItemKind::Const(ty, body_id) => ConstantItem(Constant {
|
||||||
)
|
type_: ty.clean(cx),
|
||||||
}
|
expr: print_const_expr(cx, body_id),
|
||||||
}
|
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Constant<'_> {
|
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
|
||||||
let def_id = cx.tcx.hir().local_def_id(self.id).to_def_id();
|
|
||||||
|
|
||||||
Item::from_def_id_and_parts(
|
|
||||||
def_id,
|
|
||||||
Some(self.name),
|
|
||||||
ConstantItem(Constant {
|
|
||||||
type_: self.type_.clean(cx),
|
|
||||||
expr: print_const_expr(cx, self.expr),
|
|
||||||
value: print_evaluated_const(cx, def_id),
|
value: print_evaluated_const(cx, def_id),
|
||||||
is_literal: is_literal_expr(cx, self.expr.hir_id),
|
is_literal: is_literal_expr(cx, body_id.hir_id),
|
||||||
}),
|
}),
|
||||||
cx,
|
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
|
||||||
|
bounds: ty.bounds.clean(cx),
|
||||||
|
generics: ty.generics.clean(cx),
|
||||||
|
}),
|
||||||
|
ItemKind::TyAlias(ty, ref generics) => {
|
||||||
|
let rustdoc_ty = ty.clean(cx);
|
||||||
|
let item_type = rustdoc_ty.def_id().and_then(|did| inline::build_ty(cx, did));
|
||||||
|
TypedefItem(
|
||||||
|
Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type },
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
ItemKind::Enum(ref def, ref generics) => EnumItem(Enum {
|
||||||
|
variants: def.variants.iter().map(|v| v.clean(cx)).collect(),
|
||||||
|
generics: generics.clean(cx),
|
||||||
|
variants_stripped: false,
|
||||||
|
}),
|
||||||
|
ItemKind::TraitAlias(ref generics, bounds) => TraitAliasItem(TraitAlias {
|
||||||
|
generics: generics.clean(cx),
|
||||||
|
bounds: bounds.clean(cx),
|
||||||
|
}),
|
||||||
|
ItemKind::Union(ref variant_data, ref generics) => UnionItem(Union {
|
||||||
|
struct_type: doctree::struct_type_from_def(&variant_data),
|
||||||
|
generics: generics.clean(cx),
|
||||||
|
fields: variant_data.fields().clean(cx),
|
||||||
|
fields_stripped: false,
|
||||||
|
}),
|
||||||
|
ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct {
|
||||||
|
struct_type: doctree::struct_type_from_def(&variant_data),
|
||||||
|
generics: generics.clean(cx),
|
||||||
|
fields: variant_data.fields().clean(cx),
|
||||||
|
fields_stripped: false,
|
||||||
|
}),
|
||||||
|
_ => unreachable!("not yet converted"),
|
||||||
|
};
|
||||||
|
|
||||||
|
Item::from_def_id_and_parts(def_id, Some(name), kind, cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clean<Item> for hir::Variant<'_> {
|
||||||
|
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||||
|
let kind = VariantItem(Variant { kind: self.data.clean(cx) });
|
||||||
|
let what_rustc_thinks =
|
||||||
|
Item::from_hir_id_and_parts(self.id, Some(self.ident.name), kind, cx);
|
||||||
|
// don't show `pub` for variants, which are always public
|
||||||
|
Item { visibility: Inherited, ..what_rustc_thinks }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<ImplPolarity> for ty::ImplPolarity {
|
impl Clean<ImplPolarity> for ty::ImplPolarity {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ crate use self::StructType::*;
|
|||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::{self, Span, Symbol};
|
use rustc_span::{self, symbol::Ident, Span, Symbol};
|
||||||
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::CrateNum;
|
use rustc_hir::def_id::CrateNum;
|
||||||
@@ -17,22 +17,16 @@ crate struct Module<'hir> {
|
|||||||
crate where_inner: Span,
|
crate where_inner: Span,
|
||||||
crate extern_crates: Vec<ExternCrate<'hir>>,
|
crate extern_crates: Vec<ExternCrate<'hir>>,
|
||||||
crate imports: Vec<Import<'hir>>,
|
crate imports: Vec<Import<'hir>>,
|
||||||
crate structs: Vec<Struct<'hir>>,
|
|
||||||
crate unions: Vec<Union<'hir>>,
|
|
||||||
crate enums: Vec<Enum<'hir>>,
|
|
||||||
crate fns: Vec<Function<'hir>>,
|
crate fns: Vec<Function<'hir>>,
|
||||||
crate mods: Vec<Module<'hir>>,
|
crate mods: Vec<Module<'hir>>,
|
||||||
crate id: hir::HirId,
|
crate id: hir::HirId,
|
||||||
crate typedefs: Vec<Typedef<'hir>>,
|
// (item, renamed)
|
||||||
crate opaque_tys: Vec<OpaqueTy<'hir>>,
|
crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
|
||||||
crate statics: Vec<Static<'hir>>,
|
|
||||||
crate constants: Vec<Constant<'hir>>,
|
|
||||||
crate traits: Vec<Trait<'hir>>,
|
crate traits: Vec<Trait<'hir>>,
|
||||||
crate impls: Vec<Impl<'hir>>,
|
crate impls: Vec<Impl<'hir>>,
|
||||||
crate foreigns: Vec<ForeignItem<'hir>>,
|
crate foreigns: Vec<ForeignItem<'hir>>,
|
||||||
crate macros: Vec<Macro>,
|
crate macros: Vec<Macro>,
|
||||||
crate proc_macros: Vec<ProcMacro>,
|
crate proc_macros: Vec<ProcMacro>,
|
||||||
crate trait_aliases: Vec<TraitAlias<'hir>>,
|
|
||||||
crate is_crate: bool,
|
crate is_crate: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,21 +40,14 @@ impl Module<'hir> {
|
|||||||
attrs,
|
attrs,
|
||||||
extern_crates: Vec::new(),
|
extern_crates: Vec::new(),
|
||||||
imports: Vec::new(),
|
imports: Vec::new(),
|
||||||
structs: Vec::new(),
|
|
||||||
unions: Vec::new(),
|
|
||||||
enums: Vec::new(),
|
|
||||||
fns: Vec::new(),
|
fns: Vec::new(),
|
||||||
mods: Vec::new(),
|
mods: Vec::new(),
|
||||||
typedefs: Vec::new(),
|
items: Vec::new(),
|
||||||
opaque_tys: Vec::new(),
|
|
||||||
statics: Vec::new(),
|
|
||||||
constants: Vec::new(),
|
|
||||||
traits: Vec::new(),
|
traits: Vec::new(),
|
||||||
impls: Vec::new(),
|
impls: Vec::new(),
|
||||||
foreigns: Vec::new(),
|
foreigns: Vec::new(),
|
||||||
macros: Vec::new(),
|
macros: Vec::new(),
|
||||||
proc_macros: Vec::new(),
|
proc_macros: Vec::new(),
|
||||||
trait_aliases: Vec::new(),
|
|
||||||
is_crate: false,
|
is_crate: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,29 +63,6 @@ crate enum StructType {
|
|||||||
Unit,
|
Unit,
|
||||||
}
|
}
|
||||||
|
|
||||||
crate struct Struct<'hir> {
|
|
||||||
crate id: hir::HirId,
|
|
||||||
crate struct_type: StructType,
|
|
||||||
crate name: Symbol,
|
|
||||||
crate generics: &'hir hir::Generics<'hir>,
|
|
||||||
crate fields: &'hir [hir::StructField<'hir>],
|
|
||||||
}
|
|
||||||
|
|
||||||
crate struct Union<'hir> {
|
|
||||||
crate id: hir::HirId,
|
|
||||||
crate struct_type: StructType,
|
|
||||||
crate name: Symbol,
|
|
||||||
crate generics: &'hir hir::Generics<'hir>,
|
|
||||||
crate fields: &'hir [hir::StructField<'hir>],
|
|
||||||
}
|
|
||||||
|
|
||||||
crate struct Enum<'hir> {
|
|
||||||
crate variants: Vec<Variant<'hir>>,
|
|
||||||
crate generics: &'hir hir::Generics<'hir>,
|
|
||||||
crate id: hir::HirId,
|
|
||||||
crate name: Symbol,
|
|
||||||
}
|
|
||||||
|
|
||||||
crate struct Variant<'hir> {
|
crate struct Variant<'hir> {
|
||||||
crate name: Symbol,
|
crate name: Symbol,
|
||||||
crate id: hir::HirId,
|
crate id: hir::HirId,
|
||||||
@@ -114,38 +78,6 @@ crate struct Function<'hir> {
|
|||||||
crate body: hir::BodyId,
|
crate body: hir::BodyId,
|
||||||
}
|
}
|
||||||
|
|
||||||
crate struct Typedef<'hir> {
|
|
||||||
crate ty: &'hir hir::Ty<'hir>,
|
|
||||||
crate gen: &'hir hir::Generics<'hir>,
|
|
||||||
crate name: Symbol,
|
|
||||||
crate id: hir::HirId,
|
|
||||||
}
|
|
||||||
|
|
||||||
crate struct OpaqueTy<'hir> {
|
|
||||||
crate opaque_ty: &'hir hir::OpaqueTy<'hir>,
|
|
||||||
crate name: Symbol,
|
|
||||||
crate id: hir::HirId,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
crate struct Static<'hir> {
|
|
||||||
crate type_: &'hir hir::Ty<'hir>,
|
|
||||||
crate mutability: hir::Mutability,
|
|
||||||
crate expr: hir::BodyId,
|
|
||||||
crate name: Symbol,
|
|
||||||
crate attrs: &'hir [ast::Attribute],
|
|
||||||
crate vis: &'hir hir::Visibility<'hir>,
|
|
||||||
crate id: hir::HirId,
|
|
||||||
crate span: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
crate struct Constant<'hir> {
|
|
||||||
crate type_: &'hir hir::Ty<'hir>,
|
|
||||||
crate expr: hir::BodyId,
|
|
||||||
crate name: Symbol,
|
|
||||||
crate id: hir::HirId,
|
|
||||||
}
|
|
||||||
|
|
||||||
crate struct Trait<'hir> {
|
crate struct Trait<'hir> {
|
||||||
crate is_auto: hir::IsAuto,
|
crate is_auto: hir::IsAuto,
|
||||||
crate unsafety: hir::Unsafety,
|
crate unsafety: hir::Unsafety,
|
||||||
@@ -157,13 +89,6 @@ crate struct Trait<'hir> {
|
|||||||
crate id: hir::HirId,
|
crate id: hir::HirId,
|
||||||
}
|
}
|
||||||
|
|
||||||
crate struct TraitAlias<'hir> {
|
|
||||||
crate name: Symbol,
|
|
||||||
crate generics: &'hir hir::Generics<'hir>,
|
|
||||||
crate bounds: &'hir [hir::GenericBound<'hir>],
|
|
||||||
crate id: hir::HirId,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
crate struct Impl<'hir> {
|
crate struct Impl<'hir> {
|
||||||
crate unsafety: hir::Unsafety,
|
crate unsafety: hir::Unsafety,
|
||||||
|
|||||||
@@ -82,50 +82,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
module
|
module
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_variant_data(
|
|
||||||
&mut self,
|
|
||||||
item: &'tcx hir::Item<'_>,
|
|
||||||
name: Symbol,
|
|
||||||
sd: &'tcx hir::VariantData<'_>,
|
|
||||||
generics: &'tcx hir::Generics<'_>,
|
|
||||||
) -> Struct<'tcx> {
|
|
||||||
debug!("visiting struct");
|
|
||||||
let struct_type = struct_type_from_def(&*sd);
|
|
||||||
Struct { id: item.hir_id, struct_type, name, generics, fields: sd.fields() }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_union_data(
|
|
||||||
&mut self,
|
|
||||||
item: &'tcx hir::Item<'_>,
|
|
||||||
name: Symbol,
|
|
||||||
sd: &'tcx hir::VariantData<'_>,
|
|
||||||
generics: &'tcx hir::Generics<'_>,
|
|
||||||
) -> Union<'tcx> {
|
|
||||||
debug!("visiting union");
|
|
||||||
let struct_type = struct_type_from_def(&*sd);
|
|
||||||
Union { id: item.hir_id, struct_type, name, generics, fields: sd.fields() }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_enum_def(
|
|
||||||
&mut self,
|
|
||||||
it: &'tcx hir::Item<'_>,
|
|
||||||
name: Symbol,
|
|
||||||
def: &'tcx hir::EnumDef<'_>,
|
|
||||||
generics: &'tcx hir::Generics<'_>,
|
|
||||||
) -> Enum<'tcx> {
|
|
||||||
debug!("visiting enum");
|
|
||||||
Enum {
|
|
||||||
name,
|
|
||||||
variants: def
|
|
||||||
.variants
|
|
||||||
.iter()
|
|
||||||
.map(|v| Variant { name: v.ident.name, id: v.id, def: &v.data })
|
|
||||||
.collect(),
|
|
||||||
generics,
|
|
||||||
id: it.hir_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_fn(
|
fn visit_fn(
|
||||||
&mut self,
|
&mut self,
|
||||||
om: &mut Module<'tcx>,
|
om: &mut Module<'tcx>,
|
||||||
@@ -414,45 +370,21 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
Some(ident.name),
|
Some(ident.name),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
hir::ItemKind::Enum(ref ed, ref gen) => {
|
|
||||||
om.enums.push(self.visit_enum_def(item, ident.name, ed, gen))
|
|
||||||
}
|
|
||||||
hir::ItemKind::Struct(ref sd, ref gen) => {
|
|
||||||
om.structs.push(self.visit_variant_data(item, ident.name, sd, gen))
|
|
||||||
}
|
|
||||||
hir::ItemKind::Union(ref sd, ref gen) => {
|
|
||||||
om.unions.push(self.visit_union_data(item, ident.name, sd, gen))
|
|
||||||
}
|
|
||||||
hir::ItemKind::Fn(ref sig, ref gen, body) => {
|
hir::ItemKind::Fn(ref sig, ref gen, body) => {
|
||||||
self.visit_fn(om, item, ident.name, &sig.decl, sig.header, gen, body)
|
self.visit_fn(om, item, ident.name, &sig.decl, sig.header, gen, body)
|
||||||
}
|
}
|
||||||
hir::ItemKind::TyAlias(ty, ref gen) => {
|
hir::ItemKind::Enum(..)
|
||||||
let t = Typedef { ty, gen, name: ident.name, id: item.hir_id };
|
| hir::ItemKind::Struct(..)
|
||||||
om.typedefs.push(t);
|
| hir::ItemKind::Union(..)
|
||||||
}
|
| hir::ItemKind::TyAlias(..)
|
||||||
hir::ItemKind::OpaqueTy(ref opaque_ty) => {
|
| hir::ItemKind::OpaqueTy(..)
|
||||||
let t = OpaqueTy { opaque_ty, name: ident.name, id: item.hir_id };
|
| hir::ItemKind::Static(..)
|
||||||
om.opaque_tys.push(t);
|
| hir::ItemKind::TraitAlias(..) => om.items.push((item, renamed)),
|
||||||
}
|
hir::ItemKind::Const(..) => {
|
||||||
hir::ItemKind::Static(type_, mutability, expr) => {
|
|
||||||
let s = Static {
|
|
||||||
type_,
|
|
||||||
mutability,
|
|
||||||
expr,
|
|
||||||
id: item.hir_id,
|
|
||||||
name: ident.name,
|
|
||||||
attrs: &item.attrs,
|
|
||||||
span: item.span,
|
|
||||||
vis: &item.vis,
|
|
||||||
};
|
|
||||||
om.statics.push(s);
|
|
||||||
}
|
|
||||||
hir::ItemKind::Const(type_, expr) => {
|
|
||||||
// Underscore constants do not correspond to a nameable item and
|
// Underscore constants do not correspond to a nameable item and
|
||||||
// so are never useful in documentation.
|
// so are never useful in documentation.
|
||||||
if ident.name != kw::Underscore {
|
if ident.name != kw::Underscore {
|
||||||
let s = Constant { type_, expr, id: item.hir_id, name: ident.name };
|
om.items.push((item, renamed));
|
||||||
om.constants.push(s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
|
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
|
||||||
@@ -469,11 +401,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
};
|
};
|
||||||
om.traits.push(t);
|
om.traits.push(t);
|
||||||
}
|
}
|
||||||
hir::ItemKind::TraitAlias(ref generics, ref bounds) => {
|
|
||||||
let t = TraitAlias { name: ident.name, generics, bounds, id: item.hir_id };
|
|
||||||
om.trait_aliases.push(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
hir::ItemKind::Impl {
|
hir::ItemKind::Impl {
|
||||||
unsafety,
|
unsafety,
|
||||||
polarity,
|
polarity,
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ note: the lint level is defined here
|
|||||||
LL | #![deny(missing_doc_code_examples)]
|
LL | #![deny(missing_doc_code_examples)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: missing code example in this documentation
|
|
||||||
--> $DIR/doc-without-codeblock.rs:3:1
|
|
||||||
|
|
|
||||||
LL | /// Some docs.
|
|
||||||
| ^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: missing code example in this documentation
|
error: missing code example in this documentation
|
||||||
--> $DIR/doc-without-codeblock.rs:7:1
|
--> $DIR/doc-without-codeblock.rs:7:1
|
||||||
|
|
|
|
||||||
@@ -34,5 +28,11 @@ error: missing code example in this documentation
|
|||||||
LL | /// Or maybe not because she saved herself!
|
LL | /// Or maybe not because she saved herself!
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: missing code example in this documentation
|
||||||
|
--> $DIR/doc-without-codeblock.rs:3:1
|
||||||
|
|
|
||||||
|
LL | /// Some docs.
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,29 @@
|
|||||||
error: `ambiguous` is both a struct and a function
|
error: `true` is both a module and a builtin type
|
||||||
--> $DIR/intra-links-ambiguity.rs:27:6
|
--> $DIR/intra-links-ambiguity.rs:38:6
|
||||||
|
|
|
|
||||||
LL | /// [`ambiguous`] is ambiguous.
|
LL | /// [true]
|
||||||
| ^^^^^^^^^^^ ambiguous link
|
| ^^^^ ambiguous link
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/intra-links-ambiguity.rs:1:9
|
--> $DIR/intra-links-ambiguity.rs:1:9
|
||||||
|
|
|
|
||||||
LL | #![deny(broken_intra_doc_links)]
|
LL | #![deny(broken_intra_doc_links)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
help: to link to the module, prefix with `mod@`
|
||||||
|
|
|
||||||
|
LL | /// [mod@true]
|
||||||
|
| ^^^^^^^^
|
||||||
|
help: to link to the builtin type, prefix with `prim@`
|
||||||
|
|
|
||||||
|
LL | /// [prim@true]
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
||||||
|
error: `ambiguous` is both a struct and a function
|
||||||
|
--> $DIR/intra-links-ambiguity.rs:27:6
|
||||||
|
|
|
||||||
|
LL | /// [`ambiguous`] is ambiguous.
|
||||||
|
| ^^^^^^^^^^^ ambiguous link
|
||||||
|
|
|
||||||
help: to link to the struct, prefix with `struct@`
|
help: to link to the struct, prefix with `struct@`
|
||||||
|
|
|
|
||||||
LL | /// [`struct@ambiguous`] is ambiguous.
|
LL | /// [`struct@ambiguous`] is ambiguous.
|
||||||
@@ -82,20 +97,5 @@ help: to link to the function, add parentheses
|
|||||||
LL | /// Ambiguous non-implied shortcut link [`foo::bar()`].
|
LL | /// Ambiguous non-implied shortcut link [`foo::bar()`].
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error: `true` is both a module and a builtin type
|
|
||||||
--> $DIR/intra-links-ambiguity.rs:38:6
|
|
||||||
|
|
|
||||||
LL | /// [true]
|
|
||||||
| ^^^^ ambiguous link
|
|
||||||
|
|
|
||||||
help: to link to the module, prefix with `mod@`
|
|
||||||
|
|
|
||||||
LL | /// [mod@true]
|
|
||||||
| ^^^^^^^^
|
|
||||||
help: to link to the builtin type, prefix with `prim@`
|
|
||||||
|
|
|
||||||
LL | /// [prim@true]
|
|
||||||
| ^^^^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,60 @@ warning: unresolved link to `Qux::Z`
|
|||||||
LL | //! , [Uniooon::X] and [Qux::Z].
|
LL | //! , [Uniooon::X] and [Qux::Z].
|
||||||
| ^^^^^^ no item named `Qux` in scope
|
| ^^^^^^ no item named `Qux` in scope
|
||||||
|
|
||||||
|
warning: unresolved link to `BarA`
|
||||||
|
--> $DIR/intra-links-warning.rs:21:10
|
||||||
|
|
|
||||||
|
LL | /// bar [BarA] bar
|
||||||
|
| ^^^^ no item named `BarA` in scope
|
||||||
|
|
|
||||||
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
||||||
|
|
||||||
|
warning: unresolved link to `BarB`
|
||||||
|
--> $DIR/intra-links-warning.rs:27:9
|
||||||
|
|
|
||||||
|
LL | * bar [BarB] bar
|
||||||
|
| ^^^^ no item named `BarB` in scope
|
||||||
|
|
|
||||||
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
||||||
|
|
||||||
|
warning: unresolved link to `BarC`
|
||||||
|
--> $DIR/intra-links-warning.rs:34:6
|
||||||
|
|
|
||||||
|
LL | bar [BarC] bar
|
||||||
|
| ^^^^ no item named `BarC` in scope
|
||||||
|
|
|
||||||
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
||||||
|
|
||||||
|
warning: unresolved link to `BarD`
|
||||||
|
--> $DIR/intra-links-warning.rs:45:1
|
||||||
|
|
|
||||||
|
LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: the link appears in this line:
|
||||||
|
|
||||||
|
bar [BarD] bar
|
||||||
|
^^^^
|
||||||
|
= note: no item named `BarD` in scope
|
||||||
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
||||||
|
|
||||||
|
warning: unresolved link to `BarF`
|
||||||
|
--> $DIR/intra-links-warning.rs:50:9
|
||||||
|
|
|
||||||
|
LL | #[doc = $f]
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
...
|
||||||
|
LL | f!("Foo\nbar [BarF] bar\nbaz");
|
||||||
|
| ------------------------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: the link appears in this line:
|
||||||
|
|
||||||
|
bar [BarF] bar
|
||||||
|
^^^^
|
||||||
|
= note: no item named `BarF` in scope
|
||||||
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
||||||
|
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
warning: unresolved link to `Qux:Y`
|
warning: unresolved link to `Qux:Y`
|
||||||
--> $DIR/intra-links-warning.rs:14:13
|
--> $DIR/intra-links-warning.rs:14:13
|
||||||
|
|
|
|
||||||
@@ -117,59 +171,5 @@ LL | /// docs [error2]
|
|||||||
|
|
|
|
||||||
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
||||||
|
|
||||||
warning: unresolved link to `BarA`
|
|
||||||
--> $DIR/intra-links-warning.rs:21:10
|
|
||||||
|
|
|
||||||
LL | /// bar [BarA] bar
|
|
||||||
| ^^^^ no item named `BarA` in scope
|
|
||||||
|
|
|
||||||
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
|
||||||
|
|
||||||
warning: unresolved link to `BarB`
|
|
||||||
--> $DIR/intra-links-warning.rs:27:9
|
|
||||||
|
|
|
||||||
LL | * bar [BarB] bar
|
|
||||||
| ^^^^ no item named `BarB` in scope
|
|
||||||
|
|
|
||||||
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
|
||||||
|
|
||||||
warning: unresolved link to `BarC`
|
|
||||||
--> $DIR/intra-links-warning.rs:34:6
|
|
||||||
|
|
|
||||||
LL | bar [BarC] bar
|
|
||||||
| ^^^^ no item named `BarC` in scope
|
|
||||||
|
|
|
||||||
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
|
||||||
|
|
||||||
warning: unresolved link to `BarD`
|
|
||||||
--> $DIR/intra-links-warning.rs:45:1
|
|
||||||
|
|
|
||||||
LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: the link appears in this line:
|
|
||||||
|
|
||||||
bar [BarD] bar
|
|
||||||
^^^^
|
|
||||||
= note: no item named `BarD` in scope
|
|
||||||
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
|
||||||
|
|
||||||
warning: unresolved link to `BarF`
|
|
||||||
--> $DIR/intra-links-warning.rs:50:9
|
|
||||||
|
|
|
||||||
LL | #[doc = $f]
|
|
||||||
| ^^^^^^^^^^^
|
|
||||||
...
|
|
||||||
LL | f!("Foo\nbar [BarF] bar\nbaz");
|
|
||||||
| ------------------------------- in this macro invocation
|
|
||||||
|
|
|
||||||
= note: the link appears in this line:
|
|
||||||
|
|
||||||
bar [BarF] bar
|
|
||||||
^^^^
|
|
||||||
= note: no item named `BarF` in scope
|
|
||||||
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
|
|
||||||
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
warning: 19 warnings emitted
|
warning: 19 warnings emitted
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
error: missing code example in this documentation
|
error: missing code example in this documentation
|
||||||
--> $DIR/lint-missing-doc-code-example.rs:49:1
|
--> $DIR/lint-missing-doc-code-example.rs:19:1
|
||||||
|
|
|
|
||||||
LL | /// Doc
|
LL | / mod module1 {
|
||||||
| ^^^^^^^
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/lint-missing-doc-code-example.rs:2:9
|
--> $DIR/lint-missing-doc-code-example.rs:2:9
|
||||||
@@ -11,7 +12,13 @@ LL | #![deny(missing_doc_code_examples)]
|
|||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: missing code example in this documentation
|
error: missing code example in this documentation
|
||||||
--> $DIR/lint-missing-doc-code-example.rs:63:1
|
--> $DIR/lint-missing-doc-code-example.rs:37:3
|
||||||
|
|
|
||||||
|
LL | /// doc
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: missing code example in this documentation
|
||||||
|
--> $DIR/lint-missing-doc-code-example.rs:49:1
|
||||||
|
|
|
|
||||||
LL | /// Doc
|
LL | /// Doc
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
@@ -23,16 +30,9 @@ LL | /// Doc
|
|||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: missing code example in this documentation
|
error: missing code example in this documentation
|
||||||
--> $DIR/lint-missing-doc-code-example.rs:19:1
|
--> $DIR/lint-missing-doc-code-example.rs:63:1
|
||||||
|
|
|
|
||||||
LL | / mod module1 {
|
LL | /// Doc
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
||||||
error: missing code example in this documentation
|
|
||||||
--> $DIR/lint-missing-doc-code-example.rs:37:3
|
|
||||||
|
|
|
||||||
LL | /// doc
|
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ mod hidden {
|
|||||||
// @has foo/hidden/struct.Foo.html
|
// @has foo/hidden/struct.Foo.html
|
||||||
// @has - '//p/a' '../../foo/struct.FooBar.html'
|
// @has - '//p/a' '../../foo/struct.FooBar.html'
|
||||||
pub struct Foo {}
|
pub struct Foo {}
|
||||||
|
pub union U { a: usize }
|
||||||
|
pub enum Empty {}
|
||||||
|
pub const C: usize = 1;
|
||||||
|
pub static S: usize = 1;
|
||||||
|
|
||||||
// @has foo/hidden/bar/index.html
|
// @has foo/hidden/bar/index.html
|
||||||
// @has - '//p/a' '../../foo/baz/index.html'
|
// @has - '//p/a' '../../foo/baz/index.html'
|
||||||
@@ -16,6 +20,14 @@ mod hidden {
|
|||||||
|
|
||||||
// @has foo/struct.FooBar.html
|
// @has foo/struct.FooBar.html
|
||||||
pub use hidden::Foo as FooBar;
|
pub use hidden::Foo as FooBar;
|
||||||
|
// @has foo/union.FooU.html
|
||||||
|
pub use hidden::U as FooU;
|
||||||
|
// @has foo/enum.FooEmpty.html
|
||||||
|
pub use hidden::Empty as FooEmpty;
|
||||||
|
// @has foo/constant.FooC.html
|
||||||
|
pub use hidden::C as FooC;
|
||||||
|
// @has foo/static.FooS.html
|
||||||
|
pub use hidden::S as FooS;
|
||||||
|
|
||||||
// @has foo/baz/index.html
|
// @has foo/baz/index.html
|
||||||
// @has foo/baz/struct.Thing.html
|
// @has foo/baz/struct.Thing.html
|
||||||
|
|||||||
Reference in New Issue
Block a user