diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 85ff26a36..2a85ce85d 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -539,6 +539,155 @@ fn missing_record_pat_field_no_diagnostic_if_not_exhaustive() { | |||
539 | } | 539 | } |
540 | 540 | ||
541 | #[test] | 541 | #[test] |
542 | fn missing_unsafe_diagnostic_with_raw_ptr() { | ||
543 | let diagnostics = TestDB::with_files( | ||
544 | r" | ||
545 | //- /lib.rs | ||
546 | fn missing_unsafe() { | ||
547 | let x = &5 as *const usize; | ||
548 | let y = *x; | ||
549 | } | ||
550 | ", | ||
551 | ) | ||
552 | .diagnostics() | ||
553 | .0; | ||
554 | |||
555 | assert_snapshot!(diagnostics, @r#""*x": This operation is unsafe and requires an unsafe function or block"#); | ||
556 | } | ||
557 | |||
558 | #[test] | ||
559 | fn missing_unsafe_diagnostic_with_unsafe_call() { | ||
560 | let diagnostics = TestDB::with_files( | ||
561 | r" | ||
562 | //- /lib.rs | ||
563 | unsafe fn unsafe_fn() { | ||
564 | let x = &5 as *const usize; | ||
565 | let y = *x; | ||
566 | } | ||
567 | |||
568 | fn missing_unsafe() { | ||
569 | unsafe_fn(); | ||
570 | } | ||
571 | ", | ||
572 | ) | ||
573 | .diagnostics() | ||
574 | .0; | ||
575 | |||
576 | assert_snapshot!(diagnostics, @r#""unsafe_fn()": This operation is unsafe and requires an unsafe function or block"#); | ||
577 | } | ||
578 | |||
579 | #[test] | ||
580 | fn missing_unsafe_diagnostic_with_unsafe_method_call() { | ||
581 | let diagnostics = TestDB::with_files( | ||
582 | r" | ||
583 | struct HasUnsafe; | ||
584 | |||
585 | impl HasUnsafe { | ||
586 | unsafe fn unsafe_fn(&self) { | ||
587 | let x = &5 as *const usize; | ||
588 | let y = *x; | ||
589 | } | ||
590 | } | ||
591 | |||
592 | fn missing_unsafe() { | ||
593 | HasUnsafe.unsafe_fn(); | ||
594 | } | ||
595 | |||
596 | ", | ||
597 | ) | ||
598 | .diagnostics() | ||
599 | .0; | ||
600 | |||
601 | assert_snapshot!(diagnostics, @r#""HasUnsafe.unsafe_fn()": This operation is unsafe and requires an unsafe function or block"#); | ||
602 | } | ||
603 | |||
604 | #[test] | ||
605 | fn no_missing_unsafe_diagnostic_with_raw_ptr_in_unsafe_block() { | ||
606 | let diagnostics = TestDB::with_files( | ||
607 | r" | ||
608 | fn nothing_to_see_move_along() { | ||
609 | let x = &5 as *const usize; | ||
610 | unsafe { | ||
611 | let y = *x; | ||
612 | } | ||
613 | } | ||
614 | ", | ||
615 | ) | ||
616 | .diagnostics() | ||
617 | .0; | ||
618 | |||
619 | assert_snapshot!(diagnostics, @""); | ||
620 | } | ||
621 | |||
622 | #[test] | ||
623 | fn missing_unsafe_diagnostic_with_raw_ptr_outside_unsafe_block() { | ||
624 | let diagnostics = TestDB::with_files( | ||
625 | r" | ||
626 | fn nothing_to_see_move_along() { | ||
627 | let x = &5 as *const usize; | ||
628 | unsafe { | ||
629 | let y = *x; | ||
630 | } | ||
631 | let z = *x; | ||
632 | } | ||
633 | ", | ||
634 | ) | ||
635 | .diagnostics() | ||
636 | .0; | ||
637 | |||
638 | assert_snapshot!(diagnostics, @r#""*x": This operation is unsafe and requires an unsafe function or block"#); | ||
639 | } | ||
640 | |||
641 | #[test] | ||
642 | fn no_missing_unsafe_diagnostic_with_unsafe_call_in_unsafe_block() { | ||
643 | let diagnostics = TestDB::with_files( | ||
644 | r" | ||
645 | unsafe fn unsafe_fn() { | ||
646 | let x = &5 as *const usize; | ||
647 | let y = *x; | ||
648 | } | ||
649 | |||
650 | fn nothing_to_see_move_along() { | ||
651 | unsafe { | ||
652 | unsafe_fn(); | ||
653 | } | ||
654 | } | ||
655 | ", | ||
656 | ) | ||
657 | .diagnostics() | ||
658 | .0; | ||
659 | |||
660 | assert_snapshot!(diagnostics, @""); | ||
661 | } | ||
662 | |||
663 | #[test] | ||
664 | fn no_missing_unsafe_diagnostic_with_unsafe_method_call_in_unsafe_block() { | ||
665 | let diagnostics = TestDB::with_files( | ||
666 | r" | ||
667 | struct HasUnsafe; | ||
668 | |||
669 | impl HasUnsafe { | ||
670 | unsafe fn unsafe_fn() { | ||
671 | let x = &5 as *const usize; | ||
672 | let y = *x; | ||
673 | } | ||
674 | } | ||
675 | |||
676 | fn nothing_to_see_move_along() { | ||
677 | unsafe { | ||
678 | HasUnsafe.unsafe_fn(); | ||
679 | } | ||
680 | } | ||
681 | |||
682 | ", | ||
683 | ) | ||
684 | .diagnostics() | ||
685 | .0; | ||
686 | |||
687 | assert_snapshot!(diagnostics, @""); | ||
688 | } | ||
689 | |||
690 | #[test] | ||
542 | fn break_outside_of_loop() { | 691 | fn break_outside_of_loop() { |
543 | let diagnostics = TestDB::with_files( | 692 | let diagnostics = TestDB::with_files( |
544 | r" | 693 | r" |