]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/unreachable_pub.rs
Move parse-fail tests to UI
[rust.git] / src / test / ui / lint / unreachable_pub.rs
1 // Copyright 2017 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 // compile-pass
12
13 #![feature(crate_visibility_modifier)]
14
15 #![allow(unused)]
16 #![warn(unreachable_pub)]
17
18 mod private_mod {
19     // non-leaked `pub` items in private module should be linted
20     pub use std::fmt;
21     pub use std::env::{Args}; // braced-use has different item spans than unbraced
22
23     pub struct Hydrogen {
24         // `pub` struct fields, too
25         pub neutrons: usize,
26         // (... but not more-restricted fields)
27         crate electrons: usize
28     }
29     impl Hydrogen {
30         // impls, too
31         pub fn count_neutrons(&self) -> usize { self.neutrons }
32         crate fn count_electrons(&self) -> usize { self.electrons }
33     }
34
35     pub enum Helium {}
36     pub union Lithium { c1: usize, c2: u8 }
37     pub fn beryllium() {}
38     pub trait Boron {}
39     pub const CARBON: usize = 1;
40     pub static NITROGEN: usize = 2;
41     pub type Oxygen = bool;
42
43     macro_rules! define_empty_struct_with_visibility {
44         ($visibility: vis, $name: ident) => { $visibility struct $name {} }
45     }
46     define_empty_struct_with_visibility!(pub, Fluorine);
47
48     extern {
49         pub fn catalyze() -> bool;
50     }
51
52     // items leaked through signatures (see `get_neon` below) are OK
53     pub struct Neon {}
54
55     // crate-visible items are OK
56     crate struct Sodium {}
57 }
58
59 pub mod public_mod {
60     // module is public: these are OK, too
61     pub struct Magnesium {}
62     crate struct Aluminum {}
63 }
64
65 pub fn get_neon() -> private_mod::Neon {
66     private_mod::Neon {}
67 }
68
69 fn main() {
70     let _ = get_neon();
71 }