]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/undocumented_unsafe_blocks.rs
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / undocumented_unsafe_blocks.rs
index fd64c60384d6ff4ee9434743a233761b87c31792..08aee4332151446a6fdd17603bd651cae7ee7306 100644 (file)
@@ -250,6 +250,11 @@ fn from_proc_macro() {
     proc_macro_unsafe::unsafe_block!(token);
 }
 
+fn in_closure(x: *const u32) {
+    // Safety: reason
+    let _ = || unsafe { *x };
+}
+
 // Invalid comments
 
 #[rustfmt::skip]
@@ -344,16 +349,16 @@ unsafe impl A for () {}
     unsafe impl A for (i32) {}
 
     mod sub_mod {
-        // error: also works for the first item
+        // error:
         unsafe impl B for (u32) {}
         unsafe trait B {}
     }
 
     #[rustfmt::skip]
     mod sub_mod2 {
-        // 
+        //
         // SAFETY: ok
-        // 
+        //
 
         unsafe impl B for (u32) {}
         unsafe trait B {}
@@ -363,24 +368,51 @@ unsafe trait B {}
 mod unsafe_impl_from_macro {
     unsafe trait T {}
 
+    // error
     macro_rules! no_safety_comment {
         ($t:ty) => {
             unsafe impl T for $t {}
         };
     }
-    // error
+
+    // ok
     no_safety_comment!(());
 
+    // ok
     macro_rules! with_safety_comment {
         ($t:ty) => {
             // SAFETY:
             unsafe impl T for $t {}
         };
     }
+
     // ok
     with_safety_comment!((i32));
 }
 
+mod unsafe_impl_macro_and_not_macro {
+    unsafe trait T {}
+
+    // error
+    macro_rules! no_safety_comment {
+        ($t:ty) => {
+            unsafe impl T for $t {}
+        };
+    }
+
+    // ok
+    no_safety_comment!(());
+
+    // error
+    unsafe impl T for (i32) {}
+
+    // ok
+    no_safety_comment!(u32);
+
+    // error
+    unsafe impl T for (bool) {}
+}
+
 #[rustfmt::skip]
 mod unsafe_impl_valid_comment {
     unsafe trait SaFety {}
@@ -440,4 +472,22 @@ unsafe trait Interference {}
     unsafe impl Interference for () {}
 }
 
+unsafe trait ImplInFn {}
+
+fn impl_in_fn() {
+    // error
+    unsafe impl ImplInFn for () {}
+
+    // SAFETY: ok
+    unsafe impl ImplInFn for (i32) {}
+}
+
+unsafe trait CrateRoot {}
+
+// error
+unsafe impl CrateRoot for () {}
+
+// SAFETY: ok
+unsafe impl CrateRoot for (i32) {}
+
 fn main() {}