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 util::nodemap::{DefIdSet, NodeSet};
23 /// A set of AST nodes exported by the crate.
24 pub type ExportedItems = NodeSet;
26 /// A set containing all exported definitions from external crates.
27 /// The set does not contain any entries from local crates.
28 pub type ExternalExports = DefIdSet;
30 /// A set of AST nodes that are fully public in the crate. This map is used for
31 /// documentation purposes (reexporting a private struct inlines the doc,
32 /// reexporting a public struct doesn't inline the doc).
33 pub type PublicItems = NodeSet;
35 #[derive(Copy, Debug)]
36 pub enum LastPrivate {
38 // `use` directives (imports) can refer to two separate definitions in the
39 // type and value namespaces. We record here the last private node for each
40 // and whether the import is in fact used for each.
41 // If the Option<PrivateDep> fields are None, it means there is no definition
43 LastImport{value_priv: Option<PrivateDep>,
44 value_used: ImportUse,
45 type_priv: Option<PrivateDep>,
46 type_used: ImportUse},
49 #[derive(Copy, Debug)]
52 DependsOn(ast::DefId),
55 // How an import is used.
56 #[derive(Copy, PartialEq, Debug)]
58 Unused, // The import is not used.
59 Used, // The import is used.
63 pub fn or(self, other: LastPrivate) -> LastPrivate {
65 (me, LastMod(AllPublic)) => me,