This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +3
-14
lines changed Expand file tree Collapse file tree 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;
2020use rustc_span:: Span ;
2121use smallvec:: { smallvec, Array , SmallVec } ;
2222use std:: ops:: DerefMut ;
23- use std:: { panic, ptr } ;
23+ use std:: panic;
2424use thin_vec:: ThinVec ;
2525
2626pub trait ExpectOne < A : Array > {
@@ -318,19 +318,8 @@ pub trait MutVisitor: Sized {
318318//
319319// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
320320pub 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) ;
334323}
335324
336325// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
You can’t perform that action at this time.
0 commit comments