Give DiagnosticBuilder
a default type.
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
This commit is contained in:
parent
6257f3bf1f
commit
757d6f6ef8
59 changed files with 250 additions and 454 deletions
|
@ -4,8 +4,7 @@ use crate::parse::ParseSess;
|
|||
use rustc_ast::token;
|
||||
use rustc_ast::util::literal::LitError;
|
||||
use rustc_errors::{
|
||||
error_code, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, IntoDiagnostic,
|
||||
Level, MultiSpan,
|
||||
error_code, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, IntoDiagnostic, Level, MultiSpan,
|
||||
};
|
||||
use rustc_macros::Diagnostic;
|
||||
use rustc_span::{BytePos, Span, Symbol};
|
||||
|
@ -18,11 +17,7 @@ pub struct FeatureGateError {
|
|||
|
||||
impl<'a> IntoDiagnostic<'a> for FeatureGateError {
|
||||
#[track_caller]
|
||||
fn into_diagnostic(
|
||||
self,
|
||||
dcx: &'a DiagCtxt,
|
||||
level: Level,
|
||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a> {
|
||||
let mut diag = DiagnosticBuilder::new(dcx, level, self.explain);
|
||||
diag.set_span(self.span);
|
||||
diag.code(error_code!(E0658));
|
||||
|
|
|
@ -83,7 +83,7 @@ pub fn feature_err(
|
|||
feature: Symbol,
|
||||
span: impl Into<MultiSpan>,
|
||||
explain: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
feature_err_issue(sess, feature, span, GateIssue::Language, explain)
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ pub fn feature_err_issue(
|
|||
span: impl Into<MultiSpan>,
|
||||
issue: GateIssue,
|
||||
explain: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
let span = span.into();
|
||||
|
||||
// Cancel an earlier warning for this same error, if it exists.
|
||||
|
@ -318,10 +318,7 @@ impl ParseSess {
|
|||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn create_err<'a>(
|
||||
&'a self,
|
||||
err: impl IntoDiagnostic<'a>,
|
||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> {
|
||||
err.into_diagnostic(&self.dcx, Level::Error { lint: false })
|
||||
}
|
||||
|
||||
|
@ -371,10 +368,7 @@ impl ParseSess {
|
|||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_err(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> {
|
||||
self.dcx.struct_err(msg)
|
||||
}
|
||||
|
||||
|
|
|
@ -354,7 +354,7 @@ impl Session {
|
|||
&self,
|
||||
sp: S,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
self.dcx().struct_span_err(sp, msg)
|
||||
}
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -364,16 +364,13 @@ impl Session {
|
|||
sp: S,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
self.dcx().struct_span_err_with_code(sp, msg, code)
|
||||
}
|
||||
// FIXME: This method should be removed (every error should have an associated error code).
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_err(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> {
|
||||
self.parse_sess.struct_err(msg)
|
||||
}
|
||||
#[track_caller]
|
||||
|
@ -382,7 +379,7 @@ impl Session {
|
|||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
self.dcx().struct_err_with_code(msg, code)
|
||||
}
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -463,10 +460,7 @@ impl Session {
|
|||
self.dcx().err(msg)
|
||||
}
|
||||
#[track_caller]
|
||||
pub fn create_err<'a>(
|
||||
&'a self,
|
||||
err: impl IntoDiagnostic<'a>,
|
||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> {
|
||||
self.parse_sess.create_err(err)
|
||||
}
|
||||
#[track_caller]
|
||||
|
@ -474,7 +468,7 @@ impl Session {
|
|||
&'a self,
|
||||
err: impl IntoDiagnostic<'a>,
|
||||
feature: Symbol,
|
||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'a> {
|
||||
let mut err = self.parse_sess.create_err(err);
|
||||
if err.code.is_none() {
|
||||
err.code = std::option::Option::Some(error_code!(E0658));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue