mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Implement Diagnostic directly on Box<FnOnce...>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
use std::path::PathBuf;
|
||||
use std::thread::panicking;
|
||||
|
||||
use rustc_data_structures::sync::DynSend;
|
||||
use rustc_error_messages::{DiagArgMap, DiagArgName, DiagArgValue, IntoDiagArg};
|
||||
use rustc_lint_defs::{Applicability, LintExpectationId};
|
||||
use rustc_macros::{Decodable, Encodable};
|
||||
@@ -118,6 +119,14 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Diagnostic<'a, ()>
|
||||
for Box<dyn for<'b> FnOnce(DiagCtxtHandle<'b>, Level) -> Diag<'b, ()> + DynSend + 'static>
|
||||
{
|
||||
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
|
||||
self(dcx, level)
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait implemented by error types. This should not be implemented manually. Instead, use
|
||||
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
|
||||
#[rustc_diagnostic_item = "Subdiagnostic"]
|
||||
|
||||
@@ -7,10 +7,7 @@
|
||||
use rustc_ast::visit::{self as ast_visit, Visitor, walk_list};
|
||||
use rustc_ast::{self as ast, AttrVec, HasAttrs};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::sync::DynSend;
|
||||
use rustc_errors::{
|
||||
BufferedEarlyLint, DecorateDiagCompat, Diag, DiagCtxtHandle, Diagnostic, Level, LintBuffer,
|
||||
};
|
||||
use rustc_errors::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer};
|
||||
use rustc_feature::Features;
|
||||
use rustc_middle::ty::{RegisteredTools, TyCtxt};
|
||||
use rustc_session::Session;
|
||||
@@ -38,16 +35,6 @@ pub struct EarlyContextAndPass<'ecx, 'tcx, T: EarlyLintPass> {
|
||||
|
||||
impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
|
||||
fn check_id(&mut self, id: ast::NodeId) {
|
||||
struct BoxDiag(
|
||||
Box<dyn for<'a> FnOnce(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + 'static>,
|
||||
);
|
||||
|
||||
impl<'a> Diagnostic<'a, ()> for BoxDiag {
|
||||
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
|
||||
(self.0)(dcx, level)
|
||||
}
|
||||
}
|
||||
|
||||
for early_lint in self.context.buffered.take(id) {
|
||||
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
|
||||
match diagnostic {
|
||||
@@ -63,7 +50,7 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
|
||||
);
|
||||
}
|
||||
DecorateDiagCompat::Dynamic(d) => {
|
||||
self.context.opt_span_diag_lint(lint_id.lint, span, BoxDiag(d));
|
||||
self.context.opt_span_diag_lint(lint_id.lint, span, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user