[−][src]Struct rustc_privacy::EmbargoVisitor

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

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<(HirId, DefId)>

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

impl<'tcx> EmbargoVisitor<'tcx>[src]

pub(crate) fn get(&self, id: HirId) -> Option<AccessLevel>[src]

pub(crate) fn update(
    &mut self,
    id: HirId,
    level: Option<AccessLevel>
) -> Option<AccessLevel>
[src]

Updates node level and returns the updated level.

pub(crate) fn reach(
    &mut self,
    item_id: HirId,
    access_level: Option<AccessLevel>
) -> ReachEverythingInTheInterfaceVisitor<'_, 'tcx>
[src]

pub(crate) fn update_macro_reachable(
    &mut self,
    reachable_mod: HirId,
    defining_mod: DefId
) -> bool
[src]

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

pub(crate) fn update_macro_reachable_mod(
    &mut self,
    reachable_mod: HirId,
    defining_mod: DefId
)
[src]

pub(crate) fn update_macro_reachable_def(
    &mut self,
    hir_id: HirId,
    def_kind: DefKind,
    vis: Visibility,
    module: DefId
)
[src]

pub(crate) fn update_visibility_of_intermediate_use_statements(
    &mut self,
    segments: &[PathSegment<'_>]
)
[src]

Given the path segments of a 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

impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx>[src]

type Map = Map<'tcx>

pub fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map>[src]

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

Auto Trait Implementations

impl<'tcx> !RefUnwindSafe for EmbargoVisitor<'tcx>

impl<'tcx> !Send for EmbargoVisitor<'tcx>

impl<'tcx> !Sync for EmbargoVisitor<'tcx>

impl<'tcx> Unpin for EmbargoVisitor<'tcx>

impl<'tcx> !UnwindSafe for EmbargoVisitor<'tcx>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized, 
[src]

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.