forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#132877 - matthiaskrgr:rollup-hbxg7p0, r=matth…
…iaskrgr Rollup of 3 pull requests Successful merges: - rust-lang#131781 (Stabilize Arm64EC inline assembly) - rust-lang#132426 (Prefer `pub(super)` in `unreachable_pub` lint suggestion) - rust-lang#132866 (Break from review rotation) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
11 changed files
with
314 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
//@ check-pass | ||
//@ edition: 2018 | ||
//@ run-rustfix | ||
|
||
#![allow(unused)] | ||
#![warn(unreachable_pub)] | ||
|
||
mod private_mod { | ||
// non-leaked `pub` items in private module should be linted | ||
pub(crate) use std::fmt; //~ WARNING unreachable_pub | ||
pub(crate) use std::env::{Args}; // braced-use has different item spans than unbraced | ||
//~^ WARNING unreachable_pub | ||
|
||
// we lint on struct definition | ||
pub(crate) struct Hydrogen { //~ WARNING unreachable_pub | ||
// but not on fields, even if they are `pub` as putting `pub(crate)` | ||
// it would clutter the source code for little value | ||
pub neutrons: usize, | ||
pub(crate) electrons: usize | ||
} | ||
pub(crate) struct Calcium { | ||
pub neutrons: usize, | ||
} | ||
impl Hydrogen { | ||
// impls, too | ||
pub(crate) fn count_neutrons(&self) -> usize { self.neutrons } //~ WARNING unreachable_pub | ||
pub(crate) fn count_electrons(&self) -> usize { self.electrons } | ||
} | ||
impl Clone for Hydrogen { | ||
fn clone(&self) -> Hydrogen { | ||
Hydrogen { neutrons: self.neutrons, electrons: self.electrons } | ||
} | ||
} | ||
|
||
pub(crate) enum Helium {} //~ WARNING unreachable_pub | ||
pub(crate) union Lithium { c1: usize, c2: u8 } //~ WARNING unreachable_pub | ||
pub(crate) fn beryllium() {} //~ WARNING unreachable_pub | ||
pub(crate) trait Boron {} //~ WARNING unreachable_pub | ||
pub(crate) const CARBON: usize = 1; //~ WARNING unreachable_pub | ||
pub(crate) static NITROGEN: usize = 2; //~ WARNING unreachable_pub | ||
pub(crate) type Oxygen = bool; //~ WARNING unreachable_pub | ||
|
||
macro_rules! define_empty_struct_with_visibility { | ||
($visibility: vis, $name: ident) => { $visibility struct $name {} } | ||
//~^ WARNING unreachable_pub | ||
} | ||
define_empty_struct_with_visibility!(pub(crate), Fluorine); | ||
|
||
extern "C" { | ||
pub(crate) fn catalyze() -> bool; //~ WARNING unreachable_pub | ||
} | ||
|
||
mod private_in_private { | ||
pub(super) enum Helium {} //~ WARNING unreachable_pub | ||
pub(super) fn beryllium() {} //~ WARNING unreachable_pub | ||
} | ||
|
||
pub(crate) mod crate_in_private { | ||
pub(crate) const CARBON: usize = 1; //~ WARNING unreachable_pub | ||
} | ||
|
||
pub(crate) mod pub_in_private { //~ WARNING unreachable_pub | ||
pub(crate) static NITROGEN: usize = 2; //~ WARNING unreachable_pub | ||
} | ||
|
||
fn foo() { | ||
const { | ||
pub(crate) struct Foo; //~ WARNING unreachable_pub | ||
}; | ||
} | ||
|
||
enum Weird { | ||
Variant = { | ||
pub(crate) struct Foo; //~ WARNING unreachable_pub | ||
|
||
mod tmp { | ||
pub(crate) struct Bar; //~ WARNING unreachable_pub | ||
} | ||
|
||
let _ = tmp::Bar; | ||
|
||
0 | ||
}, | ||
} | ||
|
||
pub(crate) use fpu_precision::set_precision; //~ WARNING unreachable_pub | ||
|
||
mod fpu_precision { | ||
pub(crate) fn set_precision<T>() {} //~ WARNING unreachable_pub | ||
pub(super) fn set_micro_precision<T>() {} //~ WARNING unreachable_pub | ||
} | ||
|
||
// items leaked through signatures (see `get_neon` below) are OK | ||
pub struct Neon {} | ||
|
||
// crate-visible items are OK | ||
pub(crate) struct Sodium {} | ||
} | ||
|
||
pub mod public_mod { | ||
// module is public: these are OK, too | ||
pub struct Magnesium {} | ||
pub(crate) struct Aluminum {} | ||
} | ||
|
||
pub fn get_neon() -> private_mod::Neon { | ||
private_mod::Neon {} | ||
} | ||
|
||
fn main() { | ||
let _ = get_neon(); | ||
let _ = private_mod::beryllium(); | ||
let _ = private_mod::crate_in_private::CARBON; | ||
let _ = private_mod::pub_in_private::NITROGEN; | ||
let _ = unsafe { private_mod::catalyze() }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.