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