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