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);
256 fn inline_block_comment() {
257 /* Safety: */ unsafe {}
264 fn no_comment_array() {
265 let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
268 fn no_comment_tuple() {
269 let _ = (42, unsafe {}, "test", unsafe {});
272 fn no_comment_unary() {
273 let _ = *unsafe { &42 };
276 #[allow(clippy::match_single_binding)]
277 fn no_comment_match() {
278 let _ = match unsafe {} {
283 fn no_comment_addr_of() {
287 fn no_comment_repeat() {
288 let _ = [unsafe {}; 5];
291 fn local_no_comment() {
295 fn no_comment_macro_call() {
305 fn no_comment_macro_def() {
315 fn trailing_comment() {
319 fn internal_comment() {
333 pub fn print_binary_tree() {
334 println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
337 mod unsafe_impl_smoke_test {
340 // error: no safety comment
341 unsafe impl A for () {}
344 unsafe impl A for (i32) {}
348 unsafe impl B for (u32) {}
358 unsafe impl B for (u32) {}
363 mod unsafe_impl_from_macro {
367 macro_rules! no_safety_comment {
369 unsafe impl T for $t {}
374 no_safety_comment!(());
377 macro_rules! with_safety_comment {
380 unsafe impl T for $t {}
385 with_safety_comment!((i32));
388 mod unsafe_impl_macro_and_not_macro {
392 macro_rules! no_safety_comment {
394 unsafe impl T for $t {}
399 no_safety_comment!(());
402 unsafe impl T for (i32) {}
405 no_safety_comment!(u32);
408 unsafe impl T for (bool) {}
412 mod unsafe_impl_valid_comment {
413 unsafe trait SaFety {}
415 unsafe impl SaFety for () {}
417 unsafe trait MultiLineComment {}
418 // The following impl is safe
421 unsafe impl MultiLineComment for () {}
423 unsafe trait NoAscii {}
424 // 安全 SAFETY: 以下のコードは安全です
425 unsafe impl NoAscii for () {}
427 unsafe trait InlineAndPrecedingComment {}
429 /* comment */ unsafe impl InlineAndPrecedingComment for () {}
431 unsafe trait BuriedSafety {}
432 // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
433 // incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
434 // ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
435 // reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
436 // occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
438 // Tellus elementum sagittis vitae et leo duis ut diam quam. Sit amet nulla facilisi
439 // morbi tempus iaculis urna. Amet luctus venenatis lectus magna. At quis risus sed vulputate odio
440 // ut. Luctus venenatis lectus magna fringilla urna. Tortor id aliquet lectus proin nibh nisl
441 // condimentum id venenatis. Vulputate dignissim suspendisse in est ante in nibh mauris cursus.
442 unsafe impl BuriedSafety for () {}
444 unsafe trait MultiLineBlockComment {}
445 /* This is a description
447 unsafe impl MultiLineBlockComment for () {}
451 mod unsafe_impl_invalid_comment {
452 unsafe trait NoComment {}
454 unsafe impl NoComment for () {}
456 unsafe trait InlineComment {}
458 /* SAFETY: */ unsafe impl InlineComment for () {}
460 unsafe trait TrailingComment {}
462 unsafe impl TrailingComment for () {} // SAFETY:
464 unsafe trait Interference {}
466 const BIG_NUMBER: i32 = 1000000;
467 unsafe impl Interference for () {}
470 unsafe trait ImplInFn {}
474 unsafe impl ImplInFn for () {}
477 unsafe impl ImplInFn for (i32) {}
480 unsafe trait CrateRoot {}
483 unsafe impl CrateRoot for () {}
486 unsafe impl CrateRoot for (i32) {}