Skip to content

Commit 00b2606

Browse files
committed
Mark impl Trait Functions as reachable. (Fixes #50865)
1 parent f285876 commit 00b2606

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,7 @@ dependencies = [
22372237
name = "rustc_privacy"
22382238
version = "0.0.0"
22392239
dependencies = [
2240+
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
22402241
"rustc 0.0.0",
22412242
"rustc_data_structures 0.0.0",
22422243
"rustc_typeck 0.0.0",

src/librustc/middle/privacy.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use syntax::ast::NodeId;
2121
// Accessibility levels, sorted in ascending order
2222
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
2323
pub enum AccessLevel {
24+
// Superset of Reachable used to mark impl Trait items.
25+
// ReachableFromImplTrait,
2426
// Exported items + items participating in various kinds of public interfaces,
2527
// but not directly nameable. For example, if function `fn f() -> T {...}` is
2628
// public, then type `T` is reachable. Its values can be obtained by other crates

src/librustc/middle/reachable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) ->
446446
// Step 2: Mark all symbols that the symbols on the worklist touch.
447447
reachable_context.propagate();
448448

449+
debug!("Inline reachability shows: {:?}", reachable_context.reachable_symbols);
450+
449451
// Return the set of reachable symbols.
450452
ReachableSet(Lrc::new(reachable_context.reachable_symbols))
451453
}

src/librustc_privacy/lib.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,30 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
159159
hir::ItemKind::ForeignMod(..) => {
160160
self.prev_level
161161
}
162+
// Impl trait return types mark their parent function.
163+
// It (and its children) are revisited if the change applies.
164+
hir::ItemKind::Existential(ref ty_data) => {
165+
if let Some(impl_trait_fn) = ty_data.impl_trait_fn {
166+
if let Some(node_id) = self.tcx.hir.as_local_node_id(impl_trait_fn) {
167+
self.update(node_id, Some(AccessLevel::Reachable));
168+
}
169+
}
170+
if item.vis.node.is_pub() { self.prev_level } else { None }
171+
}
162172
// Other `pub` items inherit levels from parents
163173
hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) | hir::ItemKind::ExternCrate(..) |
164174
hir::ItemKind::GlobalAsm(..) | hir::ItemKind::Fn(..) | hir::ItemKind::Mod(..) |
165175
hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) |
166176
hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) |
167-
hir::ItemKind::Existential(..) |
168177
hir::ItemKind::Ty(..) | hir::ItemKind::Union(..) | hir::ItemKind::Use(..) => {
169-
if let hir::ItemKind::Fn(ref _decl, ref _header, ref _generics, ref _body) = item.node {
170-
debug!("Walked function");
171-
}
172178
if item.vis.node.is_pub() { self.prev_level } else { None }
173179
}
174180
};
175181

176182
// Update level of the item itself
177183
let item_level = self.update(item.id, inherited_item_level);
178184

179-
debug!("believed to be: {:?}", item_level);
185+
debug!("Its privacy is believed to be: {:?}", item_level);
180186

181187
// Update levels of nested things
182188
match item.node {

0 commit comments

Comments
 (0)