-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add diagnostics for missing bodies for free and associated items #23262
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
+163
−22
Merged
Changes from all commits
Commits
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext}; | ||
|
|
||
| // Diagnostic: missing-body | ||
| // | ||
| // This diagnostic is triggered when a body is missing. | ||
| pub(crate) fn missing_body(ctx: &DiagnosticsContext<'_, '_>, d: &hir::MissingBody) -> Diagnostic { | ||
| let message = match d.kind { | ||
| hir::MissingBodyItemKind::AssocConst => "associated constant in `impl` without body", | ||
| hir::MissingBodyItemKind::AssocType => "associated type in `impl` without body", | ||
| hir::MissingBodyItemKind::Const => "free constant item without body", | ||
| hir::MissingBodyItemKind::Static => "free static item without body", | ||
| hir::MissingBodyItemKind::TypeAlias => "free type alias without body", | ||
| }; | ||
| Diagnostic::new_with_syntax_node_ptr(ctx, DiagnosticCode::SyntaxError, message, d.node).stable() | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::tests::check_diagnostics; | ||
|
|
||
| #[test] | ||
| fn associated_const() { | ||
| check_diagnostics( | ||
| r#" | ||
| trait Foo { const BAR: u32; } | ||
| impl Foo for () { const BAR: u32; } | ||
| //^^^^^^^^^^^^^^^ error: associated constant in `impl` without body | ||
| "#, | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn associated_type_impl() { | ||
| check_diagnostics( | ||
| r#" | ||
| trait Foo { type Bar; } | ||
| impl Foo for () { type Bar; } | ||
| //^^^^^^^^^ error: associated type in `impl` without body | ||
| "#, | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn free_const() { | ||
| check_diagnostics( | ||
| r#" | ||
| const FOO: u32; | ||
| //^^^^^^^^^^^^^^^ error: free constant item without body | ||
| "#, | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn free_static() { | ||
| check_diagnostics( | ||
| r#" | ||
| static FOO: u32; | ||
| //^^^^^^^^^^^^^^^^ error: free static item without body | ||
| "#, | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn type_alias_module() { | ||
| check_diagnostics( | ||
| r#" | ||
| type Foo; | ||
| //^^^^^^^^^ error: free type alias without body | ||
| "#, | ||
| ); | ||
| } | ||
| } |
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
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.