]> git.proxmox.com Git - rustc.git/blame - src/test/ui/lint/unreachable_pub-pub_crate.rs
New upstream version 1.28.0~beta.14+dfsg1
[rustc.git] / src / test / ui / lint / unreachable_pub-pub_crate.rs
CommitLineData
abe05a73
XL
1// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11// This is just like unreachable_pub.rs, but without the
12// `crate_visibility_modifier` feature (so that we can test the suggestions to
13// use `pub(crate)` that are given when that feature is off, as opposed to the
14// suggestions to use `crate` given when it is on). When that feature becomes
15// stable, this test can be deleted.
16
83c7162d 17// compile-pass
ff7c6d11 18
abe05a73
XL
19#![feature(macro_vis_matcher)]
20
21#![allow(unused)]
22#![warn(unreachable_pub)]
23
24mod private_mod {
25 // non-leaked `pub` items in private module should be linted
26 pub use std::fmt;
94b46f34 27 pub use std::env::{Args}; // braced-use has different item spans than unbraced
abe05a73
XL
28
29 pub struct Hydrogen {
30 // `pub` struct fields, too
31 pub neutrons: usize,
32 // (... but not more-restricted fields)
33 pub(crate) electrons: usize
34 }
35 impl Hydrogen {
36 // impls, too
37 pub fn count_neutrons(&self) -> usize { self.neutrons }
38 pub(crate) fn count_electrons(&self) -> usize { self.electrons }
39 }
40
41 pub enum Helium {}
42 pub union Lithium { c1: usize, c2: u8 }
43 pub fn beryllium() {}
44 pub trait Boron {}
45 pub const CARBON: usize = 1;
46 pub static NITROGEN: usize = 2;
47 pub type Oxygen = bool;
48
49 macro_rules! define_empty_struct_with_visibility {
50 ($visibility: vis, $name: ident) => { $visibility struct $name {} }
51 }
52 define_empty_struct_with_visibility!(pub, Fluorine);
53
54 extern {
55 pub fn catalyze() -> bool;
56 }
57
58 // items leaked through signatures (see `get_neon` below) are OK
59 pub struct Neon {}
60
61 // crate-visible items are OK
62 pub(crate) struct Sodium {}
63}
64
65pub mod public_mod {
66 // module is public: these are OK, too
67 pub struct Magnesium {}
68 pub(crate) struct Aluminum {}
69}
70
71pub fn get_neon() -> private_mod::Neon {
72 private_mod::Neon {}
73}
74
75fn main() {
76 let _ = get_neon();
77}