Replace a lock with an atomic
This commit is contained in:
parent
aad33198ff
commit
c7a3a943f2
3 changed files with 11 additions and 6 deletions
|
@ -29,6 +29,7 @@ use rustc_ast::{Async, AttrArgs, AttrArgsEq, Expr, ExprKind, MacDelimiter, Mutab
|
||||||
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
|
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
|
use rustc_data_structures::sync::Ordering;
|
||||||
use rustc_errors::PResult;
|
use rustc_errors::PResult;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
Applicability, DiagnosticBuilder, ErrorGuaranteed, FatalError, IntoDiagnostic, MultiSpan,
|
Applicability, DiagnosticBuilder, ErrorGuaranteed, FatalError, IntoDiagnostic, MultiSpan,
|
||||||
|
@ -1540,8 +1541,12 @@ pub(crate) fn make_unclosed_delims_error(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn emit_unclosed_delims(unclosed_delims: &mut Vec<UnmatchedDelim>, sess: &ParseSess) {
|
pub fn emit_unclosed_delims(unclosed_delims: &mut Vec<UnmatchedDelim>, sess: &ParseSess) {
|
||||||
*sess.reached_eof.borrow_mut() |=
|
let _ = sess.reached_eof.compare_exchange(
|
||||||
unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none());
|
false,
|
||||||
|
unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none()),
|
||||||
|
Ordering::Relaxed,
|
||||||
|
Ordering::Relaxed,
|
||||||
|
);
|
||||||
for unmatched in unclosed_delims.drain(..) {
|
for unmatched in unclosed_delims.drain(..) {
|
||||||
if let Some(mut e) = make_unclosed_delims_error(unmatched, sess) {
|
if let Some(mut e) = make_unclosed_delims_error(unmatched, sess) {
|
||||||
e.emit();
|
e.emit();
|
||||||
|
|
|
@ -187,7 +187,7 @@ fn sigpipe(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
|
||||||
|
|
||||||
fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {
|
fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {
|
||||||
let sp = tcx.def_span(CRATE_DEF_ID);
|
let sp = tcx.def_span(CRATE_DEF_ID);
|
||||||
if *tcx.sess.parse_sess.reached_eof.borrow() {
|
if tcx.sess.parse_sess.reached_eof.load(rustc_data_structures::sync::Ordering::Relaxed) {
|
||||||
// There's an unclosed brace that made the parser reach `Eof`, we shouldn't complain about
|
// There's an unclosed brace that made the parser reach `Eof`, we shouldn't complain about
|
||||||
// the missing `fn main()` then as it might have been hidden inside an unclosed block.
|
// the missing `fn main()` then as it might have been hidden inside an unclosed block.
|
||||||
tcx.sess.delay_span_bug(sp, "`main` not found, but expected unclosed brace error");
|
tcx.sess.delay_span_bug(sp, "`main` not found, but expected unclosed brace error");
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::lint::{
|
||||||
};
|
};
|
||||||
use rustc_ast::node_id::NodeId;
|
use rustc_ast::node_id::NodeId;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
|
||||||
use rustc_data_structures::sync::{Lock, Lrc};
|
use rustc_data_structures::sync::{AtomicBool, Lock, Lrc};
|
||||||
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
|
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
fallback_fluent_bundle, Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
|
fallback_fluent_bundle, Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
|
||||||
|
@ -208,7 +208,7 @@ pub struct ParseSess {
|
||||||
pub gated_spans: GatedSpans,
|
pub gated_spans: GatedSpans,
|
||||||
pub symbol_gallery: SymbolGallery,
|
pub symbol_gallery: SymbolGallery,
|
||||||
/// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors.
|
/// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors.
|
||||||
pub reached_eof: Lock<bool>,
|
pub reached_eof: AtomicBool,
|
||||||
/// Environment variables accessed during the build and their values when they exist.
|
/// Environment variables accessed during the build and their values when they exist.
|
||||||
pub env_depinfo: Lock<FxHashSet<(Symbol, Option<Symbol>)>>,
|
pub env_depinfo: Lock<FxHashSet<(Symbol, Option<Symbol>)>>,
|
||||||
/// File paths accessed during the build.
|
/// File paths accessed during the build.
|
||||||
|
@ -254,7 +254,7 @@ impl ParseSess {
|
||||||
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
|
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
|
||||||
gated_spans: GatedSpans::default(),
|
gated_spans: GatedSpans::default(),
|
||||||
symbol_gallery: SymbolGallery::default(),
|
symbol_gallery: SymbolGallery::default(),
|
||||||
reached_eof: Lock::new(false),
|
reached_eof: AtomicBool::new(false),
|
||||||
env_depinfo: Default::default(),
|
env_depinfo: Default::default(),
|
||||||
file_depinfo: Default::default(),
|
file_depinfo: Default::default(),
|
||||||
type_ascription_path_suggestions: Default::default(),
|
type_ascription_path_suggestions: Default::default(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue