Add level
arg to into_diagnostic
.
And make all hand-written `IntoDiagnostic` impls generic, by using `DiagnosticBuilder::new(dcx, level, ...)` instead of e.g. `dcx.struct_err(...)`. This means the `create_*` functions are the source of the error level. This change will let us remove `struct_diagnostic`. Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`, it's necessary to pass diagnostics tests now that it's used in `into_diagnostic` functions.
This commit is contained in:
parent
31df50c897
commit
e7724a2e31
24 changed files with 307 additions and 288 deletions
|
@ -2,7 +2,10 @@ use std::borrow::Cow;
|
|||
|
||||
use rustc_ast::token::Token;
|
||||
use rustc_ast::{Path, Visibility};
|
||||
use rustc_errors::{AddToDiagnostic, Applicability, ErrorGuaranteed, IntoDiagnostic};
|
||||
use rustc_errors::{
|
||||
AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic,
|
||||
Level, SubdiagnosticMessage,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_session::errors::ExprParenthesesNeeded;
|
||||
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
|
||||
|
@ -1042,23 +1045,30 @@ impl<'a> IntoDiagnostic<'a> for ExpectedIdentifier {
|
|||
#[track_caller]
|
||||
fn into_diagnostic(
|
||||
self,
|
||||
dcx: &'a rustc_errors::DiagCtxt,
|
||||
) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
dcx: &'a DiagCtxt,
|
||||
level: Level,
|
||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
let token_descr = TokenDescription::from_token(&self.token);
|
||||
|
||||
let mut diag = dcx.struct_err(match token_descr {
|
||||
Some(TokenDescription::ReservedIdentifier) => {
|
||||
fluent::parse_expected_identifier_found_reserved_identifier_str
|
||||
}
|
||||
Some(TokenDescription::Keyword) => fluent::parse_expected_identifier_found_keyword_str,
|
||||
Some(TokenDescription::ReservedKeyword) => {
|
||||
fluent::parse_expected_identifier_found_reserved_keyword_str
|
||||
}
|
||||
Some(TokenDescription::DocComment) => {
|
||||
fluent::parse_expected_identifier_found_doc_comment_str
|
||||
}
|
||||
None => fluent::parse_expected_identifier_found_str,
|
||||
});
|
||||
let mut diag = DiagnosticBuilder::new(
|
||||
dcx,
|
||||
level,
|
||||
match token_descr {
|
||||
Some(TokenDescription::ReservedIdentifier) => {
|
||||
fluent::parse_expected_identifier_found_reserved_identifier_str
|
||||
}
|
||||
Some(TokenDescription::Keyword) => {
|
||||
fluent::parse_expected_identifier_found_keyword_str
|
||||
}
|
||||
Some(TokenDescription::ReservedKeyword) => {
|
||||
fluent::parse_expected_identifier_found_reserved_keyword_str
|
||||
}
|
||||
Some(TokenDescription::DocComment) => {
|
||||
fluent::parse_expected_identifier_found_doc_comment_str
|
||||
}
|
||||
None => fluent::parse_expected_identifier_found_str,
|
||||
},
|
||||
);
|
||||
diag.set_span(self.span);
|
||||
diag.set_arg("token", self.token);
|
||||
|
||||
|
@ -1099,21 +1109,28 @@ impl<'a> IntoDiagnostic<'a> for ExpectedSemi {
|
|||
#[track_caller]
|
||||
fn into_diagnostic(
|
||||
self,
|
||||
dcx: &'a rustc_errors::DiagCtxt,
|
||||
) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
dcx: &'a DiagCtxt,
|
||||
level: Level,
|
||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
let token_descr = TokenDescription::from_token(&self.token);
|
||||
|
||||
let mut diag = dcx.struct_err(match token_descr {
|
||||
Some(TokenDescription::ReservedIdentifier) => {
|
||||
fluent::parse_expected_semi_found_reserved_identifier_str
|
||||
}
|
||||
Some(TokenDescription::Keyword) => fluent::parse_expected_semi_found_keyword_str,
|
||||
Some(TokenDescription::ReservedKeyword) => {
|
||||
fluent::parse_expected_semi_found_reserved_keyword_str
|
||||
}
|
||||
Some(TokenDescription::DocComment) => fluent::parse_expected_semi_found_doc_comment_str,
|
||||
None => fluent::parse_expected_semi_found_str,
|
||||
});
|
||||
let mut diag = DiagnosticBuilder::new(
|
||||
dcx,
|
||||
level,
|
||||
match token_descr {
|
||||
Some(TokenDescription::ReservedIdentifier) => {
|
||||
fluent::parse_expected_semi_found_reserved_identifier_str
|
||||
}
|
||||
Some(TokenDescription::Keyword) => fluent::parse_expected_semi_found_keyword_str,
|
||||
Some(TokenDescription::ReservedKeyword) => {
|
||||
fluent::parse_expected_semi_found_reserved_keyword_str
|
||||
}
|
||||
Some(TokenDescription::DocComment) => {
|
||||
fluent::parse_expected_semi_found_doc_comment_str
|
||||
}
|
||||
None => fluent::parse_expected_semi_found_str,
|
||||
},
|
||||
);
|
||||
diag.set_span(self.span);
|
||||
diag.set_arg("token", self.token);
|
||||
|
||||
|
@ -1436,10 +1453,7 @@ pub(crate) struct FnTraitMissingParen {
|
|||
impl AddToDiagnostic for FnTraitMissingParen {
|
||||
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
||||
where
|
||||
F: Fn(
|
||||
&mut rustc_errors::Diagnostic,
|
||||
rustc_errors::SubdiagnosticMessage,
|
||||
) -> rustc_errors::SubdiagnosticMessage,
|
||||
F: Fn(&mut rustc_errors::Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
||||
{
|
||||
diag.span_label(self.span, crate::fluent_generated::parse_fn_trait_missing_paren);
|
||||
let applicability = if self.machine_applicable {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue