From 021640a7a6f98ebabb98bb852726faf4c1284229 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 3 Mar 2025 08:10:33 -0500 Subject: [PATCH] ruff_db: rename `Diagnostic` to `OldDiagnosticTrait` This trait should eventually go away, so we rename it (and supporting types) to make room for a new concrete `Diagnostic` type. This commit is just the rename. In the next commit, we'll move it to a different module. --- crates/red_knot/src/main.rs | 5 +- crates/red_knot_project/src/db.rs | 6 +-- crates/red_knot_project/src/lib.rs | 27 ++++++----- .../red_knot_project/src/metadata/options.rs | 4 +- .../src/types/call/bind.rs | 4 +- .../src/types/context.rs | 6 +-- .../src/types/diagnostic.rs | 10 ++-- .../src/server/api/requests/diagnostic.rs | 2 +- crates/red_knot_test/src/diagnostic.rs | 12 ++--- crates/red_knot_test/src/lib.rs | 8 ++-- crates/red_knot_test/src/matcher.rs | 36 ++++++++------ crates/red_knot_wasm/src/lib.rs | 2 +- crates/ruff_benchmark/benches/red_knot.rs | 4 +- crates/ruff_db/src/diagnostic.rs | 48 +++++++++---------- 14 files changed, 91 insertions(+), 83 deletions(-) diff --git a/crates/red_knot/src/main.rs b/crates/red_knot/src/main.rs index 07ee47f03e..a9c132894e 100644 --- a/crates/red_knot/src/main.rs +++ b/crates/red_knot/src/main.rs @@ -15,7 +15,7 @@ use red_knot_project::watch::ProjectWatcher; use red_knot_project::{watch, Db}; use red_knot_project::{ProjectDatabase, ProjectMetadata}; use red_knot_server::run_server; -use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig, Severity}; +use ruff_db::diagnostic::{DisplayDiagnosticConfig, OldDiagnosticTrait, Severity}; use ruff_db::system::{OsSystem, SystemPath, SystemPathBuf}; use salsa::plumbing::ZalsaDatabase; @@ -354,8 +354,7 @@ enum MainLoopMessage { CheckWorkspace, CheckCompleted { /// The diagnostics that were found during the check. - result: Vec>, - + result: Vec>, revision: u64, }, ApplyChanges(Vec), diff --git a/crates/red_knot_project/src/db.rs b/crates/red_knot_project/src/db.rs index 96ff04301c..1245c83055 100644 --- a/crates/red_knot_project/src/db.rs +++ b/crates/red_knot_project/src/db.rs @@ -5,7 +5,7 @@ use crate::DEFAULT_LINT_REGISTRY; use crate::{Project, ProjectMetadata}; use red_knot_python_semantic::lint::{LintRegistry, RuleSelection}; use red_knot_python_semantic::{Db as SemanticDb, Program}; -use ruff_db::diagnostic::Diagnostic; +use ruff_db::diagnostic::OldDiagnosticTrait; use ruff_db::files::{File, Files}; use ruff_db::system::System; use ruff_db::vendored::VendoredFileSystem; @@ -55,11 +55,11 @@ impl ProjectDatabase { } /// Checks all open files in the project and its dependencies. - pub fn check(&self) -> Result>, Cancelled> { + pub fn check(&self) -> Result>, Cancelled> { self.with_db(|db| db.project().check(db)) } - pub fn check_file(&self, file: File) -> Result>, Cancelled> { + pub fn check_file(&self, file: File) -> Result>, Cancelled> { let _span = tracing::debug_span!("check_file", file=%file.path(self)).entered(); self.with_db(|db| self.project().check_file(db, file)) diff --git a/crates/red_knot_project/src/lib.rs b/crates/red_knot_project/src/lib.rs index ab0e286727..161030d5b0 100644 --- a/crates/red_knot_project/src/lib.rs +++ b/crates/red_knot_project/src/lib.rs @@ -9,7 +9,7 @@ pub use metadata::{ProjectDiscoveryError, ProjectMetadata}; use red_knot_python_semantic::lint::{LintRegistry, LintRegistryBuilder, RuleSelection}; use red_knot_python_semantic::register_lints; use red_knot_python_semantic::types::check_types; -use ruff_db::diagnostic::{Diagnostic, DiagnosticId, ParseDiagnostic, Severity, Span}; +use ruff_db::diagnostic::{DiagnosticId, OldDiagnosticTrait, ParseDiagnostic, Severity, Span}; use ruff_db::files::File; use ruff_db::parsed::parsed_module; use ruff_db::source::{source_text, SourceTextError}; @@ -163,22 +163,22 @@ impl Project { } /// Checks all open files in the project and its dependencies. - pub(crate) fn check(self, db: &ProjectDatabase) -> Vec> { + pub(crate) fn check(self, db: &ProjectDatabase) -> Vec> { let project_span = tracing::debug_span!("Project::check"); let _span = project_span.enter(); tracing::debug!("Checking project '{name}'", name = self.name(db)); - let mut diagnostics: Vec> = Vec::new(); + let mut diagnostics: Vec> = Vec::new(); diagnostics.extend(self.settings_diagnostics(db).iter().map(|diagnostic| { - let diagnostic: Box = Box::new(diagnostic.clone()); + let diagnostic: Box = Box::new(diagnostic.clone()); diagnostic })); let files = ProjectFiles::new(db, self); diagnostics.extend(files.diagnostics().iter().cloned().map(|diagnostic| { - let diagnostic: Box = Box::new(diagnostic); + let diagnostic: Box = Box::new(diagnostic); diagnostic })); @@ -207,12 +207,12 @@ impl Project { Arc::into_inner(result).unwrap().into_inner().unwrap() } - pub(crate) fn check_file(self, db: &dyn Db, file: File) -> Vec> { + pub(crate) fn check_file(self, db: &dyn Db, file: File) -> Vec> { let mut file_diagnostics: Vec<_> = self .settings_diagnostics(db) .iter() .map(|diagnostic| { - let diagnostic: Box = Box::new(diagnostic.clone()); + let diagnostic: Box = Box::new(diagnostic.clone()); diagnostic }) .collect(); @@ -397,8 +397,8 @@ impl Project { } } -fn check_file_impl(db: &dyn Db, file: File) -> Vec> { - let mut diagnostics: Vec> = Vec::new(); +fn check_file_impl(db: &dyn Db, file: File) -> Vec> { + let mut diagnostics: Vec> = Vec::new(); // Abort checking if there are IO errors. let source = source_text(db.upcast(), file); @@ -413,12 +413,13 @@ fn check_file_impl(db: &dyn Db, file: File) -> Vec> { let parsed = parsed_module(db.upcast(), file); diagnostics.extend(parsed.errors().iter().map(|error| { - let diagnostic: Box = Box::new(ParseDiagnostic::new(file, error.clone())); + let diagnostic: Box = + Box::new(ParseDiagnostic::new(file, error.clone())); diagnostic })); diagnostics.extend(check_types(db.upcast(), file).iter().map(|diagnostic| { - let boxed: Box = Box::new(diagnostic.clone()); + let boxed: Box = Box::new(diagnostic.clone()); boxed })); @@ -492,7 +493,7 @@ pub struct IOErrorDiagnostic { error: IOErrorKind, } -impl Diagnostic for IOErrorDiagnostic { +impl OldDiagnosticTrait for IOErrorDiagnostic { fn id(&self) -> DiagnosticId { DiagnosticId::Io } @@ -524,7 +525,7 @@ mod tests { use crate::db::tests::TestDb; use crate::{check_file_impl, ProjectMetadata}; use red_knot_python_semantic::types::check_types; - use ruff_db::diagnostic::Diagnostic; + use ruff_db::diagnostic::OldDiagnosticTrait; use ruff_db::files::system_path_to_file; use ruff_db::source::source_text; use ruff_db::system::{DbWithTestSystem, SystemPath, SystemPathBuf}; diff --git a/crates/red_knot_project/src/metadata/options.rs b/crates/red_knot_project/src/metadata/options.rs index a96536ff2c..7201d81d8e 100644 --- a/crates/red_knot_project/src/metadata/options.rs +++ b/crates/red_knot_project/src/metadata/options.rs @@ -2,7 +2,7 @@ use crate::metadata::value::{RangedValue, RelativePathBuf, ValueSource, ValueSou use crate::Db; use red_knot_python_semantic::lint::{GetLintError, Level, LintSource, RuleSelection}; use red_knot_python_semantic::{ProgramSettings, PythonPath, PythonPlatform, SearchPathSettings}; -use ruff_db::diagnostic::{Diagnostic, DiagnosticId, Severity, Span}; +use ruff_db::diagnostic::{DiagnosticId, OldDiagnosticTrait, Severity, Span}; use ruff_db::files::system_path_to_file; use ruff_db::system::{System, SystemPath}; use ruff_macros::Combine; @@ -376,7 +376,7 @@ impl OptionDiagnostic { } } -impl Diagnostic for OptionDiagnostic { +impl OldDiagnosticTrait for OptionDiagnostic { fn id(&self) -> DiagnosticId { self.id } diff --git a/crates/red_knot_python_semantic/src/types/call/bind.rs b/crates/red_knot_python_semantic/src/types/call/bind.rs index d5504f9ad4..208a3e46e1 100644 --- a/crates/red_knot_python_semantic/src/types/call/bind.rs +++ b/crates/red_knot_python_semantic/src/types/call/bind.rs @@ -6,7 +6,7 @@ use crate::types::diagnostic::{ }; use crate::types::signatures::Parameter; use crate::types::{todo_type, CallableType, UnionType}; -use ruff_db::diagnostic::{SecondaryDiagnosticMessage, Span}; +use ruff_db::diagnostic::{OldSecondaryDiagnosticMessage, Span}; use ruff_python_ast as ast; use ruff_text_size::Ranged; @@ -388,7 +388,7 @@ impl<'db> CallBindingError<'db> { if let Some(span) = Self::parameter_span_from_index(context.db(), callable_ty, parameter.index) { - messages.push(SecondaryDiagnosticMessage::new( + messages.push(OldSecondaryDiagnosticMessage::new( span, "parameter declared in function definition here", )); diff --git a/crates/red_knot_python_semantic/src/types/context.rs b/crates/red_knot_python_semantic/src/types/context.rs index 53f3aeaff2..330f15f8eb 100644 --- a/crates/red_knot_python_semantic/src/types/context.rs +++ b/crates/red_knot_python_semantic/src/types/context.rs @@ -2,7 +2,7 @@ use std::fmt; use drop_bomb::DebugDropBomb; use ruff_db::{ - diagnostic::{DiagnosticId, SecondaryDiagnosticMessage, Severity}, + diagnostic::{DiagnosticId, OldSecondaryDiagnosticMessage, Severity}, files::File, }; use ruff_text_size::{Ranged, TextRange}; @@ -84,7 +84,7 @@ impl<'db> InferContext<'db> { lint: &'static LintMetadata, ranged: T, message: fmt::Arguments, - secondary_messages: Vec, + secondary_messages: Vec, ) where T: Ranged, { @@ -136,7 +136,7 @@ impl<'db> InferContext<'db> { id: DiagnosticId, severity: Severity, message: fmt::Arguments, - secondary_messages: Vec, + secondary_messages: Vec, ) where T: Ranged, { diff --git a/crates/red_knot_python_semantic/src/types/diagnostic.rs b/crates/red_knot_python_semantic/src/types/diagnostic.rs index f2474259bb..917714fd17 100644 --- a/crates/red_knot_python_semantic/src/types/diagnostic.rs +++ b/crates/red_knot_python_semantic/src/types/diagnostic.rs @@ -8,7 +8,9 @@ use crate::types::string_annotation::{ }; use crate::types::{ClassLiteralType, KnownInstanceType, Type}; use crate::{declare_lint, Db}; -use ruff_db::diagnostic::{Diagnostic, DiagnosticId, SecondaryDiagnosticMessage, Severity, Span}; +use ruff_db::diagnostic::{ + DiagnosticId, OldDiagnosticTrait, OldSecondaryDiagnosticMessage, Severity, Span, +}; use ruff_db::files::File; use ruff_python_ast::{self as ast, AnyNodeRef}; use ruff_text_size::TextRange; @@ -828,7 +830,7 @@ pub struct TypeCheckDiagnostic { pub(crate) range: TextRange, pub(crate) severity: Severity, pub(crate) file: File, - pub(crate) secondary_messages: Vec, + pub(crate) secondary_messages: Vec, } impl TypeCheckDiagnostic { @@ -845,7 +847,7 @@ impl TypeCheckDiagnostic { } } -impl Diagnostic for TypeCheckDiagnostic { +impl OldDiagnosticTrait for TypeCheckDiagnostic { fn id(&self) -> DiagnosticId { self.id } @@ -858,7 +860,7 @@ impl Diagnostic for TypeCheckDiagnostic { Some(Span::from(self.file).with_range(self.range)) } - fn secondary_messages(&self) -> &[SecondaryDiagnosticMessage] { + fn secondary_messages(&self) -> &[OldSecondaryDiagnosticMessage] { &self.secondary_messages } diff --git a/crates/red_knot_server/src/server/api/requests/diagnostic.rs b/crates/red_knot_server/src/server/api/requests/diagnostic.rs index ba788817ec..fc207fe7bd 100644 --- a/crates/red_knot_server/src/server/api/requests/diagnostic.rs +++ b/crates/red_knot_server/src/server/api/requests/diagnostic.rs @@ -72,7 +72,7 @@ fn compute_diagnostics(snapshot: &DocumentSnapshot, db: &ProjectDatabase) -> Vec fn to_lsp_diagnostic( db: &dyn Db, - diagnostic: &dyn ruff_db::diagnostic::Diagnostic, + diagnostic: &dyn ruff_db::diagnostic::OldDiagnosticTrait, encoding: crate::PositionEncoding, ) -> Diagnostic { let range = if let Some(span) = diagnostic.span() { diff --git a/crates/red_knot_test/src/diagnostic.rs b/crates/red_knot_test/src/diagnostic.rs index 56ee51223c..b233edd26b 100644 --- a/crates/red_knot_test/src/diagnostic.rs +++ b/crates/red_knot_test/src/diagnostic.rs @@ -2,7 +2,7 @@ //! //! We don't assume that we will get the diagnostics in source order. -use ruff_db::diagnostic::Diagnostic; +use ruff_db::diagnostic::OldDiagnosticTrait; use ruff_source_file::{LineIndex, OneIndexed}; use std::ops::{Deref, Range}; @@ -19,7 +19,7 @@ pub(crate) struct SortedDiagnostics { impl SortedDiagnostics where - T: Diagnostic, + T: OldDiagnosticTrait, { pub(crate) fn new(diagnostics: impl IntoIterator, line_index: &LineIndex) -> Self { let mut diagnostics: Vec<_> = diagnostics @@ -99,7 +99,7 @@ pub(crate) struct LineDiagnosticsIterator<'a, T> { impl<'a, T> Iterator for LineDiagnosticsIterator<'a, T> where - T: Diagnostic, + T: OldDiagnosticTrait, { type Item = LineDiagnostics<'a, T>; @@ -115,7 +115,7 @@ where } } -impl std::iter::FusedIterator for LineDiagnosticsIterator<'_, T> where T: Diagnostic {} +impl std::iter::FusedIterator for LineDiagnosticsIterator<'_, T> where T: OldDiagnosticTrait {} /// All diagnostics that start on a single line of source code in one embedded Python file. #[derive(Debug)] @@ -144,7 +144,7 @@ struct DiagnosticWithLine { #[cfg(test)] mod tests { use crate::db::Db; - use crate::diagnostic::Diagnostic; + use crate::diagnostic::OldDiagnosticTrait; use ruff_db::diagnostic::{DiagnosticId, LintName, Severity, Span}; use ruff_db::files::{system_path_to_file, File}; use ruff_db::source::line_index; @@ -190,7 +190,7 @@ mod tests { file: File, } - impl Diagnostic for DummyDiagnostic { + impl OldDiagnosticTrait for DummyDiagnostic { fn id(&self) -> DiagnosticId { DiagnosticId::Lint(LintName::of("dummy")) } diff --git a/crates/red_knot_test/src/lib.rs b/crates/red_knot_test/src/lib.rs index 1449933535..04fbf2faf8 100644 --- a/crates/red_knot_test/src/lib.rs +++ b/crates/red_knot_test/src/lib.rs @@ -5,7 +5,7 @@ use colored::Colorize; use parser as test_parser; use red_knot_python_semantic::types::check_types; use red_knot_python_semantic::{Program, ProgramSettings, PythonPath, SearchPathSettings}; -use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig, ParseDiagnostic}; +use ruff_db::diagnostic::{DisplayDiagnosticConfig, OldDiagnosticTrait, ParseDiagnostic}; use ruff_db::files::{system_path_to_file, File, Files}; use ruff_db::panic::catch_unwind; use ruff_db::parsed::parsed_module; @@ -200,7 +200,7 @@ fn run_test( .iter() .cloned() .map(|error| { - let diagnostic: Box = + let diagnostic: Box = Box::new(ParseDiagnostic::new(test_file.file, error)); diagnostic }) @@ -234,7 +234,7 @@ fn run_test( } }; diagnostics.extend(type_diagnostics.into_iter().map(|diagnostic| { - let diagnostic: Box = Box::new((*diagnostic).clone()); + let diagnostic: Box = Box::new((*diagnostic).clone()); diagnostic })); @@ -299,7 +299,7 @@ struct TestFile { backtick_offsets: Vec, } -fn create_diagnostic_snapshot( +fn create_diagnostic_snapshot( db: &mut db::Db, relative_fixture_path: &Utf8Path, test: &parser::MarkdownTest, diff --git a/crates/red_knot_test/src/matcher.rs b/crates/red_knot_test/src/matcher.rs index 57df36d4b8..acaf75ead6 100644 --- a/crates/red_knot_test/src/matcher.rs +++ b/crates/red_knot_test/src/matcher.rs @@ -1,10 +1,10 @@ -//! Match [`Diagnostic`]s against assertions and produce test failure messages for any -//! mismatches. +//! Match [`OldDiagnosticTrait`]s against assertions and produce test failure +//! messages for any mismatches. use crate::assertion::{InlineFileAssertions, ParsedAssertion, UnparsedAssertion}; use crate::db::Db; use crate::diagnostic::SortedDiagnostics; use colored::Colorize; -use ruff_db::diagnostic::{Diagnostic, DiagnosticAsStrError, DiagnosticId}; +use ruff_db::diagnostic::{DiagnosticAsStrError, DiagnosticId, OldDiagnosticTrait}; use ruff_db::files::File; use ruff_db::source::{line_index, source_text, SourceText}; use ruff_source_file::{LineIndex, OneIndexed}; @@ -53,7 +53,7 @@ pub(super) fn match_file( diagnostics: impl IntoIterator, ) -> Result<(), FailuresByLine> where - T: Diagnostic, + T: OldDiagnosticTrait, { // Parse assertions from comments in the file, and get diagnostics from the file; both // ordered by line number. @@ -155,7 +155,7 @@ impl Unmatched for ParsedAssertion<'_> { } } -fn maybe_add_undefined_reveal_clarification( +fn maybe_add_undefined_reveal_clarification( diagnostic: &T, original: std::fmt::Arguments, ) -> String { @@ -171,7 +171,7 @@ fn maybe_add_undefined_reveal_clarification( impl Unmatched for T where - T: Diagnostic, + T: OldDiagnosticTrait, { fn unmatched(&self) -> String { let id = self.id(); @@ -188,7 +188,7 @@ where impl UnmatchedWithColumn for T where - T: Diagnostic, + T: OldDiagnosticTrait, { fn unmatched_with_column(&self, column: OneIndexed) -> String { let id = self.id(); @@ -226,10 +226,12 @@ impl Matcher { } } - /// Check a slice of [`Diagnostic`]s against a slice of [`UnparsedAssertion`]s. + /// Check a slice of [`OldDiagnosticTrait`]s against a slice of + /// [`UnparsedAssertion`]s. /// - /// Return vector of [`Unmatched`] for any unmatched diagnostics or assertions. - fn match_line<'a, 'b, T: Diagnostic + 'a>( + /// Return vector of [`Unmatched`] for any unmatched diagnostics or + /// assertions. + fn match_line<'a, 'b, T: OldDiagnosticTrait + 'a>( &self, diagnostics: &'a [T], assertions: &'a [UnparsedAssertion<'b>], @@ -261,7 +263,7 @@ impl Matcher { } } - fn column(&self, diagnostic: &T) -> OneIndexed { + fn column(&self, diagnostic: &T) -> OneIndexed { diagnostic .span() .and_then(|span| span.range()) @@ -273,7 +275,7 @@ impl Matcher { .unwrap_or(OneIndexed::from_zero_indexed(0)) } - /// Check if `assertion` matches any [`Diagnostic`]s in `unmatched`. + /// Check if `assertion` matches any [`OldDiagnosticTrait`]s in `unmatched`. /// /// If so, return `true` and remove the matched diagnostics from `unmatched`. Otherwise, return /// `false`. @@ -283,7 +285,11 @@ impl Matcher { /// /// A `Revealed` assertion must match a revealed-type diagnostic, and may also match an /// undefined-reveal diagnostic, if present. - fn matches(&self, assertion: &ParsedAssertion, unmatched: &mut Vec<&T>) -> bool { + fn matches( + &self, + assertion: &ParsedAssertion, + unmatched: &mut Vec<&T>, + ) -> bool { match assertion { ParsedAssertion::Error(error) => { let position = unmatched.iter().position(|diagnostic| { @@ -341,7 +347,7 @@ impl Matcher { #[cfg(test)] mod tests { use super::FailuresByLine; - use ruff_db::diagnostic::{Diagnostic, DiagnosticId, Severity, Span}; + use ruff_db::diagnostic::{DiagnosticId, OldDiagnosticTrait, Severity, Span}; use ruff_db::files::{system_path_to_file, File}; use ruff_db::system::{DbWithTestSystem, SystemPathBuf}; use ruff_python_trivia::textwrap::dedent; @@ -383,7 +389,7 @@ mod tests { file: File, } - impl Diagnostic for TestDiagnostic { + impl OldDiagnosticTrait for TestDiagnostic { fn id(&self) -> DiagnosticId { self.id } diff --git a/crates/red_knot_wasm/src/lib.rs b/crates/red_knot_wasm/src/lib.rs index c93c22da5c..3112d3d718 100644 --- a/crates/red_knot_wasm/src/lib.rs +++ b/crates/red_knot_wasm/src/lib.rs @@ -7,7 +7,7 @@ use red_knot_project::metadata::options::{EnvironmentOptions, Options}; use red_knot_project::metadata::value::RangedValue; use red_knot_project::ProjectMetadata; use red_knot_project::{Db, ProjectDatabase}; -use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig}; +use ruff_db::diagnostic::{DisplayDiagnosticConfig, OldDiagnosticTrait}; use ruff_db::files::{system_path_to_file, File}; use ruff_db::system::walk_directory::WalkDirectoryBuilder; use ruff_db::system::{ diff --git a/crates/ruff_benchmark/benches/red_knot.rs b/crates/ruff_benchmark/benches/red_knot.rs index 11ec12577c..06d77c827c 100644 --- a/crates/ruff_benchmark/benches/red_knot.rs +++ b/crates/ruff_benchmark/benches/red_knot.rs @@ -10,7 +10,7 @@ use red_knot_project::watch::{ChangeEvent, ChangedKind}; use red_knot_project::{Db, ProjectDatabase, ProjectMetadata}; use ruff_benchmark::criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use ruff_benchmark::TestFile; -use ruff_db::diagnostic::{Diagnostic, DiagnosticId, Severity}; +use ruff_db::diagnostic::{DiagnosticId, OldDiagnosticTrait, Severity}; use ruff_db::files::{system_path_to_file, File}; use ruff_db::source::source_text; use ruff_db::system::{MemoryFileSystem, SystemPath, SystemPathBuf, TestSystem}; @@ -223,7 +223,7 @@ fn benchmark_cold(criterion: &mut Criterion) { } #[track_caller] -fn assert_diagnostics(db: &dyn Db, diagnostics: &[Box]) { +fn assert_diagnostics(db: &dyn Db, diagnostics: &[Box]) { let normalized: Vec<_> = diagnostics .iter() .map(|diagnostic| { diff --git a/crates/ruff_db/src/diagnostic.rs b/crates/ruff_db/src/diagnostic.rs index 7b47735843..a270a3601a 100644 --- a/crates/ruff_db/src/diagnostic.rs +++ b/crates/ruff_db/src/diagnostic.rs @@ -162,7 +162,7 @@ impl std::fmt::Display for DiagnosticId { } } -pub trait Diagnostic: Send + Sync + std::fmt::Debug { +pub trait OldDiagnosticTrait: Send + Sync + std::fmt::Debug { fn id(&self) -> DiagnosticId; fn message(&self) -> Cow; @@ -175,7 +175,7 @@ pub trait Diagnostic: Send + Sync + std::fmt::Debug { /// Returns an optional sequence of "secondary" messages (with spans) to /// include in the rendering of this diagnostic. - fn secondary_messages(&self) -> &[SecondaryDiagnosticMessage] { + fn secondary_messages(&self) -> &[OldSecondaryDiagnosticMessage] { &[] } @@ -185,11 +185,11 @@ pub trait Diagnostic: Send + Sync + std::fmt::Debug { &'diag self, db: &'db dyn Db, config: &'config DisplayDiagnosticConfig, - ) -> DisplayDiagnostic<'db, 'diag, 'config> + ) -> OldDisplayDiagnostic<'db, 'diag, 'config> where Self: Sized, { - DisplayDiagnostic { + OldDisplayDiagnostic { db, diagnostic: self, config, @@ -199,14 +199,14 @@ pub trait Diagnostic: Send + Sync + std::fmt::Debug { /// A single secondary message assigned to a `Diagnostic`. #[derive(Clone, Debug, Eq, PartialEq)] -pub struct SecondaryDiagnosticMessage { +pub struct OldSecondaryDiagnosticMessage { span: Span, message: String, } -impl SecondaryDiagnosticMessage { - pub fn new(span: Span, message: impl Into) -> SecondaryDiagnosticMessage { - SecondaryDiagnosticMessage { +impl OldSecondaryDiagnosticMessage { + pub fn new(span: Span, message: impl Into) -> OldSecondaryDiagnosticMessage { + OldSecondaryDiagnosticMessage { span, message: message.into(), } @@ -298,13 +298,13 @@ impl DisplayDiagnosticConfig { } } -pub struct DisplayDiagnostic<'db, 'diag, 'config> { +pub struct OldDisplayDiagnostic<'db, 'diag, 'config> { db: &'db dyn Db, - diagnostic: &'diag dyn Diagnostic, + diagnostic: &'diag dyn OldDiagnosticTrait, config: &'config DisplayDiagnosticConfig, } -impl std::fmt::Display for DisplayDiagnostic<'_, '_, '_> { +impl std::fmt::Display for OldDisplayDiagnostic<'_, '_, '_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let render = |f: &mut std::fmt::Formatter, message| { let renderer = if self.config.color { @@ -461,9 +461,9 @@ impl Annotation { } } -impl Diagnostic for Box +impl OldDiagnosticTrait for Box where - T: Diagnostic, + T: OldDiagnosticTrait, { fn id(&self) -> DiagnosticId { (**self).id() @@ -477,7 +477,7 @@ where (**self).span() } - fn secondary_messages(&self) -> &[SecondaryDiagnosticMessage] { + fn secondary_messages(&self) -> &[OldSecondaryDiagnosticMessage] { (**self).secondary_messages() } @@ -486,9 +486,9 @@ where } } -impl Diagnostic for std::sync::Arc +impl OldDiagnosticTrait for std::sync::Arc where - T: Diagnostic, + T: OldDiagnosticTrait, { fn id(&self) -> DiagnosticId { (**self).id() @@ -502,7 +502,7 @@ where (**self).span() } - fn secondary_messages(&self) -> &[SecondaryDiagnosticMessage] { + fn secondary_messages(&self) -> &[OldSecondaryDiagnosticMessage] { (**self).secondary_messages() } @@ -511,7 +511,7 @@ where } } -impl Diagnostic for Box { +impl OldDiagnosticTrait for Box { fn id(&self) -> DiagnosticId { (**self).id() } @@ -524,7 +524,7 @@ impl Diagnostic for Box { (**self).span() } - fn secondary_messages(&self) -> &[SecondaryDiagnosticMessage] { + fn secondary_messages(&self) -> &[OldSecondaryDiagnosticMessage] { (**self).secondary_messages() } @@ -533,7 +533,7 @@ impl Diagnostic for Box { } } -impl Diagnostic for &'_ dyn Diagnostic { +impl OldDiagnosticTrait for &'_ dyn OldDiagnosticTrait { fn id(&self) -> DiagnosticId { (**self).id() } @@ -546,7 +546,7 @@ impl Diagnostic for &'_ dyn Diagnostic { (**self).span() } - fn secondary_messages(&self) -> &[SecondaryDiagnosticMessage] { + fn secondary_messages(&self) -> &[OldSecondaryDiagnosticMessage] { (**self).secondary_messages() } @@ -555,7 +555,7 @@ impl Diagnostic for &'_ dyn Diagnostic { } } -impl Diagnostic for std::sync::Arc { +impl OldDiagnosticTrait for std::sync::Arc { fn id(&self) -> DiagnosticId { (**self).id() } @@ -568,7 +568,7 @@ impl Diagnostic for std::sync::Arc { (**self).span() } - fn secondary_messages(&self) -> &[SecondaryDiagnosticMessage] { + fn secondary_messages(&self) -> &[OldSecondaryDiagnosticMessage] { (**self).secondary_messages() } @@ -589,7 +589,7 @@ impl ParseDiagnostic { } } -impl Diagnostic for ParseDiagnostic { +impl OldDiagnosticTrait for ParseDiagnostic { fn id(&self) -> DiagnosticId { DiagnosticId::InvalidSyntax }