-
Notifications
You must be signed in to change notification settings - Fork 6
Refactor Diagnostic Creation #770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
InsertCreativityHere
merged 9 commits into
icerpc:main
from
InsertCreativityHere:refactor-diagnostic-creation
Apr 15, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ce21d0f
All the diagnostic creation has been updated.
InsertCreativityHere d58dbd6
Moved the 'ALLOWABLE_LINT_IDENTIFIERS' to the 'allow' module.
InsertCreativityHere 19fcf08
Removed the 'implement_diagnostic_functions_for' macro.
InsertCreativityHere ad51705
Keep the old 'Allowed' name for now.
InsertCreativityHere 1f5e93d
Splitting this off into it's own PR for reviewability.
InsertCreativityHere 3972569
Remove 'From' impls.
InsertCreativityHere 0766cb9
Update test messages.
InsertCreativityHere 373a9f1
Remove trailing comma
InsertCreativityHere 28e1253
Use better constructor names.
InsertCreativityHere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,12 @@ pub struct Diagnostic { | |
| } | ||
|
|
||
| impl Diagnostic { | ||
| pub fn new(kind: impl Into<DiagnosticKind>) -> Self { | ||
| let kind = kind.into(); | ||
| /// Creates a new `Diagnostic` directly from a [`DiagnosticKind`]. | ||
| /// The newly created `Diagnostic` has no `span`, `scope`, or `notes` set. | ||
| pub fn new(kind: DiagnosticKind) -> Self { | ||
| let level = match &kind { | ||
| DiagnosticKind::Error(_) => DiagnosticLevel::Error, | ||
| DiagnosticKind::Lint(lint) => lint.get_default_level(), | ||
| DiagnosticKind::Lint(lint) => lint.default_diagnostic_level(), | ||
| }; | ||
|
|
||
| Diagnostic { | ||
|
|
@@ -34,6 +35,18 @@ impl Diagnostic { | |
| } | ||
| } | ||
|
|
||
| /// Creates a new error `Diagnostic` from the provided [`Error`]. | ||
| /// The newly created `Diagnostic` has no `span`, `scope`, or `notes` set. | ||
| pub fn from_error(error: Error) -> Self { | ||
| Self::new(DiagnosticKind::Error(error)) | ||
| } | ||
|
|
||
| /// Creates a new lint `Diagnostic` from the provided [`Lint`]. | ||
| /// The newly created `Diagnostic` has no `span`, `scope`, or `notes` set. | ||
| pub fn from_lint(lint: Lint) -> Self { | ||
| Self::new(DiagnosticKind::Lint(lint)) | ||
| } | ||
|
|
||
| /// Returns the message of this diagnostic. | ||
| pub fn message(&self) -> String { | ||
| match &self.kind { | ||
|
|
@@ -45,8 +58,8 @@ impl Diagnostic { | |
| /// Returns this diagnostic's code. This is either the name of a lint or of the form `E###`. | ||
| pub fn code(&self) -> &str { | ||
| match &self.kind { | ||
| DiagnosticKind::Error(error) => error.code(), | ||
| DiagnosticKind::Lint(lint) => lint.code(), | ||
| DiagnosticKind::Error(error) => error.error_code(), | ||
| DiagnosticKind::Lint(lint) => lint.lint_name(), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -105,18 +118,6 @@ pub enum DiagnosticKind { | |
| Lint(Lint), | ||
| } | ||
|
|
||
| impl From<Error> for DiagnosticKind { | ||
| fn from(error: Error) -> Self { | ||
| DiagnosticKind::Error(error) | ||
| } | ||
| } | ||
|
|
||
| impl From<Lint> for DiagnosticKind { | ||
| fn from(lint: Lint) -> Self { | ||
| DiagnosticKind::Lint(lint) | ||
| } | ||
| } | ||
|
Comment on lines
-108
to
-118
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are no longer needed now that we have dedicated constructors for |
||
|
|
||
| /// Diagnostic levels describe the severity of a diagnostic, and how the compiler should react to their emission. | ||
| #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub enum DiagnosticLevel { | ||
|
|
@@ -160,7 +161,7 @@ impl Diagnostics { | |
| pub fn into_updated(mut self, ast: &Ast, files: &[SliceFile], options: &SliceOptions) -> Vec<Diagnostic> { | ||
| // Helper function that checks whether a lint should be allowed according to the provided identifiers. | ||
| fn is_lint_allowed_by<'b>(mut identifiers: impl Iterator<Item = &'b String>, lint: &Lint) -> bool { | ||
| identifiers.any(|identifier| identifier == "All" || identifier == lint.code()) | ||
| identifiers.any(|identifier| identifier == "All" || identifier == lint.lint_name()) | ||
| } | ||
|
|
||
| // Helper function that checks whether a lint is allowed by attributes on the provided entity. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.