Skip to content

Commit a74a050

Browse files
committed
rustc: middle: move some types from resolve to privacy.
1 parent 5d1257a commit a74a050

File tree

2 files changed

+70
-69
lines changed

2 files changed

+70
-69
lines changed

src/librustc/middle/privacy.rs

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@
1111
//! A pass that checks to make sure private fields and methods aren't used
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.
14+
pub use self::PrivateDep::*;
15+
pub use self::ImportUse::*;
16+
pub use self::LastPrivate::*;
1417
use self::PrivacyResult::*;
1518
use self::FieldName::*;
1619

1720
use std::mem::replace;
1821

1922
use metadata::csearch;
20-
use middle::{def, resolve};
23+
use middle::def;
2124
use middle::ty::{mod, Ty};
2225
use middle::ty::{MethodCall, MethodMap, MethodOrigin, MethodParam, MethodTypeParam};
2326
use middle::ty::{MethodStatic, MethodStaticUnboxedClosure, MethodObject, MethodTraitObject};
24-
use util::nodemap::{NodeMap, NodeSet};
27+
use util::nodemap::{DefIdSet, NodeMap, NodeSet};
2528

2629
use syntax::{ast, ast_map};
2730
use syntax::ast_util::{is_local, local_def, PostExpansionMethod};
@@ -34,11 +37,54 @@ type Context<'a, 'tcx> = (&'a MethodMap<'tcx>, &'a def::ExportMap);
3437
/// A set of AST nodes exported by the crate.
3538
pub type ExportedItems = NodeSet;
3639

40+
/// A set containing all exported definitions from external crates.
41+
/// The set does not contain any entries from local crates.
42+
pub type ExternalExports = DefIdSet;
43+
3744
/// A set of AST nodes that are fully public in the crate. This map is used for
3845
/// documentation purposes (reexporting a private struct inlines the doc,
3946
/// reexporting a public struct doesn't inline the doc).
4047
pub type PublicItems = NodeSet;
4148

49+
// FIXME: dox
50+
pub type LastPrivateMap = NodeMap<LastPrivate>;
51+
52+
#[deriving(Copy, Show)]
53+
pub enum LastPrivate {
54+
LastMod(PrivateDep),
55+
// `use` directives (imports) can refer to two separate definitions in the
56+
// type and value namespaces. We record here the last private node for each
57+
// and whether the import is in fact used for each.
58+
// If the Option<PrivateDep> fields are None, it means there is no definition
59+
// in that namespace.
60+
LastImport{value_priv: Option<PrivateDep>,
61+
value_used: ImportUse,
62+
type_priv: Option<PrivateDep>,
63+
type_used: ImportUse},
64+
}
65+
66+
#[deriving(Copy, Show)]
67+
pub enum PrivateDep {
68+
AllPublic,
69+
DependsOn(ast::DefId),
70+
}
71+
72+
// How an import is used.
73+
#[deriving(Copy, PartialEq, Show)]
74+
pub enum ImportUse {
75+
Unused, // The import is not used.
76+
Used, // The import is used.
77+
}
78+
79+
impl LastPrivate {
80+
pub fn or(self, other: LastPrivate) -> LastPrivate {
81+
match (self, other) {
82+
(me, LastMod(AllPublic)) => me,
83+
(_, other) => other,
84+
}
85+
}
86+
}
87+
4288
/// Result of a checking operation - None => no errors were found. Some => an
4389
/// error and contains the span and message for reporting that error and
4490
/// optionally the same for a note about the error.
@@ -362,8 +408,8 @@ struct PrivacyVisitor<'a, 'tcx: 'a> {
362408
curitem: ast::NodeId,
363409
in_foreign: bool,
364410
parents: NodeMap<ast::NodeId>,
365-
external_exports: resolve::ExternalExports,
366-
last_private_map: resolve::LastPrivateMap,
411+
external_exports: ExternalExports,
412+
last_private_map: LastPrivateMap,
367413
}
368414

369415
enum PrivacyResult {
@@ -719,25 +765,25 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
719765
};
720766

