Skip to content

Commit 8f32fde

Browse files
committed
Remove LastPrivate
1 parent ec0fdd5 commit 8f32fde

File tree

11 files changed

+43
-372
lines changed

11 files changed

+43
-372
lines changed

src/librustc/middle/def.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use middle::def_id::DefId;
12-
use middle::privacy::LastPrivate;
1312
use middle::subst::ParamSpace;
1413
use util::nodemap::NodeMap;
1514
use syntax::ast;
@@ -65,7 +64,6 @@ pub enum Def {
6564
#[derive(Copy, Clone, Debug)]
6665
pub struct PathResolution {
6766
pub base_def: Def,
68-
pub last_private: LastPrivate,
6967
pub depth: usize
7068
}
7169

@@ -84,12 +82,10 @@ impl PathResolution {
8482
}
8583

8684
pub fn new(base_def: Def,
87-
last_private: LastPrivate,
8885
depth: usize)
8986
-> PathResolution {
9087
PathResolution {
9188
base_def: base_def,
92-
last_private: last_private,
9389
depth: depth,
9490
}
9591
}

src/librustc/middle/privacy.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
//! outside their scopes. This pass will also generate a set of exported items
1313
//! which are available for use externally when compiled as a library.
1414
15-
pub use self::PrivateDep::*;
16-
pub use self::ImportUse::*;
17-
pub use self::LastPrivate::*;
18-
19-
use middle::def_id::DefId;
2015
use util::nodemap::{DefIdSet, FnvHashMap};
2116

2217
use std::hash::Hash;
@@ -64,39 +59,3 @@ impl<Id: Hash + Eq> Default for AccessLevels<Id> {
6459
/// A set containing all exported definitions from external crates.
6560
/// The set does not contain any entries from local crates.
6661
pub type ExternalExports = DefIdSet;
67-
68-
#[derive(Copy, Clone, Debug)]
69-
pub enum LastPrivate {
70-
LastMod(PrivateDep),
71-
// `use` directives (imports) can refer to two separate definitions in the
72-
// type and value namespaces. We record here the last private node for each
73-
// and whether the import is in fact used for each.
74-
// If the Option<PrivateDep> fields are None, it means there is no definition
75-
// in that namespace.
76-
LastImport{value_priv: Option<PrivateDep>,
77-
value_used: ImportUse,
78-
type_priv: Option<PrivateDep>,
79-
type_used: ImportUse},
80-
}
81-
82-
#[derive(Copy, Clone, Debug)]
83-
pub enum PrivateDep {
84-
AllPublic,
85-
DependsOn(DefId),
86-
}
87-
88-
// How an import is used.
89-
#[derive(Copy, Clone, PartialEq, Debug)]
90-
pub enum ImportUse {
91-
Unused, // The import is not used.
92-
Used, // The import is used.
93-
}
94-
95-
impl LastPrivate {
96-
pub fn or(self, other: LastPrivate) -> LastPrivate {
97-
match (self, other) {
98-
(me, LastMod(AllPublic)) => me,
99-
(_, other) => other,
100-
}
101-
}
102-
}

src/librustc_metadata/astencode.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use middle::ty::cast;
3232
use middle::const_qualif::ConstQualif;
3333
use middle::def::{self, Def};
3434
use middle::def_id::DefId;
35-
use middle::privacy::{AllPublic, LastMod};
3635
use middle::region;
3736
use middle::subst;
3837
use middle::ty::{self, Ty};
@@ -1161,8 +1160,6 @@ fn decode_side_tables(dcx: &DecodeContext,
11611160
let def = decode_def(dcx, val_dsr);
11621161
dcx.tcx.def_map.borrow_mut().insert(id, def::PathResolution {
11631162
base_def: def,
1164-
// This doesn't matter cross-crate.
1165-
last_private: LastMod(AllPublic),
11661163
depth: 0
11671164
});
11681165
}

src/librustc_privacy/lib.rs

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ use rustc::lint;
4141
use rustc::middle::def::{self, Def};
4242
use rustc::middle::def_id::DefId;
4343
use rustc::middle::privacy::{AccessLevel, AccessLevels};
44-
use rustc::middle::privacy::ImportUse::*;
45-
use rustc::middle::privacy::LastPrivate::*;
46-
use rustc::middle::privacy::PrivateDep::*;
4744
use rustc::middle::privacy::ExternalExports;
4845
use rustc::middle::ty;
4946
use rustc::util::nodemap::{NodeMap, NodeSet};
@@ -718,7 +715,6 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
718715
source_did: Option<DefId>,
719716
msg: &str)
720717
-> CheckResult {
721-
use rustc_front::hir::Item_::ItemExternCrate;
722718
debug!("ensure_public(span={:?}, to_check={:?}, source_did={:?}, msg={:?})",
723719
span, to_check, source_did, msg);
724720
let def_privacy = self.def_privacy(to_check);
@@ -740,20 +736,6 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
740736
let def_id = source_did.unwrap_or(to_check);
741737
let node_id = self.tcx.map.as_local_node_id(def_id);
742738

743-
// Warn when using a inaccessible extern crate.
744-
if let Some(node_id) = self.tcx.map.as_local_node_id(to_check) {
745-
match self.tcx.map.get(node_id) {
746-
ast_map::Node::NodeItem(&hir::Item { node: ItemExternCrate(_), name, .. }) => {
747-
self.tcx.sess.add_lint(lint::builtin::INACCESSIBLE_EXTERN_CRATE,
748-
node_id,
749-
span,
750-
format!("extern crate `{}` is private", name));
751-
return None;
752-
}
753-
_ => {}
754-
}
755-
}
756-
757739
let (err_span, err_msg) = if Some(id) == node_id {
758740
return Some((span, format!("{} is private", msg), None));
759741
} else {
@@ -842,90 +824,6 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
842824
name)));
843825
}
844826

