File tree 2 files changed +10
-1
lines changed
src/test/ui/rfc-2091-track-caller
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> {
788
788
/// ```
789
789
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
790
790
#[ inline]
791
+ #[ track_caller]
791
792
pub fn borrow ( & self ) -> Ref < ' _ , T > {
792
793
self . try_borrow ( ) . expect ( "already mutably borrowed" )
793
794
}
@@ -863,6 +864,7 @@ impl<T: ?Sized> RefCell<T> {
863
864
/// ```
864
865
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
865
866
#[ inline]
867
+ #[ track_caller]
866
868
pub fn borrow_mut ( & self ) -> RefMut < ' _ , T > {
867
869
self . try_borrow_mut ( ) . expect ( "already borrowed" )
868
870
}
Original file line number Diff line number Diff line change 7
7
//! Test that panic locations for `#[track_caller]` functions in std have the correct
8
8
//! location reported.
9
9
10
+ use std:: cell:: RefCell ;
10
11
use std:: collections:: { BTreeMap , HashMap , VecDeque } ;
11
12
use std:: ops:: { Index , IndexMut } ;
13
+ use std:: panic:: { AssertUnwindSafe , UnwindSafe } ;
12
14
13
15
fn main ( ) {
14
16
// inspect the `PanicInfo` we receive to ensure the right file is the source
@@ -20,7 +22,7 @@ fn main() {
20
22
}
21
23
} ) ) ;
22
24
23
- fn assert_panicked ( f : impl FnOnce ( ) + std :: panic :: UnwindSafe ) {
25
+ fn assert_panicked ( f : impl FnOnce ( ) + UnwindSafe ) {
24
26
std:: panic:: catch_unwind ( f) . unwrap_err ( ) ;
25
27
}
26
28
@@ -57,4 +59,9 @@ fn main() {
57
59
let weirdo: VecDeque < ( ) > = Default :: default ( ) ;
58
60
assert_panicked ( || { weirdo. index ( 1 ) ; } ) ;
59
61
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 ( ) ; } ) ) ;
60
67
}
You can’t perform that action at this time.
0 commit comments