Use a dedicated type instead of a reference for the diagnostic context

This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
This commit is contained in:
Oli Scherer 2024-06-18 10:35:56 +00:00
parent 1d1989fdab
commit 0c5a75a61b
4 changed files with 12 additions and 10 deletions

View File

@ -67,7 +67,7 @@ fn parse_cfg_if_inner<'a>(
Ok(None) => continue, Ok(None) => continue,
Err(err) => { Err(err) => {
err.cancel(); err.cancel();
parser.psess.dcx.reset_err_count(); parser.psess.dcx().reset_err_count();
return Err( return Err(
"Expected item inside cfg_if block, but failed to parse it as an item", "Expected item inside cfg_if block, but failed to parse it as an item",
); );

View File

@ -16,8 +16,8 @@ macro_rules! parse_or {
($method:ident $(,)* $($arg:expr),* $(,)*) => { ($method:ident $(,)* $($arg:expr),* $(,)*) => {
match parser.$method($($arg,)*) { match parser.$method($($arg,)*) {
Ok(val) => { Ok(val) => {
if parser.psess.dcx.has_errors().is_some() { if parser.psess.dcx().has_errors().is_some() {
parser.psess.dcx.reset_err_count(); parser.psess.dcx().reset_err_count();
return None; return None;
} else { } else {
val val
@ -25,7 +25,7 @@ macro_rules! parse_or {
} }
Err(err) => { Err(err) => {
err.cancel(); err.cancel();
parser.psess.dcx.reset_err_count(); parser.psess.dcx().reset_err_count();
return None; return None;
} }
} }

View File

@ -29,8 +29,8 @@ macro_rules! parse_macro_arg {
if Parser::nonterminal_may_begin_with($nt_kind, &cloned_parser.token) { if Parser::nonterminal_may_begin_with($nt_kind, &cloned_parser.token) {
match $try_parse(&mut cloned_parser) { match $try_parse(&mut cloned_parser) {
Ok(x) => { Ok(x) => {
if parser.psess.dcx.has_errors().is_some() { if parser.psess.dcx().has_errors().is_some() {
parser.psess.dcx.reset_err_count(); parser.psess.dcx().reset_err_count();
} else { } else {
// Parsing succeeded. // Parsing succeeded.
*parser = cloned_parser; *parser = cloned_parser;
@ -39,7 +39,7 @@ macro_rules! parse_macro_arg {
} }
Err(e) => { Err(e) => {
e.cancel(); e.cancel();
parser.psess.dcx.reset_err_count(); parser.psess.dcx().reset_err_count();
} }
} }
} }

View File

@ -210,7 +210,9 @@ pub(crate) fn set_silent_emitter(&mut self) {
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
false, false,
); );
self.raw_psess.dcx.make_silent(fallback_bundle, None, false); self.raw_psess
.dcx()
.make_silent(fallback_bundle, None, false);
} }
pub(crate) fn span_to_filename(&self, span: Span) -> FileName { pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
@ -286,11 +288,11 @@ pub(super) fn can_reset_errors(&self) -> bool {
} }
pub(super) fn has_errors(&self) -> bool { pub(super) fn has_errors(&self) -> bool {
self.raw_psess.dcx.has_errors().is_some() self.raw_psess.dcx().has_errors().is_some()
} }
pub(super) fn reset_errors(&self) { pub(super) fn reset_errors(&self) {
self.raw_psess.dcx.reset_err_count(); self.raw_psess.dcx().reset_err_count();
} }
} }