rustc_errors: take self by value in DiagnosticBuilder::cancel.

This commit is contained in:
Eduard-Mihai Burtescu 2022-01-26 03:39:14 +00:00
parent 7592663e85
commit 5723946081
6 changed files with 5 additions and 16 deletions

View File

@ -439,7 +439,7 @@ fn find_external_module(
} }
} }
Err(mod_err) if !mods_outside_ast.is_empty() => { Err(mod_err) if !mods_outside_ast.is_empty() => {
if let ModError::ParserError(mut e) = mod_err { if let ModError::ParserError(e) = mod_err {
e.cancel(); e.cancel();
} }
Ok(Some(SubModKind::MultiExternal(mods_outside_ast))) Ok(Some(SubModKind::MultiExternal(mods_outside_ast)))

View File

@ -57,7 +57,7 @@ fn parse_cfg_if_inner<'a>(
let item = match parser.parse_item(ForceCollect::No) { let item = match parser.parse_item(ForceCollect::No) {
Ok(Some(item_ptr)) => item_ptr.into_inner(), Ok(Some(item_ptr)) => item_ptr.into_inner(),
Ok(None) => continue, Ok(None) => continue,
Err(mut err) => { Err(err) => {
err.cancel(); err.cancel();
parser.sess.span_diagnostic.reset_err_count(); parser.sess.span_diagnostic.reset_err_count();
return Err( return Err(

View File

@ -23,7 +23,7 @@ macro_rules! parse_or {
val val
} }
} }
Err(mut err) => { Err(err) => {
err.cancel(); err.cancel();
parser.sess.span_diagnostic.reset_err_count(); parser.sess.span_diagnostic.reset_err_count();
return None; return None;

View File

@ -36,7 +36,7 @@ macro_rules! parse_macro_arg {
return Some(MacroArg::$macro_arg($f(x)?)); return Some(MacroArg::$macro_arg($f(x)?));
} }
} }
Err(mut e) => { Err(e) => {
e.cancel(); e.cancel();
parser.sess.span_diagnostic.reset_err_count(); parser.sess.span_diagnostic.reset_err_count();
} }

View File

@ -115,7 +115,7 @@ pub(crate) fn parse_file_as_module(
match parser.parse_mod(&TokenKind::Eof) { match parser.parse_mod(&TokenKind::Eof) {
Ok(result) => Some(result), Ok(result) => Some(result),
Err(mut e) => { Err(mut e) => {
sess.emit_or_cancel_diagnostic(&mut e); e.emit();
if sess.can_reset_errors() { if sess.can_reset_errors() {
sess.reset_errors(); sess.reset_errors();
} }

View File

@ -230,17 +230,6 @@ pub(super) fn emit_diagnostics(&self, diagnostics: Vec<Diagnostic>) {
} }
} }
pub(crate) fn emit_or_cancel_diagnostic(&self, diagnostic: &mut Diagnostic) {
self.parse_sess.span_diagnostic.emit_diagnostic(diagnostic);
// The Handler will check whether the diagnostic should be emitted
// based on the user's rustfmt configuration and the originating file
// that caused the parser error. If the Handler determined it should skip
// emission then we need to ensure the diagnostic is cancelled.
if !diagnostic.cancelled() {
diagnostic.cancel();
}
}
pub(super) fn can_reset_errors(&self) -> bool { pub(super) fn can_reset_errors(&self) -> bool {
self.can_reset_errors.load(Ordering::Acquire) self.can_reset_errors.load(Ordering::Acquire)
} }