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
pub(crate) fn update(
&mut self,
def_id: LocalDefId,
level: Option<AccessLevel>
) -> Option<AccessLevel>
pub(crate) fn update(
&mut self,
def_id: LocalDefId,
level: Option<AccessLevel>
) -> Option<AccessLevel>
Updates node level and returns the updated level.
pub(crate) fn reach(
&mut self,
def_id: LocalDefId,
access_level: Option<AccessLevel>
) -> ReachEverythingInTheInterfaceVisitor<'_, 'tcx>
pub(crate) fn update_reachability_from_macro(
&mut self,
local_def_id: LocalDefId,
md: &MacroDef
)
pub(crate) fn update_macro_reachable(
&mut self,
module_def_id: LocalDefId,
defining_mod: LocalDefId
) -> bool
pub(crate) fn update_macro_reachable(
&mut self,
module_def_id: LocalDefId,
defining_mod: LocalDefId
) -> bool
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,
module_def_id: LocalDefId,
defining_mod: LocalDefId
)
pub(crate) fn update_macro_reachable_def(
&mut self,
def_id: LocalDefId,
def_kind: DefKind,
vis: Visibility,
module: LocalDefId
)
pub(crate) fn update_visibility_of_intermediate_use_statements(
&mut self,
segments: &[PathSegment<'_>]
)
pub(crate) fn update_visibility_of_intermediate_use_statements(
&mut self,
segments: &[PathSegment<'_>]
)
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
fn visit_variant_data(
&mut self,
s: &'v VariantData<'v>,
Symbol,
&'v Generics<'v>,
_parent_id: HirId,
Span
)
fn visit_enum_def(
&mut self,
enum_definition: &'v EnumDef<'v>,
generics: &'v Generics<'v>,
item_id: HirId,
Span
)
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
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