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