721767
match self.last_private_map[path_id] {
722-
resolve::LastMod(resolve::AllPublic) => {},
723-
resolve::LastMod(resolve::DependsOn(def)) => {
768+
LastMod(AllPublic) => {},
769+
LastMod(DependsOn(def)) => {
724770
self.report_error(ck_public(def));
725771
},
726-
resolve::LastImport{value_priv,
727-
value_used: check_value,
728-
type_priv,
729-
type_used: check_type} => {
772+
LastImport { value_priv,
773+
value_used: check_value,
774+
type_priv,
775+
type_used: check_type } => {
730776
// This dance with found_error is because we don't want to report
731777
// a privacy error twice for the same directive.
732778
let found_error = match (type_priv, check_type) {
733-
(Some(resolve::DependsOn(def)), resolve::Used) => {
779+
(Some(DependsOn(def)), Used) => {
734780
!self.report_error(ck_public(def))
735781
},
736782
_ => false,
737783
};
738784
if !found_error {
739785
match (value_priv, check_value) {
740-
(Some(resolve::DependsOn(def)), resolve::Used) => {
786+
(Some(DependsOn(def)), Used) => {
741787
self.report_error(ck_public(def));
742788
},
743789
_ => {},
@@ -749,24 +795,24 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
749795
// be illegal. We only report one error, even if it is
750796
// illegal to import from both namespaces.
751797
match (value_priv, check_value, type_priv, check_type) {
752-
(Some(p), resolve::Unused, None, _) |
753-
(None, _, Some(p), resolve::Unused) => {
798+
(Some(p), Unused, None, _) |
799+
(None, _, Some(p), Unused) => {
754800
let p = match p {
755-
resolve::AllPublic => None,
756-
resolve::DependsOn(def) => ck_public(def),
801+
AllPublic => None,
802+
DependsOn(def) => ck_public(def),
757803
};
758804
if p.is_some() {
759805
self.report_error(p);
760806
}
761807
},
762-
(Some(v), resolve::Unused, Some(t), resolve::Unused) => {
808+
(Some(v), Unused, Some(t), Unused) => {
763809
let v = match v {
764-
resolve::AllPublic => None,
765-
resolve::DependsOn(def) => ck_public(def),
810+
AllPublic => None,
811+
DependsOn(def) => ck_public(def),
766812
};
767813
let t = match t {
768-
resolve::AllPublic => None,
769-
resolve::DependsOn(def) => ck_public(def),
814+
AllPublic => None,
815+
DependsOn(def) => ck_public(def),
770816
};
771817
if let (Some(_), Some(t)) = (v, t) {
772818
self.report_error(Some(t));
@@ -1521,8 +1567,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
15211567

15221568
pub fn check_crate(tcx: &ty::ctxt,
15231569
export_map: &def::ExportMap,
1524-
external_exports: resolve::ExternalExports,
1525-
last_private_map: resolve::LastPrivateMap)
1570+
external_exports: ExternalExports,
1571+
last_private_map: LastPrivateMap)
15261572
-> (ExportedItems, PublicItems) {
15271573
let krate = tcx.map.krate();
15281574

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
pub use self::PrivateDep::*;
12-
pub use self::ImportUse::*;
13-
pub use self::LastPrivate::*;
1411
use self::PatternBindingMode::*;
1512
use self::Namespace::*;
1613
use self::NamespaceError::*;
@@ -40,6 +37,7 @@ use metadata::decoder::{DefLike, DlDef, DlField, DlImpl};
4037
use middle::def::*;
4138
use middle::lang_items::LanguageItems;
4239
use middle::pat_util::pat_bindings;
40+
use middle::privacy::*;
4341
use middle::subst::{ParamSpace, FnSpace, TypeSpace};
4442
use middle::ty::{CaptureModeMap, Freevar, FreevarMap, TraitMap};
4543
use util::nodemap::{NodeMap, NodeSet, DefIdSet, FnvHashMap};
@@ -91,49 +89,6 @@ struct BindingInfo {
9189
// Map from the name in a pattern to its binding mode.
9290
type BindingMap = HashMap<Name, BindingInfo>;
9391

94-
// This set contains all exported definitions from external crates. The set does
95-
// not contain any entries from local crates.
96-
pub type ExternalExports = DefIdSet;
97-
98-
// FIXME: dox
99-
pub type LastPrivateMap = NodeMap<LastPrivate>;
100-
101-
#[deriving(Copy, Show)]
102-
pub enum LastPrivate {
103-
LastMod(PrivateDep),
104-
// `use` directives (imports) can refer to two separate definitions in the
105-
// type and value namespaces. We record here the last private node for each
106-
// and whether the import is in fact used for each.
107-
// If the Option<PrivateDep> fields are None, it means there is no definition
108-
// in that namespace.
109-
LastImport{value_priv: Option<PrivateDep>,
110-
value_used: ImportUse,
111-
type_priv: Option<PrivateDep>,
112-
type_used: ImportUse},
113-
}
114-
115-
#[deriving(Copy, Show)]
116-
pub enum PrivateDep {
117-
AllPublic,
118-
DependsOn(DefId),
119-
}
120-
121-
// How an import is used.
122-
#[deriving(Copy, PartialEq, Show)]
123-
pub enum ImportUse {
124-
Unused, // The import is not used.
125-
Used, // The import is used.
126-
}
127-
128-
impl LastPrivate {
129-
fn or(self, other: LastPrivate) -> LastPrivate {
130-
match (self, other) {
131-
(me, LastMod(AllPublic)) => me,
132-
(_, other) => other,
133-
}
134-
}
135-
}
136-
13792
#[deriving(Copy, PartialEq)]
13893
enum PatternBindingMode {
13994
RefutableMode,

0 commit comments

Comments
 (0)