1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! A pass that checks to make sure private fields and methods aren't used
12 //! outside their scopes. This pass will also generate a set of exported items
13 //! which are available for use externally when compiled as a library.
15 pub use self::PrivateDep::*;
16 pub use self::ImportUse::*;
17 pub use self::LastPrivate::*;
19 use middle::def_id::DefId;
20 use util::nodemap::{DefIdSet, NodeSet};
22 /// A set of AST nodes exported by the crate.
23 pub type ExportedItems = NodeSet;
25 /// A set containing all exported definitions from external crates.
26 /// The set does not contain any entries from local crates.
27 pub type ExternalExports = DefIdSet;
29 /// A set of AST nodes that are fully public in the crate. This map is used for
30 /// documentation purposes (reexporting a private struct inlines the doc,
31 /// reexporting a public struct doesn't inline the doc).
32 pub type PublicItems = NodeSet;
34 #[derive(Copy, Clone, Debug)]
35 pub enum LastPrivate {
37 // `use` directives (imports) can refer to two separate definitions in the
38 // type and value namespaces. We record here the last private node for each
39 // and whether the import is in fact used for each.
40 // If the Option<PrivateDep> fields are None, it means there is no definition
42 LastImport{value_priv: Option<PrivateDep>,
43 value_used: ImportUse,
44 type_priv: Option<PrivateDep>,
45 type_used: ImportUse},
48 #[derive(Copy, Clone, Debug)]
54 // How an import is used.
55 #[derive(Copy, Clone, PartialEq, Debug)]
57 Unused, // The import is not used.
58 Used, // The import is used.
62 pub fn or(self, other: LastPrivate) -> LastPrivate {
64 (me, LastMod(AllPublic)) => me,