1 // aux-build:proc_macro_unsafe.rs
3 #![warn(clippy::undocumented_unsafe_blocks)]
4 #![allow(clippy::let_unit_value, clippy::missing_safety_doc)]
6 extern crate proc_macro_unsafe;
56 fn local_tuple_expression() {
58 let _ = (42, unsafe {});
66 fn line_comment_newlines() {
72 fn line_comment_empty() {
80 fn line_comment_with_extras() {
81 // This is a description
91 fn block_comment_newlines() {
97 fn block_comment_with_extras() {
98 /* This is a description
104 fn block_comment_terminator_same_line() {
105 /* This is a description
111 // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
112 // incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
113 // ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
114 // reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
115 // occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
117 // Tellus elementum sagittis vitae et leo duis ut diam quam. Sit amet nulla facilisi
118 // morbi tempus iaculis urna. Amet luctus venenatis lectus magna. At quis risus sed vulputate odio
119 // ut. Luctus venenatis lectus magna fringilla urna. Tortor id aliquet lectus proin nibh nisl
120 // condimentum id venenatis. Vulputate dignissim suspendisse in est ante in nibh mauris cursus.
124 fn safety_with_prepended_text() {
125 // This is a test. safety:
129 fn local_line_comment() {
134 fn local_block_comment() {
141 let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
146 let _ = (42, unsafe {}, "test", unsafe {});
151 let _ = *unsafe { &42 };
154 #[allow(clippy::match_single_binding)]
157 let _ = match unsafe {} {
162 fn comment_addr_of() {
167 fn comment_repeat() {
169 let _ = [unsafe {}; 5];
172 fn comment_macro_call() {
185 fn comment_macro_def() {
196 fn non_ascii_comment() {
201 fn local_commented_block() {
209 let _ = [(42, unsafe {}, unsafe {}), (52, unsafe {}, unsafe {})];
212 fn in_fn_call(x: *const u32) {
219 fn multi_in_fn_call(x: *const u32) {
220 fn f(x: u32, y: u32) {}
223 f(unsafe { *x }, unsafe { *x });
226 fn in_multiline_fn_call(x: *const u32) {
227 fn f(x: u32, y: u32) {}
236 fn in_macro_call(x: *const u32) {
238 println!("{}", unsafe { *x });
241 fn in_multiline_macro_call(x: *const u32) {
249 fn from_proc_macro() {
250 proc_macro_unsafe::unsafe_block!(token);
253 fn in_closure(x: *const u32) {
255 let _ = || unsafe { *x };
261 fn inline_block_comment() {
262 /* Safety: */ unsafe {}
269 fn no_comment_array() {
270 let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
273 fn no_comment_tuple() {
274 let _ = (42, unsafe {}, "test", unsafe {});
277 fn no_comment_unary() {
278 let _ = *unsafe { &42 };
281 #[allow(clippy::match_single_binding)]
282 fn no_comment_match() {
283 let _ = match unsafe {} {
288 fn no_comment_addr_of() {
292 fn no_comment_repeat() {
293 let _ = [unsafe {}; 5];
296 fn local_no_comment() {
300 fn no_comment_macro_call() {
310 fn no_comment_macro_def() {
320 fn trailing_comment() {
324 fn internal_comment() {
338 pub fn print_binary_tree() {
339 println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
342 mod unsafe_impl_smoke_test {
345 // error: no safety comment
346 unsafe impl A for () {}
349 unsafe impl A for (i32) {}
353 unsafe impl B for (u32) {}
363 unsafe impl B for (u32) {}
368 mod unsafe_impl_from_macro {
372 macro_rules! no_safety_comment {
374 unsafe impl T for $t {}
379 no_safety_comment!(());
382 macro_rules! with_safety_comment {
385 unsafe impl T for $t {}
390 with_safety_comment!((i32));
393 mod unsafe_impl_macro_and_not_macro {
397 macro_rules! no_safety_comment {
399 unsafe impl T for $t {}
404 no_safety_comment!(());
407 unsafe impl T for (i32) {}
410 no_safety_comment!(u32);
413 unsafe impl T for (bool) {}
417 mod unsafe_impl_valid_comment {
418 unsafe trait SaFety {}
420 unsafe impl SaFety for () {}
422 unsafe trait MultiLineComment {}
423 // The following impl is safe
426 unsafe impl MultiLineComment for () {}
428 unsafe trait NoAscii {}
429 // 安全 SAFETY: 以下のコードは安全です
430 unsafe impl NoAscii for () {}
432 unsafe trait InlineAndPrecedingComment {}
434 /* comment */ unsafe impl InlineAndPrecedingComment for () {}
436 unsafe trait BuriedSafety {}
437 // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
438 // incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
439 // ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
440 // reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
441 // occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
443 // Tellus elementum sagittis vitae et leo duis ut diam quam. Sit amet nulla facilisi
444 // morbi tempus iaculis urna. Amet luctus venenatis lectus magna. At quis risus sed vulputate odio
445 // ut. Luctus venenatis lectus magna fringilla urna. Tortor id aliquet lectus proin nibh nisl
446 // condimentum id venenatis. Vulputate dignissim suspendisse in est ante in nibh mauris cursus.
447 unsafe impl BuriedSafety for () {}
449 unsafe trait MultiLineBlockComment {}
450 /* This is a description
452 unsafe impl MultiLineBlockComment for () {}
456 mod unsafe_impl_invalid_comment {
457 unsafe trait NoComment {}
459 unsafe impl NoComment for () {}
461 unsafe trait InlineComment {}
463 /* SAFETY: */ unsafe impl InlineComment for () {}
465 unsafe trait TrailingComment {}
467 unsafe impl TrailingComment for () {} // SAFETY:
469 unsafe trait Interference {}
471 const BIG_NUMBER: i32 = 1000000;
472 unsafe impl Interference for () {}
475 unsafe trait ImplInFn {}
479 unsafe impl ImplInFn for () {}
482 unsafe impl ImplInFn for (i32) {}
485 unsafe trait CrateRoot {}
488 unsafe impl CrateRoot for () {}
491 unsafe impl CrateRoot for (i32) {}