Skip to main content

Module clean

Module clean 

Source
Expand description

This module defines the primary IR1 used in rustdoc together with the procedures that transform rustc data types into it.

This IR — commonly referred to as the cleaned AST — is modeled after the [AST][rustc_ast].

There are two kinds of transformation — cleaning — procedures:

  1. Cleans [HIR][hir] types. Used for user-written code and inlined local re-exports both found in the local crate.
  2. Cleans [rustc_middle::ty] types. Used for inlined cross-crate re-exports and anything output by the trait solver (e.g., when synthesizing blanket and auto-trait impls). They usually have ty or middle in their name.

Their name is prefixed by clean_.

Both the HIR and the rustc_middle::ty IR are quite removed from the source code. The cleaned AST on the other hand is closer to it which simplifies the rendering process. Furthermore, operating on a single IR instead of two avoids duplicating efforts down the line.

This IR is consumed by both the HTML and the JSON backend.


  1. Intermediate representation. ↩

Re-exports§

use std::borrow::Cow; 🔒
use std::collections::BTreeMap; 🔒
use std::mem; 🔒
use rustc_attr_ir::lang_items::LangItem; 🔒
use rustc_attr_ir::AttributeKind; 🔒
use rustc_attr_ir::DocAttribute; 🔒
use rustc_attr_ir::DocInline; 🔒
use rustc_attr_ir::find_attr; 🔒
use rustc_data_structures::fx::FxHashMap; 🔒
use rustc_data_structures::fx::FxHashSet; 🔒
use rustc_data_structures::fx::FxIndexMap; 🔒
use rustc_data_structures::fx::FxIndexSet; 🔒
use rustc_data_structures::fx::IndexEntry; 🔒
use rustc_data_structures::thin_vec::ThinVec; 🔒
use rustc_errors::FatalError; 🔒
use rustc_errors::struct_span_code_err; 🔒
use rustc_hir::def::CtorKind; 🔒
use rustc_hir::def::DefKind; 🔒
use rustc_hir::def::MacroKinds; 🔒
use rustc_hir::def::PerNS; 🔒
use rustc_hir::def::Res; 🔒
use rustc_hir::def_id::DefId; 🔒
use rustc_hir::def_id::DefIdMap; 🔒
use rustc_hir::def_id::DefIdSet; 🔒
use rustc_hir::def_id::LOCAL_CRATE; 🔒
use rustc_hir::def_id::LocalDefId; 🔒
use rustc_hir as hir; 🔒
use rustc_hir::HirId; 🔒
use rustc_hir::PredicateOrigin; 🔒
use rustc_hir_analysis::lower_const_arg_for_rustdoc; 🔒
use rustc_hir_analysis::lower_ty; 🔒
use rustc_middle::middle::resolve::Reexport; 🔒
use rustc_middle::middle::resolve_bound_vars as rbv; 🔒
use rustc_middle::ty; 🔒
use rustc_middle::ty::AdtKind; 🔒
use rustc_middle::ty::Ty; 🔒
use rustc_middle::ty::TyCtxt; 🔒
use rustc_middle::ty::TypeVisitableExt; 🔒
use rustc_middle::ty::TypingMode; 🔒
use rustc_middle::ty::Unnormalized; 🔒
use rustc_span::hygiene::AstPass; 🔒
use rustc_span::hygiene::MacroKind; 🔒
use rustc_span::symbol::Ident; 🔒
use rustc_span::symbol::Symbol; 🔒
use rustc_span::symbol::kw; 🔒
use rustc_span::ExpnKind; 🔒
use rustc_span::bug; 🔒
use rustc_span::span_bug; 🔒
use rustc_trait_selection::traits::wf::object_region_bounds; 🔒
use tracing::debug; 🔒
use tracing::instrument; 🔒
use tracing::instrument; 🔒
pub(crate) use self::cfg::CfgInfo; 🔒
pub(crate) use self::cfg::extract_cfg_from_attrs; 🔒
pub(crate) use self::utils::krate; 🔒
pub(crate) use self::utils::register_res; 🔒
pub(crate) use self::utils::synthesize_auto_trait_and_blanket_impls; 🔒
use crate::core::DocContext; 🔒
use crate::formats::item_type::ItemType; 🔒
use crate::visit_ast; 🔒
pub(crate) use self::Type::Array; 🔒
pub(crate) use self::Type::BareFunction; 🔒
pub(crate) use self::Type::BorrowedRef; 🔒
pub(crate) use self::Type::DynTrait; 🔒
pub(crate) use self::Type::Generic; 🔒
pub(crate) use self::Type::ImplTrait; 🔒
pub(crate) use self::Type::Infer; 🔒
pub(crate) use self::Type::Primitive; 🔒
pub(crate) use self::Type::QPath; 🔒
pub(crate) use self::Type::RawPointer; 🔒
pub(crate) use self::Type::SelfTy; 🔒
pub(crate) use self::Type::Slice; 🔒
pub(crate) use self::Type::Tuple; 🔒
pub(crate) use self::Type::UnsafeBinder; 🔒
use rustc_errors::codes::*; 🔒
use utils::*; 🔒

