Struct rustc_privacy::EmbargoVisitor[][src]

pub(crate) struct EmbargoVisitor<'tcx> {
    tcx: TyCtxt<'tcx>,
    access_levels: AccessLevels,
    macro_reachable: FxHashSet<(LocalDefId, LocalDefId)>,
    prev_level: Option<AccessLevel>,
    changed: bool,
}
Expand description

The embargo visitor, used to determine the exports of the AST.

Fields

tcx: TyCtxt<'tcx>access_levels: AccessLevels

Accessibility levels for reachable nodes.

macro_reachable: FxHashSet<(LocalDefId, LocalDefId)>

A set of pairs corresponding to modules, where the first module is reachable via a macro that’s defined in the second module. This cannot be represented as reachable because it can’t handle the following case:

pub mod n { // Should be Public pub(crate) mod p { // Should not be accessible pub fn f() -> i32 { 12 } // Must be Reachable } } pub macro m() { n::p::f() }

prev_level: Option<AccessLevel>

Previous accessibility level; None means unreachable.

changed: bool

Has something changed in the level map?

Implementations

Updates node level and returns the updated level.

Updates the item as being reachable through a macro defined in the given module. Returns true if the level has changed.

Given the path segments of an ItemKind::Use, then we need to update the visibility of the intermediate use so that it isn’t linted by unreachable_pub.

This isn’t trivial as path.res has the DefId of the eventual target of the use statement not of the next intermediate use statement.

To do this, consider the last two segments of the path to our intermediate use statement. We expect the penultimate segment to be a module and the last segment to be the name of the item we are exporting. We can then look at the items contained in the module for the use statement with that name and update that item’s visibility.

FIXME: This solution won’t work with glob imports and doesn’t respect namespaces. See https://github.com/rust-lang/rust/pull/57922#discussion_r251234202.

Trait Implementations

We want to visit items in the context of their containing module and so forth, so supply a crate for doing a deep walk.

Visits the top-level item and (optionally) nested items / impl items. See visit_nested_item for details. Read more

Invoked when a nested item is encountered. By default does nothing unless you override nested_visit_map to return other than None, in which case it will walk the item. You probably don’t want to override this method – instead, override nested_visit_map or use the “shallow” or “deep” visit patterns described on itemlikevisit::ItemLikeVisitor. The only reason to override this method is if you want a nested pattern but cannot supply a Map; see nested_visit_map for advice. Read more

Like visit_nested_item(), but for trait items. See visit_nested_item() for advice on when to override this method. Read more

Like visit_nested_item(), but for impl items. See visit_nested_item() for advice on when to override this method. Read more

Like visit_nested_item(), but for foreign items. See visit_nested_item() for advice on when to override this method. Read more

Invoked to visit the body of a function, method or closure. Like visit_nested_item, does nothing by default unless you override nested_visit_map to return other than None, in which case it will walk the body. Read more

When invoking visit_all_item_likes(), you need to supply an item-like visitor. This method converts an “intra-visit” visitor into an item-like visitor that walks the entire tree. If you use this, you probably don’t want to process the contents of nested item-like things, since the outer loop will visit them as well. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Layout

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 80 bytes