Diagnostics
While most errors and warnings provided by rust-analyzer come from the
cargo check
integration, there’s a growing number of diagnostics
implemented using rust-analyzer’s own analysis. Some of these
diagnostics don’t respect #[allow]
or \#[deny]
attributes yet, but
can be turned off using the rust-analyzer.diagnostics.enable
,
rust-analyzer.diagnostics.experimental.enable
or
rust-analyzer.diagnostics.disabled
settings.
Clippy
To run cargo clippy
instead of cargo check
, you can set
"rust-analyzer.check.command": "clippy"
.
break-outside-of-loop
Source: break_outside_of_loop.rs
This diagnostic is triggered if the break
keyword is used outside of a loop.
expected-function
Source: expected_function.rs
This diagnostic is triggered if a call is made on something that is not callable.
inactive-code
Source: inactive_code.rs
This diagnostic is shown for code with inactive #[cfg]
attributes.
incoherent-impl
Source: incoherent_impl.rs
This diagnostic is triggered if the targe type of an impl is from a foreign crate.
incorrect-ident-case
Source: incorrect_case.rs
This diagnostic is triggered if an item name doesn't follow Rust naming convention.
invalid-derive-target
Source: invalid_derive_target.rs
This diagnostic is shown when the derive attribute is used on an item other than a struct
,
enum
or union
.
macro-error
Source: macro_error.rs
This diagnostic is shown for macro expansion errors.
macro-error
Source: macro_error.rs
This diagnostic is shown for macro expansion errors.
malformed-derive
Source: malformed_derive.rs
This diagnostic is shown when the derive attribute has invalid input.
mismatched-arg-count
Source: mismatched_arg_count.rs
This diagnostic is triggered if a function is invoked with an incorrect amount of arguments.
mismatched-tuple-struct-pat-arg-count
Source: mismatched_arg_count.rs
This diagnostic is triggered if a function is invoked with an incorrect amount of arguments.
missing-fields
Source: missing_fields.rs
This diagnostic is triggered if record lacks some fields that exist in the corresponding structure.
Example:
struct A { a: u8, b: u8 }
let a = A { a: 10 };
missing-match-arm
Source: missing_match_arms.rs
This diagnostic is triggered if match
block is missing one or more match arms.
missing-unsafe
Source: missing_unsafe.rs
This diagnostic is triggered if an operation marked as unsafe
is used outside of an unsafe
function or block.
moved-out-of-ref
Source: moved_out_of_ref.rs
This diagnostic is triggered on moving non copy things out of references.
need-mut
Source: mutability_errors.rs
This diagnostic is triggered on mutating an immutable variable.
no-such-field
Source: no_such_field.rs
This diagnostic is triggered if created structure does not have field provided in record.
private-assoc-item
Source: private_assoc_item.rs
This diagnostic is triggered if the referenced associated item is not visible from the current module.
private-field
Source: private_field.rs
This diagnostic is triggered if the accessed field is not visible from the current module.
replace-filter-map-next-with-find-map
Source: replace_filter_map_next_with_find_map.rs
This diagnostic is triggered when .filter_map(..).next()
is used, rather than the more concise .find_map(..)
.
type-mismatch
Source: type_mismatch.rs
This diagnostic is triggered when the type of an expression or pattern does not match the expected type.
typed-hole
Source: typed_hole.rs
This diagnostic is triggered when an underscore expression is used in an invalid position.
undeclared-label
Source: undeclared_label.rs
unimplemented-builtin-macro
Source: unimplemented_builtin_macro.rs
This diagnostic is shown for builtin macros which are not yet implemented by rust-analyzer
unlinked-file
Source: unlinked_file.rs
This diagnostic is shown for files that are not included in any crate, or files that are part of crates rust-analyzer failed to discover. The file will not have IDE features available.
unnecessary-braces
Source: useless_braces.rs
Diagnostic for unnecessary braces in use
items.
unreachable-label
Source: unreachable_label.rs
unresolved-extern-crate
Source: unresolved_extern_crate.rs
This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate.
unresolved-field
Source: unresolved_field.rs
This diagnostic is triggered if a field does not exist on a given type.
unresolved-import
Source: unresolved_import.rs
This diagnostic is triggered if rust-analyzer is unable to resolve a path in
a use
declaration.
unresolved-macro-call
Source: unresolved_macro_call.rs
This diagnostic is triggered if rust-analyzer is unable to resolve the path to a macro in a macro invocation.
unresolved-method
Source: unresolved_method.rs
This diagnostic is triggered if a method does not exist on a given type.
unresolved-module
Source: unresolved_module.rs
This diagnostic is triggered if rust-analyzer is unable to discover referred module.
unresolved-proc-macro
Source: unresolved_proc_macro.rs
This diagnostic is shown when a procedural macro can not be found. This usually means that procedural macro support is simply disabled (and hence is only a weak hint instead of an error), but can also indicate project setup problems.
If you are seeing a lot of "proc macro not expanded" warnings, you can add this option to the
rust-analyzer.diagnostics.disabled
list to prevent them from showing. Alternatively you can
enable support for procedural macros (see rust-analyzer.procMacro.attributes.enable
).
unused-mut
Source: mutability_errors.rs
This diagnostic is triggered when a mutable variable isn't actually mutated.
unused-variables
Source: unused_variables.rs
This diagnostic is triggered when a local variable is not used.