rustc_privacy

Trait DefIdVisitor

Source
pub trait DefIdVisitor<'tcx> {
    type Result: VisitorResult = ();

    const SHALLOW: bool = false;
    const SKIP_ASSOC_TYS: bool = false;

    // Required methods
    fn tcx(&self) -> TyCtxt<'tcx>;
    fn visit_def_id(
        &mut self,
        def_id: DefId,
        kind: &str,
        descr: &dyn Display,
    ) -> Self::Result;

    // Provided methods
    fn skeleton(&mut self) -> DefIdVisitorSkeleton<'_, 'tcx, Self> { ... }
    fn visit(
        &mut self,
        ty_fragment: impl TypeVisitable<TyCtxt<'tcx>>,
    ) -> Self::Result { ... }
    fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> Self::Result { ... }
    fn visit_predicates(
        &mut self,
        predicates: GenericPredicates<'tcx>,
    ) -> Self::Result { ... }
    fn visit_clauses(
        &mut self,
        clauses: &[(Clause<'tcx>, Span)],
    ) -> Self::Result { ... }
}
Expand description

Implemented to visit all DefIds in a type. Visiting DefIds is useful because visibilities and reachabilities are attached to them. The idea is to visit “all components of a type”, as documented in https://github.com/rust-lang/rfcs/blob/master/text/2145-type-privacy.md#how-to-determine-visibility-of-a-type. The default type visitor (TypeVisitor) does most of the job, but it has some shortcomings. First, it doesn’t have overridable fn visit_trait_ref, so we have to catch trait DefIds manually. Second, it doesn’t visit some type components like signatures of fn types, or traits in impl Trait, see individual comments in DefIdVisitorSkeleton::visit_ty.

Provided Associated Constants§

Source

const SHALLOW: bool = false

Source

const SKIP_ASSOC_TYS: bool = false

Provided Associated Types§

Source

type Result: VisitorResult = ()

Required Methods§

Source

fn tcx(&self) -> TyCtxt<'tcx>

Source

fn visit_def_id( &mut self, def_id: DefId, kind: &str, descr: &dyn Display, ) -> Self::Result

Provided Methods§

Source

fn skeleton(&mut self) -> DefIdVisitorSkeleton<'_, 'tcx, Self>

Not overridden, but used to actually visit types and traits.

Source

fn visit( &mut self, ty_fragment: impl TypeVisitable<TyCtxt<'tcx>>, ) -> Self::Result

Source

fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> Self::Result

Source

fn visit_predicates( &mut self, predicates: GenericPredicates<'tcx>, ) -> Self::Result

Source

fn visit_clauses(&mut self, clauses: &[(Clause<'tcx>, Span)]) -> Self::Result

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, 'tcx, VL: VisibilityLike, const SHALLOW: bool> DefIdVisitor<'tcx> for FindMin<'a, 'tcx, VL, SHALLOW>

Source§

const SHALLOW: bool = SHALLOW

Source§

const SKIP_ASSOC_TYS: bool = true

Source§

impl<'tcx> DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx>

Source§

impl<'tcx> DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx>

Source§

impl<'tcx> DefIdVisitor<'tcx> for TypePrivacyVisitor<'tcx>