Skip to content

Commit 904e2b6

Browse files
committed
Make Session::features_untracked thread-safe
1 parent a46f059 commit 904e2b6

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/librustc/session/mod.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub struct Session {
101101
/// trans::back::symbol_names module for more information.
102102
pub crate_disambiguator: RefCell<Option<CrateDisambiguator>>,
103103

104-
features: RefCell<Option<feature_gate::Features>>,
104+
features: Once<feature_gate::Features>,
105105

106106
/// The maximum recursion limit for potentially infinitely recursive
107107
/// operations such as auto-dereference and monomorphization.
@@ -532,18 +532,12 @@ impl Session {
532532
/// DO NOT USE THIS METHOD if there is a TyCtxt available, as it circumvents
533533
/// dependency tracking. Use tcx.features() instead.
534534
#[inline]
535-
pub fn features_untracked(&self) -> cell::Ref<feature_gate::Features> {
536-
let features = self.features.borrow();
537-
538-
if features.is_none() {
539-
bug!("Access to Session::features before it is initialized");
540-
}
541-
542-
cell::Ref::map(features, |r| r.as_ref().unwrap())
535+
pub fn features_untracked(&self) -> &feature_gate::Features {
536+
self.features.get()
543537
}
544538

545539
pub fn init_features(&self, features: feature_gate::Features) {
546-
*(self.features.borrow_mut()) = Some(features);
540+
self.features.set(features);
547541
}
548542

549543
/// Calculates the flavor of LTO to use for this compilation.
@@ -1108,7 +1102,7 @@ pub fn build_session_(
11081102
crate_types: RefCell::new(Vec::new()),
11091103
dependency_formats: RefCell::new(FxHashMap()),
11101104
crate_disambiguator: RefCell::new(None),
1111-
features: RefCell::new(None),
1105+
features: Once::new(),
11121106
recursion_limit: Once::new(),
11131107
type_length_limit: Once::new(),
11141108
const_eval_stack_frame_limit: 100,

0 commit comments

Comments
 (0)