2019-11-05 18:00:00 -06:00
|
|
|
// check-pass
|
2017-12-10 13:14:01 -06:00
|
|
|
|
2017-11-02 22:50:17 -05:00
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(unreachable_pub)]
|
|
|
|
|
|
|
|
mod private_mod {
|
|
|
|
// non-leaked `pub` items in private module should be linted
|
2019-11-05 18:00:00 -06:00
|
|
|
pub use std::fmt; //~ WARNING unreachable_pub
|
2018-05-06 00:14:33 -05:00
|
|
|
pub use std::env::{Args}; // braced-use has different item spans than unbraced
|
2019-11-05 18:00:00 -06:00
|
|
|
//~^ WARNING unreachable_pub
|
2017-11-02 22:50:17 -05:00
|
|
|
|
2019-11-05 18:00:00 -06:00
|
|
|
pub struct Hydrogen { //~ WARNING unreachable_pub
|
2017-11-02 22:50:17 -05:00
|
|
|
// `pub` struct fields, too
|
2019-11-05 18:00:00 -06:00
|
|
|
pub neutrons: usize, //~ WARNING unreachable_pub
|
2017-11-02 22:50:17 -05:00
|
|
|
// (... but not more-restricted fields)
|
2022-05-20 20:06:44 -05:00
|
|
|
pub(crate) electrons: usize
|
2017-11-02 22:50:17 -05:00
|
|
|
}
|
|
|
|
impl Hydrogen {
|
|
|
|
// impls, too
|
2019-11-05 18:00:00 -06:00
|
|
|
pub fn count_neutrons(&self) -> usize { self.neutrons } //~ WARNING unreachable_pub
|
2022-05-20 20:06:44 -05:00
|
|
|
pub(crate) fn count_electrons(&self) -> usize { self.electrons }
|
2017-11-02 22:50:17 -05:00
|
|
|
}
|
2022-02-13 12:38:36 -06:00
|
|
|
impl Clone for Hydrogen {
|
|
|
|
fn clone(&self) -> Hydrogen {
|
|
|
|
Hydrogen { neutrons: self.neutrons, electrons: self.electrons }
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 22:50:17 -05:00
|
|
|
|
2019-11-05 18:00:00 -06:00
|
|
|
pub enum Helium {} //~ WARNING unreachable_pub
|
|
|
|
pub union Lithium { c1: usize, c2: u8 } //~ WARNING unreachable_pub
|
|
|
|
pub fn beryllium() {} //~ WARNING unreachable_pub
|
|
|
|
pub trait Boron {} //~ WARNING unreachable_pub
|
|
|
|
pub const CARBON: usize = 1; //~ WARNING unreachable_pub
|
|
|
|
pub static NITROGEN: usize = 2; //~ WARNING unreachable_pub
|
|
|
|
pub type Oxygen = bool; //~ WARNING unreachable_pub
|
2017-11-02 22:50:17 -05:00
|
|
|
|
|
|
|
macro_rules! define_empty_struct_with_visibility {
|
|
|
|
($visibility: vis, $name: ident) => { $visibility struct $name {} }
|
2019-11-05 18:00:00 -06:00
|
|
|
//~^ WARNING unreachable_pub
|
2017-11-02 22:50:17 -05:00
|
|
|
}
|
|
|
|
define_empty_struct_with_visibility!(pub, Fluorine);
|
|
|
|
|
2020-09-01 16:12:52 -05:00
|
|
|
extern "C" {
|
2019-11-05 18:00:00 -06:00
|
|
|
pub fn catalyze() -> bool; //~ WARNING unreachable_pub
|
2017-11-02 22:50:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// items leaked through signatures (see `get_neon` below) are OK
|
|
|
|
pub struct Neon {}
|
|
|
|
|
|
|
|
// crate-visible items are OK
|
2022-05-20 20:06:44 -05:00
|
|
|
pub(crate) struct Sodium {}
|
2017-11-02 22:50:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub mod public_mod {
|
|
|
|
// module is public: these are OK, too
|
|
|
|
pub struct Magnesium {}
|
2022-05-20 20:06:44 -05:00
|
|
|
pub(crate) struct Aluminum {}
|
2017-11-02 22:50:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_neon() -> private_mod::Neon {
|
|
|
|
private_mod::Neon {}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _ = get_neon();
|
|
|
|
}
|