845-
// Checks that a path is in scope.
846-
fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Name) {
847-
debug!("privacy - path {}", self.nodestr(path_id));
848-
let path_res = *self.tcx.def_map.borrow().get(&path_id).unwrap();
849-
let ck = |tyname: &str| {
850-
let ck_public = |def: DefId| {
851-
debug!("privacy - ck_public {:?}", def);
852-
let origdid = path_res.def_id();
853-
self.ensure_public(span,
854-
def,
855-
Some(origdid),
856-
&format!("{} `{}`", tyname, last))
857-
};
858-
859-
match path_res.last_private {
860-
LastMod(AllPublic) => {},
861-
LastMod(DependsOn(def)) => {
862-
self.report_error(ck_public(def));
863-
},
864-
LastImport { value_priv,
865-
value_used: check_value,
866-
type_priv,
867-
type_used: check_type } => {
868-
// This dance with found_error is because we don't want to
869-
// report a privacy error twice for the same directive.
870-
let found_error = match (type_priv, check_type) {
871-
(Some(DependsOn(def)), Used) => {
872-
!self.report_error(ck_public(def))
873-
},
874-
_ => false,
875-
};
876-
if !found_error {
877-
match (value_priv, check_value) {
878-
(Some(DependsOn(def)), Used) => {
879-
self.report_error(ck_public(def));
880-
},
881-
_ => {},
882-
}
883-
}
884-
// If an import is not used in either namespace, we still
885-
// want to check that it could be legal. Therefore we check
886-
// in both namespaces and only report an error if both would
887-
// be illegal. We only report one error, even if it is
888-
// illegal to import from both namespaces.
889-
match (value_priv, check_value, type_priv, check_type) {
890-
(Some(p), Unused, None, _) |
891-
(None, _, Some(p), Unused) => {
892-
let p = match p {
893-
AllPublic => None,
894-
DependsOn(def) => ck_public(def),
895-
};
896-
if p.is_some() {
897-
self.report_error(p);
898-
}
899-
},
900-
(Some(v), Unused, Some(t), Unused) => {
901-
let v = match v {
902-
AllPublic => None,
903-
DependsOn(def) => ck_public(def),
904-
};
905-
let t = match t {
906-
AllPublic => None,
907-
DependsOn(def) => ck_public(def),
908-
};
909-
if let (Some(_), Some(t)) = (v, t) {
910-
self.report_error(Some(t));
911-
}
912-
},
913-
_ => {},
914-
}
915-
},
916-
}
917-
};
918-
// FIXME(#12334) Imports can refer to definitions in both the type and
919-
// value namespaces. The privacy information is aware of this, but the
920-
// def map is not. Therefore the names we work out below will not always
921-
// be accurate and we can get slightly wonky error messages (but type
922-
// checking is always correct).
923-
let def = path_res.full_def();
924-
if def != Def::Err {
925-
ck(def.kind_name());
926-
}
927-
}
928-
929827
// Checks that a method is in scope.
930828
fn check_method(&mut self, span: Span, method_def_id: DefId,
931829
name: ast::Name) {
@@ -1067,25 +965,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
1067965
intravisit::walk_foreign_item(self, fi);
1068966
self.in_foreign = false;
1069967
}
1070-
1071-
fn visit_path(&mut self, path: &hir::Path, id: ast::NodeId) {
1072-
if !path.segments.is_empty() {
1073-
self.check_path(path.span, id, path.segments.last().unwrap().identifier.name);
1074-
intravisit::walk_path(self, path);
1075-
}
1076-
}
1077-
1078-
fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) {
1079-
let name = if let hir::PathListIdent { name, .. } = item.node {
1080-
name
1081-
} else if !prefix.segments.is_empty() {
1082-
prefix.segments.last().unwrap().identifier.name
1083-
} else {
1084-
self.tcx.sess.bug("`self` import in an import list with empty prefix");
1085-
};
1086-
self.check_path(item.span, item.node.id(), name);
1087-
intravisit::walk_path_list_item(self, prefix, item);
1088-
}
1089968
}
1090969

