File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
src/test/ui/rfc-2091-track-caller Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -788,6 +788,7 @@ impl<T: ?Sized> RefCell<T> {
788788 /// ```
789789 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
790790 #[ inline]
791+ #[ track_caller]
791792 pub fn borrow ( & self ) -> Ref < ' _ , T > {
792793 self . try_borrow ( ) . expect ( "already mutably borrowed" )
793794 }
@@ -863,6 +864,7 @@ impl<T: ?Sized> RefCell<T> {
863864 /// ```
864865 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
865866 #[ inline]
867+ #[ track_caller]
866868 pub fn borrow_mut ( & self ) -> RefMut < ' _ , T > {
867869 self . try_borrow_mut ( ) . expect ( "already borrowed" )
868870 }
Original file line number Diff line number Diff line change 77//! Test that panic locations for `#[track_caller]` functions in std have the correct
88//! location reported.
99
10+ use std:: cell:: RefCell ;
1011use std:: collections:: { BTreeMap , HashMap , VecDeque } ;
1112use std:: ops:: { Index , IndexMut } ;
13+ use std:: panic:: { AssertUnwindSafe , UnwindSafe } ;
1214
1315fn main ( ) {
1416 // inspect the `PanicInfo` we receive to ensure the right file is the source
@@ -20,7 +22,7 @@ fn main() {
2022 }
2123 } ) ) ;
2224
23- fn assert_panicked ( f : impl FnOnce ( ) + std :: panic :: UnwindSafe ) {
25+ fn assert_panicked ( f : impl FnOnce ( ) + UnwindSafe ) {
2426 std:: panic:: catch_unwind ( f) . unwrap_err ( ) ;
2527 }
2628
@@ -57,4 +59,9 @@ fn main() {
5759 let weirdo: VecDeque < ( ) > = Default :: default ( ) ;
5860 assert_panicked ( || { weirdo. index ( 1 ) ; } ) ;
5961 assert_panicked ( || { weirdo[ 1 ] ; } ) ;
62+
63+ let refcell: RefCell < ( ) > = Default :: default ( ) ;
64+ let _conflicting = refcell. borrow_mut ( ) ;
65+ assert_panicked ( AssertUnwindSafe ( || { refcell. borrow ( ) ; } ) ) ;
66+ assert_panicked ( AssertUnwindSafe ( || { refcell. borrow_mut ( ) ; } ) ) ;
6067}
You can’t perform that action at this time.
0 commit comments