## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# 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"`.

#### attribute-expansion-disabled

Source: macro_error.rs

This diagnostic is shown for attribute proc macros when attribute expansions have been disabled.

#### await-outside-of-async

Source: await_outside_of_async.rs

This diagnostic is triggered if the `await` keyword is used outside of an async function or block

#### bad-rtn

Source: bad_rtn.rs

This diagnostic is shown when a RTN (Return Type Notation, `Type::method(..): Send`) is written in an improper place.

#### break-outside-of-loop

Source: break_outside_of_loop.rs

This diagnostic is triggered if the `break` keyword is used outside of a loop.

#### cast-to-unsized

Source: invalid_cast.rs

This diagnostic is triggered when casting to an unsized type

#### elided-lifetimes-in-path

Source: elided_lifetimes_in_path.rs

This diagnostic is triggered when lifetimes are elided in paths. It is a lint only for some cases, and a hard error for others.

#### expected-function

Source: expected_function.rs

This diagnostic is triggered if a call is made on something that is not callable.

#### generic-args-prohibited

Source: generic_args_prohibited.rs

This diagnostic is shown when generic arguments are provided for a type that does not accept generic arguments.

#### 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-generics-len

Source: incorrect_generics_len.rs

This diagnostic is triggered if the number of generic arguments does not match their declaration.

#### incorrect-generics-order

Source: incorrect_generics_order.rs

This diagnostic is triggered the order of provided generic arguments does not match their declaration.

#### incorrect-ident-case

Source: incorrect_case.rs

This diagnostic is triggered if an item name doesn’t follow Rust naming convention.

#### invalid-cast

Source: invalid_cast.rs

This diagnostic is triggered if the code contains an illegal cast

#### 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-def-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-lifetime

Source: missing_lifetime.rs

This diagnostic is triggered when a lifetime argument is missing.

#### 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.

#### non-exhaustive-let

Source: non_exhaustive_let.rs

This diagnostic is triggered if a `let` statement without an `else` branch has a non-exhaustive pattern.

#### parenthesized-generic-args-without-fn-trait

Source: parenthesized_generic_args_without_fn_trait.rs

This diagnostic is shown when a `Fn`-trait-style generic parameters (`Trait(A, B) -> C`) was used on non-`Fn` trait/type.

#### 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.

#### proc-macro-disabled

Source: macro_error.rs

This diagnostic is shown for proc macros that have been specifically disabled via `rust-analyzer.procMacro.ignored`.

#### remove-trailing-return

Source: remove_trailing_return.rs

This diagnostic is triggered when there is a redundant `return` at the end of a function or closure.

#### remove-unnecessary-else

Source: remove_unnecessary_else.rs

This diagnostic is triggered when there is an `else` block for an `if` expression whose then branch diverges (e.g. ends with a `return`, `continue`, `break` e.t.c).

#### 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(..)`.

#### trait-impl-incorrect-safety

Source: trait_impl_incorrect_safety.rs

Diagnoses incorrect safety annotations of trait impls.

#### trait-impl-missing-assoc_item

Source: trait_impl_missing_assoc_item.rs

Diagnoses missing trait items in a trait impl.

#### trait-impl-orphan

Source: trait_impl_orphan.rs

Only traits defined in the current crate can be implemented for arbitrary types

#### trait-impl-redundant-assoc_item

Source: trait_impl_redundant_assoc_item.rs

Diagnoses redundant trait items in a trait impl.

#### 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-assoc-item

Source: unresolved_assoc_item.rs

This diagnostic is triggered if the referenced associated item does not exist.

#### 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-ident

Source: unresolved_ident.rs

This diagnostic is triggered if an expr-position ident is invalid.

#### 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.

#### 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.