Modules§

auto_trait 🔒
blanket_impl 🔒
cfg 🔒
The representation of a #[doc(cfg(...))] attribute.
inline 🔒
Support for inlining external documentation into the current AST.
render_macro_matchers 🔒
simplify 🔒
Simplification of where-clauses and parameter bounds into a prettier and more canonical form.
size_asserts 🔒
types 🔒
utils 🔒

Structs§

AliasedType 🔒
AssocConstant 🔒
AssocFunction 🔒
AssocItemConstraint 🔒
A constraint on an associated item.
AssocType 🔒
Attributes 🔒
The attributes on an Item, including attributes like #[derive(...)] and #[inline], as well as doc comments.
BareFunctionDecl 🔒
Constant 🔒
Crate 🔒
The crate currently being documented.
DeclMacro 🔒
Discriminant 🔒
Enum 🔒
ExternalCrate 🔒
FnDecl 🔒
Function 🔒
GenericParamDef 🔒
Generics 🔒
Impl 🔒
Import 🔒
ImportSource 🔒
Item 🔒
Anything with a source location and set of attributes and, optionally, a name. That is, anything that can be documented. This doesn’t correspond directly to the AST’s concept of an item; it’s a strict superset.
ItemInner 🔒
ItemLink 🔒
A link that has not yet been rendered.
Lifetime 🔒
Module 🔒
Parameter 🔒
A function parameter.
Path 🔒
PathSegment 🔒
PolyTrait 🔒
A trait reference, which may have higher ranked lifetimes.
ProcMacro 🔒
QPathData 🔒
RenderedLink 🔒
Span 🔒
Small wrapper around [rustc_span::Span] that adds helper methods and enforces calling [rustc_span::Span::source_callsite()].
Static 🔒
Struct 🔒
Trait 🔒
TraitAlias 🔒
TypeAlias 🔒
Union 🔒
UnsafeBinderTy 🔒
Variant 🔒
VariantStruct 🔒
This is a more limited form of the standard Struct, different in that it lacks the things most items have (name, id, parameterization). Found only as a variant in an enum.

Enums§

AssocItemConstraintKind 🔒
The kind of associated item constraint.
ConstantExpr 🔒
ContainerTy 🔒
Defaultness 🔒
ExternalLocation 🔒
Indicates where an external crate can be found.
GenericArg 🔒
GenericArgs 🔒
GenericBound 🔒
GenericParamDefKind 🔒
ImplKind 🔒
ImportKind 🔒
ImportLowerMode 🔒
ItemId 🔒
ItemKind 🔒
ObjectLifetimeDefault 🔒
ParamDefaults 🔒
Whether to clean generic parameter defaults or not.
ParamsSrc 🔒
PreciseCapturingArg 🔒
PrimitiveType 🔒
A primitive (aka, builtin) type.
Term 🔒
Type 🔒
Rustdoc’s representation of types, mostly based on the [hir::Ty].
TypeAliasInnerType 🔒
VariantKind 🔒
WherePredicate 🔒

