aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests.rs')
-rw-r--r--crates/ra_hir_ty/src/tests.rs149
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]
542fn missing_unsafe_diagnostic_with_raw_ptr() {
543 let diagnostics = TestDB::with_files(
544 r"
545//- /lib.rs
546fn 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]
559fn missing_unsafe_diagnostic_with_unsafe_call() {
560 let diagnostics = TestDB::with_files(
561 r"
562//- /lib.rs
563unsafe fn unsafe_fn() {
564 let x = &5 as *const usize;
565 let y = *x;
566}
567
568fn 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]
580fn missing_unsafe_diagnostic_with_unsafe_method_call() {
581 let diagnostics = TestDB::with_files(
582 r"
583struct HasUnsafe;
584
585impl HasUnsafe {
586 unsafe fn unsafe_fn(&self) {
587 let x = &5 as *const usize;
588 let y = *x;
589 }
590}
591
592fn 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]
605fn no_missing_unsafe_diagnostic_with_raw_ptr_in_unsafe_block() {
606 let diagnostics = TestDB::with_files(
607 r"
608fn 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]
623fn missing_unsafe_diagnostic_with_raw_ptr_outside_unsafe_block() {
624 let diagnostics = TestDB::with_files(
625 r"
626fn 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]
642fn no_missing_unsafe_diagnostic_with_unsafe_call_in_unsafe_block() {
643 let diagnostics = TestDB::with_files(
644 r"
645unsafe fn unsafe_fn() {
646 let x = &5 as *const usize;
647 let y = *x;
648}
649
650fn 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]
664fn no_missing_unsafe_diagnostic_with_unsafe_method_call_in_unsafe_block() {
665 let diagnostics = TestDB::with_files(
666 r"
667struct HasUnsafe;
668
669impl HasUnsafe {
670 unsafe fn unsafe_fn() {
671 let x = &5 as *const usize;
672 let y = *x;
673 }
674}
675
676fn 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]
542fn break_outside_of_loop() { 691fn break_outside_of_loop() {
543 let diagnostics = TestDB::with_files( 692 let diagnostics = TestDB::with_files(
544 r" 693 r"