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