]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/privacy.rs
rollup merge of #23867: nikomatsakis/issue-23086-take-3
[rust.git] / src / librustc / middle / privacy.rs
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.
4 //
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.
10
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.
14
15 pub use self::PrivateDep::*;
16 pub use self::ImportUse::*;
17 pub use self::LastPrivate::*;
18
19 use util::nodemap::{DefIdSet, NodeSet};
20
21 use syntax::ast;
22
23 /// A set of AST nodes exported by the crate.
24 pub type ExportedItems = NodeSet;
25
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;
29
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;
34
35 #[derive(Copy, Clone, Debug)]
36 pub enum LastPrivate {
37     LastMod(PrivateDep),
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
42     // in that namespace.
43     LastImport{value_priv: Option<PrivateDep>,
44                value_used: ImportUse,
45                type_priv: Option<PrivateDep>,
46                type_used: ImportUse},
47 }
48
49 #[derive(Copy, Clone, Debug)]
50 pub enum PrivateDep {
51     AllPublic,
52     DependsOn(ast::DefId),
53 }
54
55 // How an import is used.
56 #[derive(Copy, Clone, PartialEq, Debug)]
57 pub enum ImportUse {
58     Unused,       // The import is not used.
59     Used,         // The import is used.
60 }
61
62 impl LastPrivate {
63     pub fn or(self, other: LastPrivate) -> LastPrivate {
64         match (self, other) {
65             (me, LastMod(AllPublic)) => me,
66             (_, other) => other,
67         }
68     }
69 }