2023-04-20 10:19:36 -05:00
|
|
|
//@aux-build:proc_macros.rs:proc-macro
|
2020-01-04 13:19:14 -06:00
|
|
|
|
2022-03-17 18:53:28 -05:00
|
|
|
#![allow(clippy::let_unit_value)]
|
|
|
|
|
2023-03-07 08:40:55 -06:00
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::external;
|
2020-01-04 13:19:14 -06:00
|
|
|
|
2019-09-11 11:39:02 -05:00
|
|
|
/// This is not sufficiently documented
|
|
|
|
pub unsafe fn destroy_the_planet() {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This one is
|
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// This function shouldn't be called unless the horsemen are ready
|
|
|
|
pub unsafe fn apocalypse(universe: &mut ()) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This is a private function, so docs aren't necessary
|
|
|
|
unsafe fn you_dont_see_me() {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
2019-10-02 10:19:30 -05:00
|
|
|
mod private_mod {
|
|
|
|
pub unsafe fn only_crate_wide_accessible() {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn republished() {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use private_mod::republished;
|
|
|
|
|
2021-09-28 10:33:58 -05:00
|
|
|
pub trait SafeTraitUnsafeMethods {
|
2019-10-02 10:19:30 -05:00
|
|
|
unsafe fn woefully_underdocumented(self);
|
|
|
|
|
|
|
|
/// # Safety
|
|
|
|
unsafe fn at_least_somewhat_documented(self);
|
|
|
|
}
|
|
|
|
|
2021-09-28 10:33:58 -05:00
|
|
|
pub unsafe trait UnsafeTrait {
|
|
|
|
fn method();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// # Safety
|
|
|
|
pub unsafe trait DocumentedUnsafeTrait {
|
|
|
|
fn method2();
|
|
|
|
}
|
|
|
|
|
2019-10-02 10:19:30 -05:00
|
|
|
pub struct Struct;
|
|
|
|
|
2021-09-28 10:33:58 -05:00
|
|
|
impl SafeTraitUnsafeMethods for Struct {
|
2019-10-02 10:19:30 -05:00
|
|
|
unsafe fn woefully_underdocumented(self) {
|
|
|
|
// all is well
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn at_least_somewhat_documented(self) {
|
|
|
|
// all is still well
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 10:33:58 -05:00
|
|
|
unsafe impl UnsafeTrait for Struct {
|
|
|
|
fn method() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl DocumentedUnsafeTrait for Struct {
|
|
|
|
fn method2() {}
|
|
|
|
}
|
|
|
|
|
2019-10-02 10:19:30 -05:00
|
|
|
impl Struct {
|
|
|
|
pub unsafe fn more_undocumented_unsafe() -> Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// # Safety
|
|
|
|
pub unsafe fn somewhat_documented(&self) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn private(&self) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-04 13:19:14 -06:00
|
|
|
macro_rules! very_unsafe {
|
|
|
|
() => {
|
|
|
|
pub unsafe fn whee() {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// Please keep the seat belt fastened
|
|
|
|
pub unsafe fn drive() {
|
|
|
|
whee()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
very_unsafe!();
|
|
|
|
|
|
|
|
// we don't lint code from external macros
|
2023-03-07 08:40:55 -06:00
|
|
|
external! {
|
|
|
|
pub unsafe fn oy_vey() {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2020-01-04 13:19:14 -06:00
|
|
|
|
2019-09-11 11:39:02 -05:00
|
|
|
fn main() {
|
2019-10-02 10:19:30 -05:00
|
|
|
unsafe {
|
|
|
|
you_dont_see_me();
|
|
|
|
destroy_the_planet();
|
|
|
|
let mut universe = ();
|
|
|
|
apocalypse(&mut universe);
|
|
|
|
private_mod::only_crate_wide_accessible();
|
2020-01-04 13:19:14 -06:00
|
|
|
drive();
|
2019-10-02 10:19:30 -05:00
|
|
|
}
|
2019-09-11 11:39:02 -05:00
|
|
|
}
|
2021-10-14 05:16:35 -05:00
|
|
|
|
|
|
|
// do not lint if any parent has `#[doc(hidden)]` attribute
|
|
|
|
// see #7347
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub mod __macro {
|
|
|
|
pub struct T;
|
|
|
|
impl T {
|
|
|
|
pub unsafe fn f() {}
|
|
|
|
}
|
|
|
|
}
|
2021-10-21 10:50:50 -05:00
|
|
|
|
|
|
|
/// # Implementation safety
|
|
|
|
pub unsafe trait DocumentedUnsafeTraitWithImplementationHeader {
|
|
|
|
fn method();
|
|
|
|
}
|