1091970
////////////////////////////////////////////////////////////////////////////////

src/librustc_resolve/check_unused.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use Resolver;
2323
use Namespace::{TypeNS, ValueNS};
2424

2525
use rustc::lint;
26-
use rustc::middle::privacy::{DependsOn, LastImport, Used, Unused};
2726
use syntax::ast;
2827
use syntax::codemap::{Span, DUMMY_SP};
2928

@@ -69,45 +68,6 @@ impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
6968
span,
7069
"unused import".to_string());
7170
}
72-
73-
let mut def_map = self.def_map.borrow_mut();
74-
let path_res = if let Some(r) = def_map.get_mut(&id) {
75-
r
76-
} else {
77-
return;
78-
};
79-
let (v_priv, t_priv) = match path_res.last_private {
80-
LastImport { value_priv, type_priv, .. } => (value_priv, type_priv),
81-
_ => {
82-
panic!("we should only have LastImport for `use` directives")
83-
}
84-
};
85-
86-
let mut v_used = if self.used_imports.contains(&(id, ValueNS)) {
87-
Used
88-
} else {
89-
Unused
90-
};
91-
let t_used = if self.used_imports.contains(&(id, TypeNS)) {
92-
Used
93-
} else {
94-
Unused
95-
};
96-
97-
match (v_priv, t_priv) {
98-
// Since some items may be both in the value _and_ type namespaces (e.g., structs)
99-
// we might have two LastPrivates pointing at the same thing. There is no point
100-
// checking both, so lets not check the value one.
101-
(Some(DependsOn(def_v)), Some(DependsOn(def_t))) if def_v == def_t => v_used = Unused,
102-
_ => {}
103-
}
104-
105-
path_res.last_private = LastImport {
106-
value_priv: v_priv,
107-
value_used: v_used,
108-
type_priv: t_priv,
109-
type_used: t_used,
110-
};
11171
}
11272
}
11373

0 commit comments

Comments
 (0)