aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide_diagnostics/src/handlers/break_outside_of_loop.rs (renamed from crates/ide_diagnostics/src/break_outside_of_loop.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/inactive_code.rs (renamed from crates/ide_diagnostics/src/inactive_code.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/incorrect_case.rs (renamed from crates/ide_diagnostics/src/incorrect_case.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/macro_error.rs (renamed from crates/ide_diagnostics/src/macro_error.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/mismatched_arg_count.rs (renamed from crates/ide_diagnostics/src/mismatched_arg_count.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/missing_fields.rs (renamed from crates/ide_diagnostics/src/missing_fields.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/missing_match_arms.rs (renamed from crates/ide_diagnostics/src/missing_match_arms.rs)4
-rw-r--r--crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs (renamed from crates/ide_diagnostics/src/missing_ok_or_some_in_tail_expr.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/missing_unsafe.rs (renamed from crates/ide_diagnostics/src/missing_unsafe.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/no_such_field.rs (renamed from crates/ide_diagnostics/src/no_such_field.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/remove_this_semicolon.rs (renamed from crates/ide_diagnostics/src/remove_this_semicolon.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs (renamed from crates/ide_diagnostics/src/replace_filter_map_next_with_find_map.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/unimplemented_builtin_macro.rs (renamed from crates/ide_diagnostics/src/unimplemented_builtin_macro.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/unlinked_file.rs (renamed from crates/ide_diagnostics/src/unlinked_file.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/unresolved_extern_crate.rs (renamed from crates/ide_diagnostics/src/unresolved_extern_crate.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/unresolved_import.rs (renamed from crates/ide_diagnostics/src/unresolved_import.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs (renamed from crates/ide_diagnostics/src/unresolved_macro_call.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/unresolved_module.rs (renamed from crates/ide_diagnostics/src/unresolved_module.rs)2
-rw-r--r--crates/ide_diagnostics/src/handlers/unresolved_proc_macro.rs (renamed from crates/ide_diagnostics/src/unresolved_proc_macro.rs)2
-rw-r--r--crates/ide_diagnostics/src/lib.rs112
20 files changed, 87 insertions, 65 deletions
diff --git a/crates/ide_diagnostics/src/break_outside_of_loop.rs b/crates/ide_diagnostics/src/handlers/break_outside_of_loop.rs
index 79e8cea37..5ad0fbd1b 100644
--- a/crates/ide_diagnostics/src/break_outside_of_loop.rs
+++ b/crates/ide_diagnostics/src/handlers/break_outside_of_loop.rs
@@ -3,7 +3,7 @@ use crate::{Diagnostic, DiagnosticsContext};
3// Diagnostic: break-outside-of-loop 3// Diagnostic: break-outside-of-loop
4// 4//
5// This diagnostic is triggered if the `break` keyword is used outside of a loop. 5// This diagnostic is triggered if the `break` keyword is used outside of a loop.
6pub(super) fn break_outside_of_loop( 6pub(crate) fn break_outside_of_loop(
7 ctx: &DiagnosticsContext<'_>, 7 ctx: &DiagnosticsContext<'_>,
8 d: &hir::BreakOutsideOfLoop, 8 d: &hir::BreakOutsideOfLoop,
9) -> Diagnostic { 9) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/inactive_code.rs b/crates/ide_diagnostics/src/handlers/inactive_code.rs
index 34837cc0d..4b722fd64 100644
--- a/crates/ide_diagnostics/src/inactive_code.rs
+++ b/crates/ide_diagnostics/src/handlers/inactive_code.rs
@@ -6,7 +6,7 @@ use crate::{Diagnostic, DiagnosticsContext, Severity};
6// Diagnostic: inactive-code 6// Diagnostic: inactive-code
7// 7//
8// This diagnostic is shown for code with inactive `#[cfg]` attributes. 8// This diagnostic is shown for code with inactive `#[cfg]` attributes.
9pub(super) fn inactive_code( 9pub(crate) fn inactive_code(
10 ctx: &DiagnosticsContext<'_>, 10 ctx: &DiagnosticsContext<'_>,
11 d: &hir::InactiveCode, 11 d: &hir::InactiveCode,
12) -> Option<Diagnostic> { 12) -> Option<Diagnostic> {
diff --git a/crates/ide_diagnostics/src/incorrect_case.rs b/crates/ide_diagnostics/src/handlers/incorrect_case.rs
index 2cf232d56..3a33029cf 100644
--- a/crates/ide_diagnostics/src/incorrect_case.rs
+++ b/crates/ide_diagnostics/src/handlers/incorrect_case.rs
@@ -13,7 +13,7 @@ use crate::{
13// Diagnostic: incorrect-ident-case 13// Diagnostic: incorrect-ident-case
14// 14//
15// This diagnostic is triggered if an item name doesn't follow https://doc.rust-lang.org/1.0.0/style/style/naming/README.html[Rust naming convention]. 15// This diagnostic is triggered if an item name doesn't follow https://doc.rust-lang.org/1.0.0/style/style/naming/README.html[Rust naming convention].
16pub(super) fn incorrect_case(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCase) -> Diagnostic { 16pub(crate) fn incorrect_case(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCase) -> Diagnostic {
17 Diagnostic::new( 17 Diagnostic::new(
18 "incorrect-ident-case", 18 "incorrect-ident-case",
19 format!( 19 format!(
diff --git a/crates/ide_diagnostics/src/macro_error.rs b/crates/ide_diagnostics/src/handlers/macro_error.rs
index 180f297eb..d4d928ad1 100644
--- a/crates/ide_diagnostics/src/macro_error.rs
+++ b/crates/ide_diagnostics/src/handlers/macro_error.rs
@@ -3,7 +3,7 @@ use crate::{Diagnostic, DiagnosticsContext};
3// Diagnostic: macro-error 3// Diagnostic: macro-error
4// 4//
5// This diagnostic is shown for macro expansion errors. 5// This diagnostic is shown for macro expansion errors.
6pub(super) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) -> Diagnostic { 6pub(crate) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) -> Diagnostic {
7 Diagnostic::new( 7 Diagnostic::new(
8 "macro-error", 8 "macro-error",
9 d.message.clone(), 9 d.message.clone(),
diff --git a/crates/ide_diagnostics/src/mismatched_arg_count.rs b/crates/ide_diagnostics/src/handlers/mismatched_arg_count.rs
index c5749c8a6..ce313b2cc 100644
--- a/crates/ide_diagnostics/src/mismatched_arg_count.rs
+++ b/crates/ide_diagnostics/src/handlers/mismatched_arg_count.rs
@@ -3,7 +3,7 @@ use crate::{Diagnostic, DiagnosticsContext};
3// Diagnostic: mismatched-arg-count 3// Diagnostic: mismatched-arg-count
4// 4//
5// This diagnostic is triggered if a function is invoked with an incorrect amount of arguments. 5// This diagnostic is triggered if a function is invoked with an incorrect amount of arguments.
6pub(super) fn mismatched_arg_count( 6pub(crate) fn mismatched_arg_count(
7 ctx: &DiagnosticsContext<'_>, 7 ctx: &DiagnosticsContext<'_>,
8 d: &hir::MismatchedArgCount, 8 d: &hir::MismatchedArgCount,
9) -> Diagnostic { 9) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/missing_fields.rs b/crates/ide_diagnostics/src/handlers/missing_fields.rs
index 5af67f461..bc82c0e4a 100644
--- a/crates/ide_diagnostics/src/missing_fields.rs
+++ b/crates/ide_diagnostics/src/handlers/missing_fields.rs
@@ -18,7 +18,7 @@ use crate::{fix, Diagnostic, DiagnosticsContext};
18// 18//
19// let a = A { a: 10 }; 19// let a = A { a: 10 };
20// ``` 20// ```
21pub(super) fn missing_fields(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Diagnostic { 21pub(crate) fn missing_fields(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Diagnostic {
22 let mut message = String::from("Missing structure fields:\n"); 22 let mut message = String::from("Missing structure fields:\n");
23 for field in &d.missed_fields { 23 for field in &d.missed_fields {
24 format_to!(message, "- {}\n", field); 24 format_to!(message, "- {}\n", field);
diff --git a/crates/ide_diagnostics/src/missing_match_arms.rs b/crates/ide_diagnostics/src/handlers/missing_match_arms.rs
index c83155d2f..9ea533d74 100644
--- a/crates/ide_diagnostics/src/missing_match_arms.rs
+++ b/crates/ide_diagnostics/src/handlers/missing_match_arms.rs
@@ -5,7 +5,7 @@ use crate::{Diagnostic, DiagnosticsContext};
5// Diagnostic: missing-match-arm 5// Diagnostic: missing-match-arm
6// 6//
7// This diagnostic is triggered if `match` block is missing one or more match arms. 7// This diagnostic is triggered if `match` block is missing one or more match arms.
8pub(super) fn missing_match_arms( 8pub(crate) fn missing_match_arms(
9 ctx: &DiagnosticsContext<'_>, 9 ctx: &DiagnosticsContext<'_>,
10 d: &hir::MissingMatchArms, 10 d: &hir::MissingMatchArms,
11) -> Diagnostic { 11) -> Diagnostic {
@@ -17,7 +17,7 @@ pub(super) fn missing_match_arms(
17} 17}
18 18
19#[cfg(test)] 19#[cfg(test)]
20pub(super) mod tests { 20mod tests {
21 use crate::tests::check_diagnostics; 21 use crate::tests::check_diagnostics;
22 22
23 fn check_diagnostics_no_bails(ra_fixture: &str) { 23 fn check_diagnostics_no_bails(ra_fixture: &str) {
diff --git a/crates/ide_diagnostics/src/missing_ok_or_some_in_tail_expr.rs b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs
index 01c79b6f5..63de54570 100644
--- a/crates/ide_diagnostics/src/missing_ok_or_some_in_tail_expr.rs
+++ b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs
@@ -17,7 +17,7 @@ use crate::{fix, Diagnostic, DiagnosticsContext};
17// 10 17// 10
18// } 18// }
19// ``` 19// ```
20pub(super) fn missing_ok_or_some_in_tail_expr( 20pub(crate) fn missing_ok_or_some_in_tail_expr(
21 ctx: &DiagnosticsContext<'_>, 21 ctx: &DiagnosticsContext<'_>,
22 d: &hir::MissingOkOrSomeInTailExpr, 22 d: &hir::MissingOkOrSomeInTailExpr,
23) -> Diagnostic { 23) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/missing_unsafe.rs b/crates/ide_diagnostics/src/handlers/missing_unsafe.rs
index f5f38a0d3..62d8687ba 100644
--- a/crates/ide_diagnostics/src/missing_unsafe.rs
+++ b/crates/ide_diagnostics/src/handlers/missing_unsafe.rs
@@ -3,7 +3,7 @@ use crate::{Diagnostic, DiagnosticsContext};
3// Diagnostic: missing-unsafe 3// Diagnostic: missing-unsafe
4// 4//
5// This diagnostic is triggered if an operation marked as `unsafe` is used outside of an `unsafe` function or block. 5// This diagnostic is triggered if an operation marked as `unsafe` is used outside of an `unsafe` function or block.
6pub(super) fn missing_unsafe(ctx: &DiagnosticsContext<'_>, d: &hir::MissingUnsafe) -> Diagnostic { 6pub(crate) fn missing_unsafe(ctx: &DiagnosticsContext<'_>, d: &hir::MissingUnsafe) -> Diagnostic {
7 Diagnostic::new( 7 Diagnostic::new(
8 "missing-unsafe", 8 "missing-unsafe",
9 "this operation is unsafe and requires an unsafe function or block", 9 "this operation is unsafe and requires an unsafe function or block",
diff --git a/crates/ide_diagnostics/src/no_such_field.rs b/crates/ide_diagnostics/src/handlers/no_such_field.rs
index c4fa387ca..e4cc8a840 100644
--- a/crates/ide_diagnostics/src/no_such_field.rs
+++ b/crates/ide_diagnostics/src/handlers/no_such_field.rs
@@ -11,7 +11,7 @@ use crate::{fix, Assist, Diagnostic, DiagnosticsContext};
11// Diagnostic: no-such-field 11// Diagnostic: no-such-field
12// 12//
13// This diagnostic is triggered if created structure does not have field provided in record. 13// This diagnostic is triggered if created structure does not have field provided in record.
14pub(super) fn no_such_field(ctx: &DiagnosticsContext<'_>, d: &hir::NoSuchField) -> Diagnostic { 14pub(crate) fn no_such_field(ctx: &DiagnosticsContext<'_>, d: &hir::NoSuchField) -> Diagnostic {
15 Diagnostic::new( 15 Diagnostic::new(
16 "no-such-field", 16 "no-such-field",
17 "no such field", 17 "no such field",
diff --git a/crates/ide_diagnostics/src/remove_this_semicolon.rs b/crates/ide_diagnostics/src/handlers/remove_this_semicolon.rs
index dc6c9c083..b52e4dc84 100644
--- a/crates/ide_diagnostics/src/remove_this_semicolon.rs
+++ b/crates/ide_diagnostics/src/handlers/remove_this_semicolon.rs
@@ -8,7 +8,7 @@ use crate::{fix, Assist, Diagnostic, DiagnosticsContext};
8// Diagnostic: remove-this-semicolon 8// Diagnostic: remove-this-semicolon
9// 9//
10// This diagnostic is triggered when there's an erroneous `;` at the end of the block. 10// This diagnostic is triggered when there's an erroneous `;` at the end of the block.
11pub(super) fn remove_this_semicolon( 11pub(crate) fn remove_this_semicolon(
12 ctx: &DiagnosticsContext<'_>, 12 ctx: &DiagnosticsContext<'_>,
13 d: &hir::RemoveThisSemicolon, 13 d: &hir::RemoveThisSemicolon,
14) -> Diagnostic { 14) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/replace_filter_map_next_with_find_map.rs b/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs
index 775c350d2..10d5da15d 100644
--- a/crates/ide_diagnostics/src/replace_filter_map_next_with_find_map.rs
+++ b/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs
@@ -11,7 +11,7 @@ use crate::{fix, Assist, Diagnostic, DiagnosticsContext, Severity};
11// Diagnostic: replace-filter-map-next-with-find-map 11// Diagnostic: replace-filter-map-next-with-find-map
12// 12//
13// This diagnostic is triggered when `.filter_map(..).next()` is used, rather than the more concise `.find_map(..)`. 13// This diagnostic is triggered when `.filter_map(..).next()` is used, rather than the more concise `.find_map(..)`.
14pub(super) fn replace_filter_map_next_with_find_map( 14pub(crate) fn replace_filter_map_next_with_find_map(
15 ctx: &DiagnosticsContext<'_>, 15 ctx: &DiagnosticsContext<'_>,
16 d: &hir::ReplaceFilterMapNextWithFindMap, 16 d: &hir::ReplaceFilterMapNextWithFindMap,
17) -> Diagnostic { 17) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/unimplemented_builtin_macro.rs b/crates/ide_diagnostics/src/handlers/unimplemented_builtin_macro.rs
index a600544f0..e879de75c 100644
--- a/crates/ide_diagnostics/src/unimplemented_builtin_macro.rs
+++ b/crates/ide_diagnostics/src/handlers/unimplemented_builtin_macro.rs
@@ -3,7 +3,7 @@ use crate::{Diagnostic, DiagnosticsContext, Severity};
3// Diagnostic: unimplemented-builtin-macro 3// Diagnostic: unimplemented-builtin-macro
4// 4//
5// This diagnostic is shown for builtin macros which are not yet implemented by rust-analyzer 5// This diagnostic is shown for builtin macros which are not yet implemented by rust-analyzer
6pub(super) fn unimplemented_builtin_macro( 6pub(crate) fn unimplemented_builtin_macro(
7 ctx: &DiagnosticsContext<'_>, 7 ctx: &DiagnosticsContext<'_>,
8 d: &hir::UnimplementedBuiltinMacro, 8 d: &hir::UnimplementedBuiltinMacro,
9) -> Diagnostic { 9) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/unlinked_file.rs b/crates/ide_diagnostics/src/handlers/unlinked_file.rs
index 424532e3a..8921ddde2 100644
--- a/crates/ide_diagnostics/src/unlinked_file.rs
+++ b/crates/ide_diagnostics/src/handlers/unlinked_file.rs
@@ -23,7 +23,7 @@ pub(crate) struct UnlinkedFile {
23// 23//
24// This diagnostic is shown for files that are not included in any crate, or files that are part of 24// This diagnostic is shown for files that are not included in any crate, or files that are part of
25// crates rust-analyzer failed to discover. The file will not have IDE features available. 25// crates rust-analyzer failed to discover. The file will not have IDE features available.
26pub(super) fn unlinked_file(ctx: &DiagnosticsContext, d: &UnlinkedFile) -> Diagnostic { 26pub(crate) fn unlinked_file(ctx: &DiagnosticsContext, d: &UnlinkedFile) -> Diagnostic {
27 // Limit diagnostic to the first few characters in the file. This matches how VS Code 27 // Limit diagnostic to the first few characters in the file. This matches how VS Code
28 // renders it with the full span, but on other editors, and is less invasive. 28 // renders it with the full span, but on other editors, and is less invasive.
29 let range = ctx.sema.db.parse(d.file).syntax_node().text_range(); 29 let range = ctx.sema.db.parse(d.file).syntax_node().text_range();
diff --git a/crates/ide_diagnostics/src/unresolved_extern_crate.rs b/crates/ide_diagnostics/src/handlers/unresolved_extern_crate.rs
index 69f07d0b0..f5313cc0c 100644
--- a/crates/ide_diagnostics/src/unresolved_extern_crate.rs
+++ b/crates/ide_diagnostics/src/handlers/unresolved_extern_crate.rs
@@ -3,7 +3,7 @@ use crate::{Diagnostic, DiagnosticsContext};
3// Diagnostic: unresolved-extern-crate 3// Diagnostic: unresolved-extern-crate
4// 4//
5// This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate. 5// This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate.
6pub(super) fn unresolved_extern_crate( 6pub(crate) fn unresolved_extern_crate(
7 ctx: &DiagnosticsContext<'_>, 7 ctx: &DiagnosticsContext<'_>,
8 d: &hir::UnresolvedExternCrate, 8 d: &hir::UnresolvedExternCrate,
9) -> Diagnostic { 9) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/unresolved_import.rs b/crates/ide_diagnostics/src/handlers/unresolved_import.rs
index 7779033d4..f30051c12 100644
--- a/crates/ide_diagnostics/src/unresolved_import.rs
+++ b/crates/ide_diagnostics/src/handlers/unresolved_import.rs
@@ -4,7 +4,7 @@ use crate::{Diagnostic, DiagnosticsContext};
4// 4//
5// This diagnostic is triggered if rust-analyzer is unable to resolve a path in 5// This diagnostic is triggered if rust-analyzer is unable to resolve a path in
6// a `use` declaration. 6// a `use` declaration.
7pub(super) fn unresolved_import( 7pub(crate) fn unresolved_import(
8 ctx: &DiagnosticsContext<'_>, 8 ctx: &DiagnosticsContext<'_>,
9 d: &hir::UnresolvedImport, 9 d: &hir::UnresolvedImport,
10) -> Diagnostic { 10) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/unresolved_macro_call.rs b/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs
index 88133d0f3..4c3c1c19a 100644
--- a/crates/ide_diagnostics/src/unresolved_macro_call.rs
+++ b/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs
@@ -7,7 +7,7 @@ use crate::{Diagnostic, DiagnosticsContext};
7// 7//
8// This diagnostic is triggered if rust-analyzer is unable to resolve the path 8// This diagnostic is triggered if rust-analyzer is unable to resolve the path
9// to a macro in a macro invocation. 9// to a macro in a macro invocation.
10pub(super) fn unresolved_macro_call( 10pub(crate) fn unresolved_macro_call(
11 ctx: &DiagnosticsContext<'_>, 11 ctx: &DiagnosticsContext<'_>,
12 d: &hir::UnresolvedMacroCall, 12 d: &hir::UnresolvedMacroCall,
13) -> Diagnostic { 13) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/unresolved_module.rs b/crates/ide_diagnostics/src/handlers/unresolved_module.rs
index 5aa9dae17..17166a0c6 100644
--- a/crates/ide_diagnostics/src/unresolved_module.rs
+++ b/crates/ide_diagnostics/src/handlers/unresolved_module.rs
@@ -7,7 +7,7 @@ use crate::{fix, Diagnostic, DiagnosticsContext};
7// Diagnostic: unresolved-module 7// Diagnostic: unresolved-module
8// 8//
9// This diagnostic is triggered if rust-analyzer is unable to discover referred module. 9// This diagnostic is triggered if rust-analyzer is unable to discover referred module.
10pub(super) fn unresolved_module( 10pub(crate) fn unresolved_module(
11 ctx: &DiagnosticsContext<'_>, 11 ctx: &DiagnosticsContext<'_>,
12 d: &hir::UnresolvedModule, 12 d: &hir::UnresolvedModule,
13) -> Diagnostic { 13) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/unresolved_proc_macro.rs b/crates/ide_diagnostics/src/handlers/unresolved_proc_macro.rs
index 744cce508..fde1d1323 100644
--- a/crates/ide_diagnostics/src/unresolved_proc_macro.rs
+++ b/crates/ide_diagnostics/src/handlers/unresolved_proc_macro.rs
@@ -9,7 +9,7 @@ use crate::{Diagnostic, DiagnosticsContext, Severity};
9// If you are seeing a lot of "proc macro not expanded" warnings, you can add this option to the 9// If you are seeing a lot of "proc macro not expanded" warnings, you can add this option to the
10// `rust-analyzer.diagnostics.disabled` list to prevent them from showing. Alternatively you can 10// `rust-analyzer.diagnostics.disabled` list to prevent them from showing. Alternatively you can
11// enable support for procedural macros (see `rust-analyzer.procMacro.enable`). 11// enable support for procedural macros (see `rust-analyzer.procMacro.enable`).
12pub(super) fn unresolved_proc_macro( 12pub(crate) fn unresolved_proc_macro(
13 ctx: &DiagnosticsContext<'_>, 13 ctx: &DiagnosticsContext<'_>,
14 d: &hir::UnresolvedProcMacro, 14 d: &hir::UnresolvedProcMacro,
15) -> Diagnostic { 15) -> Diagnostic {
diff --git a/crates/ide_diagnostics/src/lib.rs b/crates/ide_diagnostics/src/lib.rs
index 2a16c73a8..88037be5a 100644
--- a/crates/ide_diagnostics/src/lib.rs
+++ b/crates/ide_diagnostics/src/lib.rs
@@ -1,28 +1,49 @@
1//! Collects diagnostics & fixits for a single file. 1//! Diagnostics rendering and fixits.
2//! 2//!
3//! The tricky bit here is that diagnostics are produced by hir in terms of 3//! Most of the diagnostics originate from the dark depth of the compiler, and
4//! macro-expanded files, but we need to present them to the users in terms of 4//! are originally expressed in term of IR. When we emit the diagnostic, we are
5//! original files. So we need to map the ranges. 5//! usually not in the position to decide how to best "render" it in terms of
6 6//! user-authored source code. We are especially not in the position to offer
7mod break_outside_of_loop; 7//! fixits, as the compiler completely lacks the infrastructure to edit the
8mod inactive_code; 8//! source code.
9mod incorrect_case; 9//!
10mod macro_error; 10//! Instead, we "bubble up" raw, structured diagnostics until the `hir` crate,
11mod mismatched_arg_count; 11//! where we "cook" them so that each diagnostic is formulated in terms of `hir`
12mod missing_fields; 12//! types. Well, at least that's the aspiration, the "cooking" is somewhat
13mod missing_match_arms; 13//! ad-hoc at the moment. Anyways, we get a bunch of ide-friendly diagnostic
14mod missing_ok_or_some_in_tail_expr; 14//! structs from hir, and we want to render them to unified serializable
15mod missing_unsafe; 15//! representation (span, level, message) here. If we can, we also provide
16mod no_such_field; 16//! fixits. By the way, that's why we want to keep diagnostics structured
17mod remove_this_semicolon; 17//! internally -- so that we have all the info to make fixes.
18mod replace_filter_map_next_with_find_map; 18//!
19mod unimplemented_builtin_macro; 19//! We have one "handler" module per diagnostic code. Such a module contains
20mod unlinked_file; 20//! rendering, optional fixes and tests. It's OK if some low-level compiler
21mod unresolved_extern_crate; 21//! functionality ends up being tested via a diagnostic.
22mod unresolved_import; 22//!
23mod unresolved_macro_call; 23//! There are also a couple of ad-hoc diagnostics implemented directly here, we
24mod unresolved_module; 24//! don't yet have a great pattern for how to do them properly.
25mod unresolved_proc_macro; 25
26mod handlers {
27 pub(crate) mod break_outside_of_loop;
28 pub(crate) mod inactive_code;
29 pub(crate) mod incorrect_case;
30 pub(crate) mod macro_error;
31 pub(crate) mod mismatched_arg_count;
32 pub(crate) mod missing_fields;
33 pub(crate) mod missing_match_arms;
34 pub(crate) mod missing_ok_or_some_in_tail_expr;
35 pub(crate) mod missing_unsafe;
36 pub(crate) mod no_such_field;
37 pub(crate) mod remove_this_semicolon;
38 pub(crate) mod replace_filter_map_next_with_find_map;
39 pub(crate) mod unimplemented_builtin_macro;
40 pub(crate) mod unlinked_file;
41 pub(crate) mod unresolved_extern_crate;
42 pub(crate) mod unresolved_import;
43 pub(crate) mod unresolved_macro_call;
44 pub(crate) mod unresolved_module;
45 pub(crate) mod unresolved_proc_macro;
46}
26 47
27mod field_shorthand; 48mod field_shorthand;
28 49
@@ -41,7 +62,8 @@ use syntax::{
41 SyntaxNode, TextRange, 62 SyntaxNode, TextRange,
42}; 63};
43use text_edit::TextEdit; 64use text_edit::TextEdit;
44use unlinked_file::UnlinkedFile; 65
66use crate::handlers::unlinked_file::UnlinkedFile;
45 67
46#[derive(Copy, Clone, Debug, PartialEq)] 68#[derive(Copy, Clone, Debug, PartialEq)]
47pub struct DiagnosticCode(pub &'static str); 69pub struct DiagnosticCode(pub &'static str);
@@ -148,32 +170,32 @@ pub fn diagnostics(
148 let ctx = DiagnosticsContext { config, sema, resolve }; 170 let ctx = DiagnosticsContext { config, sema, resolve };
149 if module.is_none() { 171 if module.is_none() {
150 let d = UnlinkedFile { file: file_id }; 172 let d = UnlinkedFile { file: file_id };
151 let d = unlinked_file::unlinked_file(&ctx, &d); 173 let d = handlers::unlinked_file::unlinked_file(&ctx, &d);
152 res.push(d) 174 res.push(d)
153 } 175 }
154 176
155 for diag in diags { 177 for diag in diags {
156 #[rustfmt::skip] 178 #[rustfmt::skip]
157 let d = match diag { 179 let d = match diag {
158 AnyDiagnostic::BreakOutsideOfLoop(d) => break_outside_of_loop::break_outside_of_loop(&ctx, &d), 180 AnyDiagnostic::BreakOutsideOfLoop(d) => handlers::break_outside_of_loop::break_outside_of_loop(&ctx, &d),
159 AnyDiagnostic::IncorrectCase(d) => incorrect_case::incorrect_case(&ctx, &d), 181 AnyDiagnostic::IncorrectCase(d) => handlers::incorrect_case::incorrect_case(&ctx, &d),
160 AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d), 182 AnyDiagnostic::MacroError(d) => handlers::macro_error::macro_error(&ctx, &d),
161 AnyDiagnostic::MismatchedArgCount(d) => mismatched_arg_count::mismatched_arg_count(&ctx, &d), 183 AnyDiagnostic::MismatchedArgCount(d) => handlers::mismatched_arg_count::mismatched_arg_count(&ctx, &d),
162 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), 184 AnyDiagnostic::MissingFields(d) => handlers::missing_fields::missing_fields(&ctx, &d),
163 AnyDiagnostic::MissingMatchArms(d) => missing_match_arms::missing_match_arms(&ctx, &d), 185 AnyDiagnostic::MissingMatchArms(d) => handlers::missing_match_arms::missing_match_arms(&ctx, &d),
164 AnyDiagnostic::MissingOkOrSomeInTailExpr(d) => missing_ok_or_some_in_tail_expr::missing_ok_or_some_in_tail_expr(&ctx, &d), 186 AnyDiagnostic::MissingOkOrSomeInTailExpr(d) => handlers::missing_ok_or_some_in_tail_expr::missing_ok_or_some_in_tail_expr(&ctx, &d),
165 AnyDiagnostic::MissingUnsafe(d) => missing_unsafe::missing_unsafe(&ctx, &d), 187 AnyDiagnostic::MissingUnsafe(d) => handlers::missing_unsafe::missing_unsafe(&ctx, &d),
166 AnyDiagnostic::NoSuchField(d) => no_such_field::no_such_field(&ctx, &d), 188 AnyDiagnostic::NoSuchField(d) => handlers::no_such_field::no_such_field(&ctx, &d),
167 AnyDiagnostic::RemoveThisSemicolon(d) => remove_this_semicolon::remove_this_semicolon(&ctx, &d), 189 AnyDiagnostic::RemoveThisSemicolon(d) => handlers::remove_this_semicolon::remove_this_semicolon(&ctx, &d),
168 AnyDiagnostic::ReplaceFilterMapNextWithFindMap(d) => replace_filter_map_next_with_find_map::replace_filter_map_next_with_find_map(&ctx, &d), 190 AnyDiagnostic::ReplaceFilterMapNextWithFindMap(d) => handlers::replace_filter_map_next_with_find_map::replace_filter_map_next_with_find_map(&ctx, &d),
169 AnyDiagnostic::UnimplementedBuiltinMacro(d) => unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d), 191 AnyDiagnostic::UnimplementedBuiltinMacro(d) => handlers::unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d),
170 AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d), 192 AnyDiagnostic::UnresolvedExternCrate(d) => handlers::unresolved_extern_crate::unresolved_extern_crate(&ctx, &d),
171 AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d), 193 AnyDiagnostic::UnresolvedImport(d) => handlers::unresolved_import::unresolved_import(&ctx, &d),
172 AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d), 194 AnyDiagnostic::UnresolvedMacroCall(d) => handlers::unresolved_macro_call::unresolved_macro_call(&ctx, &d),
173 AnyDiagnostic::UnresolvedModule(d) => unresolved_module::unresolved_module(&ctx, &d), 195 AnyDiagnostic::UnresolvedModule(d) => handlers::unresolved_module::unresolved_module(&ctx, &d),
174 AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d), 196 AnyDiagnostic::UnresolvedProcMacro(d) => handlers::unresolved_proc_macro::unresolved_proc_macro(&ctx, &d),
175 197
176 AnyDiagnostic::InactiveCode(d) => match inactive_code::inactive_code(&ctx, &d) { 198 AnyDiagnostic::InactiveCode(d) => match handlers::inactive_code::inactive_code(&ctx, &d) {
177 Some(it) => it, 199 Some(it) => it,
178 None => continue, 200 None => continue,
179 } 201 }