Functions§

add_without_unwanted_attributes 🔒
When inlining items, we merge their attributes (and all the reexports attributes too) with the final reexport. For example:
can_elide_trait_object_lifetime_bound 🔒
clean_assoc_item_constraint 🔒
clean_bare_fn_ty 🔒
clean_bound_vars 🔒
clean_clause 🔒
clean_const 🔒
clean_const_item_rhs 🔒
clean_doc_module 🔒
clean_extern_crate 🔒
clean_field 🔒
clean_field_with_def_id 🔒
clean_fn_decl_legacy_const_generics 🔒
This is needed to make it more “readable” when documenting functions using rustc_legacy_const_generics. More information in https://github.com/rust-lang/rust/issues/83167.
clean_fn_decl_with_params 🔒
clean_fn_or_proc_macro 🔒
clean_function 🔒
clean_generic_args 🔒
clean_generic_bound 🔒
clean_generic_param 🔒
clean_generic_param_def 🔒
clean_generics 🔒
clean_hir_term 🔒
clean_impl 🔒
clean_impl_item 🔒
clean_lifetime 🔒
clean_maybe_renamed_foreign_item 🔒
clean_maybe_renamed_item 🔒
clean_middle_assoc_item 🔒
clean_middle_const 🔒
clean_middle_field 🔒
clean_middle_opaque_bounds 🔒
clean_middle_region 🔒
clean_middle_term 🔒
clean_middle_ty 🔒
clean_params 🔒
clean_params_via_body 🔒
clean_path 🔒
clean_path_segment 🔒
clean_poly_fn_sig 🔒
clean_poly_trait_predicate 🔒
clean_poly_trait_ref 🔒
clean_poly_trait_ref_with_constraints 🔒
clean_precise_capturing_arg 🔒
clean_proc_macro 🔒
clean_projection 🔒
clean_projection_predicate 🔒
clean_qpath 🔒
clean_region_outlives_clause 🔒
clean_trait_item 🔒
clean_trait_object_lifetime_bound 🔒
clean_trait_ref 🔒
clean_trait_ref_with_constraints 🔒
clean_ty 🔒
clean_ty_alias_inner_type 🔒
clean_ty_generics 🔒
clean_ty_generics_inner 🔒
clean_type_outlives_clause 🔒
clean_unsafe_binder_ty 🔒
clean_use_statement 🔒
clean_use_statement_leaf 🔒
clean_variant 🔒
clean_variant_data 🔒
clean_variant_def 🔒
clean_variant_def_with_args 🔒
clean_where_predicate 🔒
first_non_private 🔒
The goal of this function is to return the first Path which is not private (ie not private or doc(hidden)). If it’s not possible, it’ll return the “end type”.
first_non_private_clean_path 🔒
generate_item_with_correct_attrs 🔒
get_all_import_attributes 🔒
Collect attributes from the whole import chain.
is_elided_lifetime 🔒
This can happen for async fn, e.g. async fn f<'_>(&'_ self).
is_field_vis_inherited 🔒
is_glob_import 🔒
is_impl_trait 🔒
Synthetic type-parameters are inserted after normal ones. In order for normal parameters to be able to refer to synthetic ones, scans them first.
macro_reexport_is_inline 🔒
Returns true if def_id is a macro and should be inlined.
maybe_expand_private_type_alias 🔒
normalize 🔒
Returns None if the type could not be normalized
projection_to_path_segment 🔒
reexport_chain 🔒
rustc_span 🔒
should_fully_qualify_path 🔒

Type Aliases§

ItemIdSet 🔒
SimplifiedTypes 🔒