]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
abe05a73
XL
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
60c5eb7d 7// check-pass
ff7c6d11 8
abe05a73 9
abe05a73
XL
10#![warn(unreachable_pub)]
11
12mod private_mod {
13 // non-leaked `pub` items in private module should be linted
60c5eb7d 14 pub use std::fmt; //~ WARNING unreachable_pub
94b46f34 15 pub use std::env::{Args}; // braced-use has different item spans than unbraced
60c5eb7d 16 //~^ WARNING unreachable_pub
abe05a73 17
60c5eb7d 18 pub struct Hydrogen { //~ WARNING unreachable_pub
abe05a73 19 // `pub` struct fields, too
60c5eb7d 20 pub neutrons: usize, //~ WARNING unreachable_pub
abe05a73
XL
21 // (... but not more-restricted fields)
22 pub(crate) electrons: usize
23 }
24 impl Hydrogen {
25 // impls, too
60c5eb7d 26 pub fn count_neutrons(&self) -> usize { self.neutrons } //~ WARNING unreachable_pub
abe05a73
XL
27 pub(crate) fn count_electrons(&self) -> usize { self.electrons }
28 }
29
60c5eb7d
XL
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
abe05a73
XL
37
38 macro_rules! define_empty_struct_with_visibility {
39 ($visibility: vis, $name: ident) => { $visibility struct $name {} }
60c5eb7d 40 //~^ WARNING unreachable_pub
abe05a73
XL
41 }
42 define_empty_struct_with_visibility!(pub, Fluorine);
43
44 extern {
60c5eb7d 45 pub fn catalyze() -> bool; //~ WARNING unreachable_pub
abe05a73
XL
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
55pub mod public_mod {
56 // module is public: these are OK, too
57 pub struct Magnesium {}
58 pub(crate) struct Aluminum {}
59}
60
61pub fn get_neon() -> private_mod::Neon {
62 private_mod::Neon {}
63}
64
65fn main() {
66 let _ = get_neon();
67}