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