Skip to content

Commit c7a3a94

Browse files
committed
Replace a lock with an atomic
1 parent aad3319 commit c7a3a94

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc_ast::{Async, AttrArgs, AttrArgsEq, Expr, ExprKind, MacDelimiter, Mutab
2929
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
3030
use rustc_ast_pretty::pprust;
3131
use rustc_data_structures::fx::FxHashMap;
32+
use rustc_data_structures::sync::Ordering;
3233
use rustc_errors::PResult;
3334
use rustc_errors::{
3435
Applicability, DiagnosticBuilder, ErrorGuaranteed, FatalError, IntoDiagnostic, MultiSpan,
@@ -1540,8 +1541,12 @@ pub(crate) fn make_unclosed_delims_error(
15401541
}
15411542

15421543
pub fn emit_unclosed_delims(unclosed_delims: &mut Vec<UnmatchedDelim>, sess: &ParseSess) {
1543-
*sess.reached_eof.borrow_mut() |=
1544-
unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none());
1544+
let _ = sess.reached_eof.compare_exchange(
1545+
false,
1546+
unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none()),
1547+
Ordering::Relaxed,
1548+
Ordering::Relaxed,
1549+
);
15451550
for unmatched in unclosed_delims.drain(..) {
15461551
if let Some(mut e) = make_unclosed_delims_error(unmatched, sess) {
15471552
e.emit();

compiler/rustc_passes/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn sigpipe(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
187187

188188
fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {
189189
let sp = tcx.def_span(CRATE_DEF_ID);
190-
if *tcx.sess.parse_sess.reached_eof.borrow() {
190+
if tcx.sess.parse_sess.reached_eof.load(rustc_data_structures::sync::Ordering::Relaxed) {
191191
// There's an unclosed brace that made the parser reach `Eof`, we shouldn't complain about
192192
// the missing `fn main()` then as it might have been hidden inside an unclosed block.
193193
tcx.sess.delay_span_bug(sp, "`main` not found, but expected unclosed brace error");

compiler/rustc_session/src/parse.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::lint::{
88
};
99
use rustc_ast::node_id::NodeId;
1010
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
11-
use rustc_data_structures::sync::{Lock, Lrc};
11+
use rustc_data_structures::sync::{AtomicBool, Lock, Lrc};
1212
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
1313
use rustc_errors::{
1414
fallback_fluent_bundle, Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
@@ -208,7 +208,7 @@ pub struct ParseSess {
208208
pub gated_spans: GatedSpans,
209209
pub symbol_gallery: SymbolGallery,
210210
/// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors.
211-
pub reached_eof: Lock<bool>,
211+
pub reached_eof: AtomicBool,
212212
/// Environment variables accessed during the build and their values when they exist.
213213
pub env_depinfo: Lock<FxHashSet<(Symbol, Option<Symbol>)>>,
214214
/// File paths accessed during the build.
@@ -254,7 +254,7 @@ impl ParseSess {
254254
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
255255
gated_spans: GatedSpans::default(),
256256
symbol_gallery: SymbolGallery::default(),
257-
reached_eof: Lock::new(false),
257+
reached_eof: AtomicBool::new(false),
258258
env_depinfo: Default::default(),
259259
file_depinfo: Default::default(),
260260
type_ascription_path_suggestions: Default::default(),

0 commit comments

Comments
 (0)