1
Fork 0

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 c91edc3888
commit 7ba82d61eb
77 changed files with 363 additions and 328 deletions

View file

@ -3,7 +3,7 @@ use std::borrow::Cow;
use rustc_ast::token::Token;
use rustc_ast::{Path, Visibility};
use rustc_errors::{
codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level,
codes::*, Applicability, Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level,
SubdiagMessageOp, Subdiagnostic,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
@ -1052,7 +1052,7 @@ pub(crate) struct ExpectedIdentifier {
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for ExpectedIdentifier {
#[track_caller]
fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
let token_descr = TokenDescription::from_token(&self.token);
let mut diag = Diag::new(
@ -1112,7 +1112,7 @@ pub(crate) struct ExpectedSemi {
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for ExpectedSemi {
#[track_caller]
fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
let token_descr = TokenDescription::from_token(&self.token);
let mut diag = Diag::new(

View file

@ -7,7 +7,7 @@ use rustc_ast::ast::{self, AttrStyle};
use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind};
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::util::unicode::contains_text_flow_control_chars;
use rustc_errors::{codes::*, Applicability, Diag, DiagCtxt, StashKey};
use rustc_errors::{codes::*, Applicability, Diag, DiagCtxtHandle, StashKey};
use rustc_lexer::unescape::{self, EscapeError, Mode};
use rustc_lexer::{Base, DocStyle, RawStrError};
use rustc_lexer::{Cursor, LiteralKind};
@ -113,7 +113,7 @@ struct StringReader<'psess, 'src> {
}
impl<'psess, 'src> StringReader<'psess, 'src> {
fn dcx(&self) -> &'psess DiagCtxt {
fn dcx(&self) -> DiagCtxtHandle<'psess> {
self.psess.dcx()
}

View file

@ -3,7 +3,7 @@
use std::iter::once;
use std::ops::Range;
use rustc_errors::{Applicability, DiagCtxt, ErrorGuaranteed};
use rustc_errors::{Applicability, DiagCtxtHandle, ErrorGuaranteed};
use rustc_lexer::unescape::{EscapeError, Mode};
use rustc_span::{BytePos, Span};
use tracing::debug;
@ -11,7 +11,7 @@ use tracing::debug;
use crate::errors::{MoreThanOneCharNote, MoreThanOneCharSugg, NoBraceUnicodeSub, UnescapeError};
pub(crate) fn emit_unescape_error(
dcx: &DiagCtxt,
dcx: DiagCtxtHandle<'_>,
// interior part of the literal, between quotes
lit: &str,
// full span of the literal, including quotes and any prefix

View file

@ -34,7 +34,7 @@ use rustc_ast::{
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{
pluralize, Applicability, Diag, DiagCtxt, ErrorGuaranteed, FatalError, PErr, PResult,
pluralize, Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, PErr, PResult,
Subdiagnostic,
};
use rustc_session::errors::ExprParenthesesNeeded;
@ -240,7 +240,7 @@ impl<'a> DerefMut for SnapshotParser<'a> {
}
impl<'a> Parser<'a> {
pub fn dcx(&self) -> &'a DiagCtxt {
pub fn dcx(&self) -> DiagCtxtHandle<'a> {
self.psess.dcx()
}

View file

@ -61,7 +61,7 @@ where
{
let mut p = string_to_parser(&psess, s);
let x = f(&mut p).unwrap();
p.psess.dcx.abort_if_errors();
p.dcx().abort_if_errors();
x
}
@ -193,7 +193,7 @@ impl<T: Write> Write for Shared<T> {
#[allow(rustc::untranslatable_diagnostic)] // no translation needed for tests
fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &str) {
create_default_session_globals_then(|| {
let (handler, source_map, output) = create_test_handler();
let (dcx, source_map, output) = create_test_handler();
source_map.new_source_file(Path::new("test.rs").to_owned().into(), file_text.to_owned());
let primary_span = make_span(&file_text, &span_labels[0].start, &span_labels[0].end);
@ -205,7 +205,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
println!("text: {:?}", source_map.span_to_snippet(span));
}
handler.span_err(msp, "foo");
dcx.handle().span_err(msp, "foo");
assert!(
expected_output.chars().next() == Some('\n'),