]> git.proxmox.com Git - rustc.git/blobdiff - src/tools/clippy/tests/ui/doc_unsafe.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / doc_unsafe.rs
index 484aa72d59a25a43c6276ebf4d48dd7ba12e7c01..0c8eac5ccffc3a6af5c987446f3d310af8bf5dde 100644 (file)
@@ -1,7 +1,9 @@
-// aux-build:doc_unsafe_macros.rs
+//@aux-build:proc_macros.rs
 
-#[macro_use]
-extern crate doc_unsafe_macros;
+#![allow(clippy::let_unit_value)]
+
+extern crate proc_macros;
+use proc_macros::external;
 
 /// This is not sufficiently documented
 pub unsafe fn destroy_the_planet() {
@@ -34,16 +36,25 @@ mod private_mod {
 
 pub use private_mod::republished;
 
-pub trait UnsafeTrait {
+pub trait SafeTraitUnsafeMethods {
     unsafe fn woefully_underdocumented(self);
 
     /// # Safety
     unsafe fn at_least_somewhat_documented(self);
 }
 
+pub unsafe trait UnsafeTrait {
+    fn method();
+}
+
+/// # Safety
+pub unsafe trait DocumentedUnsafeTrait {
+    fn method2();
+}
+
 pub struct Struct;
 
-impl UnsafeTrait for Struct {
+impl SafeTraitUnsafeMethods for Struct {
     unsafe fn woefully_underdocumented(self) {
         // all is well
     }
@@ -53,6 +64,14 @@ impl UnsafeTrait for Struct {
     }
 }
 
+unsafe impl UnsafeTrait for Struct {
+    fn method() {}
+}
+
+unsafe impl DocumentedUnsafeTrait for Struct {
+    fn method2() {}
+}
+
 impl Struct {
     pub unsafe fn more_undocumented_unsafe() -> Self {
         unimplemented!();
@@ -86,7 +105,11 @@ macro_rules! very_unsafe {
 very_unsafe!();
 
 // we don't lint code from external macros
-undocd_unsafe!();
+external! {
+    pub unsafe fn oy_vey() {
+        unimplemented!();
+    }
+}
 
 fn main() {
     unsafe {
@@ -98,3 +121,18 @@ fn main() {
         drive();
     }
 }
+
+// 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() {}
+    }
+}
+
+/// # Implementation safety
+pub unsafe trait DocumentedUnsafeTraitWithImplementationHeader {
+    fn method();
+}