Skip to content

Commit 81684bf

Browse files
committed
New AccessLevel and accompanying propagation.
1 parent 00b2606 commit 81684bf

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/librustc/ich/impls_ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ impl_stable_hash_for!(enum traits::Reveal {
10861086
});
10871087

10881088
impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
1089+
ReachableFromImplTrait,
10891090
Reachable,
10901091
Exported,
10911092
Public

src/librustc/middle/privacy.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use syntax::ast::NodeId;
2222
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
2323
pub enum AccessLevel {
2424
// Superset of Reachable used to mark impl Trait items.
25-
// ReachableFromImplTrait,
25+
ReachableFromImplTrait,
2626
// Exported items + items participating in various kinds of public interfaces,
2727
// but not directly nameable. For example, if function `fn f() -> T {...}` is
2828
// public, then type `T` is reachable. Its values can be obtained by other crates
@@ -42,7 +42,8 @@ pub struct AccessLevels<Id = NodeId> {
4242

4343
impl<Id: Hash + Eq> AccessLevels<Id> {
4444
pub fn is_reachable(&self, id: Id) -> bool {
45-
self.map.contains_key(&id)
45+
// self.map.contains_key(&id)
46+
self.map.get(&id) >= Some(&AccessLevel::Reachable)
4647
}
4748
pub fn is_exported(&self, id: Id) -> bool {
4849
self.map.get(&id) >= Some(&AccessLevel::Exported)

src/librustc_privacy/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct EmbargoVisitor<'a, 'tcx: 'a> {
8484
}
8585

8686
struct ReachEverythingInTheInterfaceVisitor<'b, 'a: 'b, 'tcx: 'a> {
87+
access_level: Option<AccessLevel>,
8788
item_def_id: DefId,
8889
ev: &'b mut EmbargoVisitor<'a, 'tcx>,
8990
}
@@ -134,6 +135,7 @@ impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> {
134135
fn reach<'b>(&'b mut self, item_id: ast::NodeId)
135136
-> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> {
136137
ReachEverythingInTheInterfaceVisitor {
138+
access_level: self.prev_level.map(|l| l.min(AccessLevel::Reachable)),
137139
item_def_id: self.tcx.hir.local_def_id(item_id),
138140
ev: self,
139141
}
@@ -164,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
164166
hir::ItemKind::Existential(ref ty_data) => {
165167
if let Some(impl_trait_fn) = ty_data.impl_trait_fn {
166168
if let Some(node_id) = self.tcx.hir.as_local_node_id(impl_trait_fn) {
167-
self.update(node_id, Some(AccessLevel::Reachable));
169+
self.update(node_id, Some(AccessLevel::ReachableFromImplTrait));
168170
}
169171
}
170172
if item.vis.node.is_pub() { self.prev_level } else { None }
@@ -240,6 +242,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
240242
hir::ItemKind::ExternCrate(..) => {}
241243
}
242244

245+
let orig_level = self.prev_level;
246+
self.prev_level = item_level;
247+
243248
// Mark all items in interfaces of reachable items as reachable
244249
match item.node {
245250
// The interface is empty
@@ -337,9 +342,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
337342
}
338343
}
339344

340-
let orig_level = self.prev_level;
341-
self.prev_level = item_level;
342-
343345
intravisit::walk_item(self, item);
344346

345347
self.prev_level = orig_level;
@@ -475,7 +477,7 @@ impl<'b, 'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> {
475477
fn check_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>) {
476478
if let Some(node_id) = self.ev.tcx.hir.as_local_node_id(trait_ref.def_id) {
477479
let item = self.ev.tcx.hir.expect_item(node_id);
478-
self.ev.update(item.id, Some(AccessLevel::Reachable));
480+
self.ev.update(item.id, self.access_level);
479481
}
480482
}
481483
}
@@ -496,7 +498,7 @@ impl<'b, 'a, 'tcx> TypeVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'b
496498

497499
if let Some(def_id) = ty_def_id {
498500
if let Some(node_id) = self.ev.tcx.hir.as_local_node_id(def_id) {
499-
self.ev.update(node_id, Some(AccessLevel::Reachable));
501+
self.ev.update(node_id, self.access_level);
500502
}
501503
}
502504

0 commit comments

Comments
 (0)