File tree 1 file changed +3
-14
lines changed
1 file changed +3
-14
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ use rustc_span::symbol::Ident;
20
20
use rustc_span:: Span ;
21
21
use smallvec:: { smallvec, Array , SmallVec } ;
22
22
use std:: ops:: DerefMut ;
23
- use std:: { panic, ptr } ;
23
+ use std:: panic;
24
24
use thin_vec:: ThinVec ;
25
25
26
26
pub trait ExpectOne < A : Array > {
@@ -318,19 +318,8 @@ pub trait MutVisitor: Sized {
318
318
//
319
319
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
320
320
pub fn visit_clobber < T : DummyAstNode > ( t : & mut T , f : impl FnOnce ( T ) -> T ) {
321
- unsafe {
322
- // Safe because `t` is used in a read-only fashion by `read()` before
323
- // being overwritten by `write()`.
324
- let old_t = ptr:: read ( t) ;
325
- let new_t =
326
- panic:: catch_unwind ( panic:: AssertUnwindSafe ( || f ( old_t) ) ) . unwrap_or_else ( |err| {
327
- // Set `t` to some valid but possible meaningless value,
328
- // and pass the fatal error further.
329
- ptr:: write ( t, T :: dummy ( ) ) ;
330
- panic:: resume_unwind ( err) ;
331
- } ) ;
332
- ptr:: write ( t, new_t) ;
333
- }
321
+ let old_t = std:: mem:: replace ( t, T :: dummy ( ) ) ;
322
+ * t = f ( old_t) ;
334
323
}
335
324
336
325
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
You can’t perform that action at this time.
0 commit comments