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