Stop using DiagnosticBuilder::buffer in the parser.

One consequence is that errors returned by
`maybe_new_parser_from_source_str` now must be consumed, so a bunch of
places that previously ignored those errors now cancel them. (Most of
them explicitly dropped the errors before. I guess that was to indicate
"we are explicitly ignoring these", though I'm not 100% sure.)
This commit is contained in:
Nicholas Nethercote 2024-01-11 14:22:44 +11:00
parent d02150fd45
commit 6656413a5c
8 changed files with 39 additions and 32 deletions

View file

@ -53,7 +53,7 @@ pub fn check(
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) {
Ok(p) => p,
Err(errs) => {
drop(errs);
errs.into_iter().for_each(|err| err.cancel());
return (false, test_attr_spans);
},
};

View file

@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use rustc_ast::token::TokenKind;
use rustc_ast::{ast, attr, ptr};
use rustc_errors::Diagnostic;
use rustc_errors::DiagnosticBuilder;
use rustc_parse::{new_parser_from_file, parser::Parser as RawParser};
use rustc_span::{sym, Span};
use thin_vec::ThinVec;
@ -65,7 +65,7 @@ impl<'a> ParserBuilder<'a> {
fn parser(
sess: &'a rustc_session::parse::ParseSess,
input: Input,
) -> Result<rustc_parse::parser::Parser<'a>, Option<Vec<Diagnostic>>> {
) -> Result<rustc_parse::parser::Parser<'a>, Option<Vec<DiagnosticBuilder<'a>>>> {
match input {
Input::File(ref file) => catch_unwind(AssertUnwindSafe(move || {
new_parser_from_file(sess, file, None)

View file

@ -4,7 +4,9 @@ use std::sync::atomic::{AtomicBool, Ordering};
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter};
use rustc_errors::translation::Translate;
use rustc_errors::{ColorConfig, DiagCtxt, Diagnostic, Level as DiagnosticLevel};
use rustc_errors::{
ColorConfig, DiagCtxt, Diagnostic, DiagnosticBuilder, Level as DiagnosticLevel,
};
use rustc_session::parse::ParseSess as RawParseSess;
use rustc_span::{
source_map::{FilePathMapping, SourceMap},
@ -283,9 +285,9 @@ impl ParseSess {
// Methods that should be restricted within the parse module.
impl ParseSess {
pub(super) fn emit_diagnostics(&self, diagnostics: Vec<Diagnostic>) {
pub(super) fn emit_diagnostics(&self, diagnostics: Vec<DiagnosticBuilder<'_>>) {
for diagnostic in diagnostics {
self.parse_sess.dcx.emit_diagnostic(diagnostic);
diagnostic.emit();
}
}