mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Start migrating DecorateDiagCompat::Builtin items to DecorateDiagCompat::Dynamic
This commit is contained in:
@@ -14,6 +14,18 @@ pub enum DecorateDiagCompat {
|
||||
Builtin(BuiltinLintDiag),
|
||||
}
|
||||
|
||||
pub struct DynamicDiag<
|
||||
F: for<'a> FnOnce(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + 'static,
|
||||
>(Box<F>);
|
||||
|
||||
impl<F: for<'a> FnOnce(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + 'static>
|
||||
DynamicDiag<F>
|
||||
{
|
||||
pub fn new(f: F) -> Self {
|
||||
Self(Box::new(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for DecorateDiagCompat {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("DecorateDiagCompat").finish()
|
||||
@@ -34,6 +46,15 @@ fn from(b: BuiltinLintDiag) -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: for<'a> FnOnce(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + 'static>
|
||||
From<DynamicDiag<F>> for DecorateDiagCompat
|
||||
{
|
||||
#[inline]
|
||||
fn from(d: DynamicDiag<F>) -> Self {
|
||||
Self::Dynamic(d.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Lints that are buffered up early on in the `Session` before the
|
||||
/// `LintLevels` is calculated.
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
Ansi256Color, AnsiColor, Color, EffectIter, Effects, Reset, RgbColor, Style as Anstyle,
|
||||
};
|
||||
pub use codes::*;
|
||||
pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer};
|
||||
pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, DynamicDiag, LintBuffer};
|
||||
pub use diagnostic::{
|
||||
BugAbort, Diag, DiagDecorator, DiagInner, DiagLocation, DiagStyledString, Diagnostic,
|
||||
EmissionGuarantee, FatalAbort, StringPart, Subdiag, Subdiagnostic,
|
||||
|
||||
@@ -170,13 +170,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
|
||||
lints::ReservedMultihash { suggestion }.into_diag(dcx, level)
|
||||
}
|
||||
}
|
||||
BuiltinLintDiag::BreakWithLabelAndLoop(sugg_span) => lints::BreakWithLabelAndLoop {
|
||||
sub: lints::BreakWithLabelAndLoopSub {
|
||||
left: sugg_span.shrink_to_lo(),
|
||||
right: sugg_span.shrink_to_hi(),
|
||||
},
|
||||
}
|
||||
.into_diag(dcx, level),
|
||||
BuiltinLintDiag::DeprecatedWhereclauseLocation(left_sp, sugg) => {
|
||||
let suggestion = match sugg {
|
||||
Some((right_sp, sugg)) => lints::DeprecatedWhereClauseLocationSugg::MoveToEnd {
|
||||
|
||||
@@ -3220,24 +3220,6 @@ pub(crate) struct RawPrefix {
|
||||
pub suggestion: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(
|
||||
"this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression"
|
||||
)]
|
||||
pub(crate) struct BreakWithLabelAndLoop {
|
||||
#[subdiagnostic]
|
||||
pub sub: BreakWithLabelAndLoopSub,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[multipart_suggestion("wrap this expression in parentheses", applicability = "machine-applicable")]
|
||||
pub(crate) struct BreakWithLabelAndLoopSub {
|
||||
#[suggestion_part(code = "(")]
|
||||
pub left: Span,
|
||||
#[suggestion_part(code = ")")]
|
||||
pub right: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("where clause not allowed here")]
|
||||
#[note("see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information")]
|
||||
|
||||
@@ -686,7 +686,6 @@ pub enum BuiltinLintDiag {
|
||||
is_string: bool,
|
||||
suggestion: Span,
|
||||
},
|
||||
BreakWithLabelAndLoop(Span),
|
||||
UnicodeTextFlow(Span, String),
|
||||
DeprecatedWhereclauseLocation(Span, Option<(Span, String)>),
|
||||
SingleUseLifetime {
|
||||
|
||||
@@ -4499,3 +4499,21 @@ pub(super) fn from_token(token: &Token) -> Option<Self> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(
|
||||
"this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression"
|
||||
)]
|
||||
pub(crate) struct BreakWithLabelAndLoop {
|
||||
#[subdiagnostic]
|
||||
pub sub: BreakWithLabelAndLoopSub,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[multipart_suggestion("wrap this expression in parentheses", applicability = "machine-applicable")]
|
||||
pub(crate) struct BreakWithLabelAndLoopSub {
|
||||
#[suggestion_part(code = "(")]
|
||||
pub left: Span,
|
||||
#[suggestion_part(code = ")")]
|
||||
pub right: Span,
|
||||
}
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
StmtKind, Ty, TyKind, UnOp, UnsafeBinderCastKind, YieldKind,
|
||||
};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_errors::{Applicability, Diag, PResult, StashKey, Subdiagnostic};
|
||||
use rustc_errors::{Applicability, Diag, Diagnostic, PResult, StashKey, Subdiagnostic};
|
||||
use rustc_literal_escaper::unescape_char;
|
||||
use rustc_session::errors::{ExprParenthesesNeeded, report_lit_error};
|
||||
use rustc_session::lint::BuiltinLintDiag;
|
||||
use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::{BytePos, ErrorGuaranteed, Ident, Pos, Span, Spanned, Symbol, kw, respan, sym};
|
||||
@@ -1921,11 +1920,20 @@ fn parse_expr_break(&mut self) -> PResult<'a, Box<Expr>> {
|
||||
_ => false,
|
||||
}
|
||||
{
|
||||
let span = expr.span;
|
||||
self.psess.buffer_lint(
|
||||
BREAK_WITH_LABEL_AND_LOOP,
|
||||
lo.to(expr.span),
|
||||
ast::CRATE_NODE_ID,
|
||||
BuiltinLintDiag::BreakWithLabelAndLoop(expr.span),
|
||||
rustc_errors::DynamicDiag::new(move |dcx, level| {
|
||||
errors::BreakWithLabelAndLoop {
|
||||
sub: errors::BreakWithLabelAndLoopSub {
|
||||
left: span.shrink_to_lo(),
|
||||
right: span.shrink_to_hi(),
|
||||
},
|
||||
}
|
||||
.into_diag(dcx, level)
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user