Skip to content

Commit 006f9b2

Browse files
committed
Make Session.injected_panic_runtime thread-safe
1 parent dacf9ba commit 006f9b2

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/librustc/middle/dependency_format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
223223
//
224224
// Things like allocators and panic runtimes may not have been activated
225225
// quite yet, so do so here.
226-
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
226+
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
227227
&|cnum| tcx.is_panic_runtime(cnum));
228228
activate_injected_allocator(sess, &mut ret);
229229

@@ -302,7 +302,7 @@ fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<DependencyLis
302302
// Our allocator/panic runtime may not have been linked above if it wasn't
303303
// explicitly linked, which is the case for any injected dependency. Handle
304304
// that here and activate them.
305-
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
305+
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
306306
&|cnum| tcx.is_panic_runtime(cnum));
307307
activate_injected_allocator(sess, &mut ret);
308308

src/librustc/session/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub struct Session {
120120
/// injected.
121121
pub injected_allocator: Once<Option<CrateNum>>,
122122
pub allocator_kind: Once<Option<AllocatorKind>>,
123-
pub injected_panic_runtime: Cell<Option<CrateNum>>,
123+
pub injected_panic_runtime: Once<Option<CrateNum>>,
124124

125125
/// Map from imported macro spans (which consist of
126126
/// the localized span for the macro body) to the
@@ -1107,7 +1107,7 @@ pub fn build_session_(
11071107
next_node_id: OneThread::new(Cell::new(NodeId::new(1))),
11081108
injected_allocator: Once::new(),
11091109
allocator_kind: Once::new(),
1110-
injected_panic_runtime: Cell::new(None),
1110+
injected_panic_runtime: Once::new(),
11111111
imported_macro_spans: OneThread::new(RefCell::new(HashMap::new())),
11121112
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
11131113
ignored_attr_names: ich::compute_ignored_attr_names(),

src/librustc_metadata/creader.rs

+2
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ impl<'a> CrateLoader<'a> {
614614
});
615615
if !any_non_rlib {
616616
info!("panic runtime injection skipped, only generating rlib");
617+
self.sess.injected_panic_runtime.set(None);
617618
return
618619
}
619620

@@ -646,6 +647,7 @@ impl<'a> CrateLoader<'a> {
646647
// we just don't need one at all, then we're done here and there's
647648
// nothing else to do.
648649
if !needs_panic_runtime || runtime_found {
650+
self.sess.injected_panic_runtime.set(None);
649651
return
650652
}
651653

0 commit comments

Comments
 (0)