# 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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/macro_error.rs#L7) 


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




#### await-outside-of-async

Source:  [await_outside_of_async.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/await_outside_of_async.rs#L3) 


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




#### bad-rtn

Source:  [bad_rtn.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/bad_rtn.rs#L5) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs#L3) 


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




#### cast-to-unsized

Source:  [invalid_cast.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/invalid_cast.rs#L106) 


This diagnostic is triggered when casting to an unsized type




#### elided-lifetimes-in-path

Source:  [elided_lifetimes_in_path.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/elided_lifetimes_in_path.rs#L3) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/expected_function.rs#L5) 


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




#### generic-args-prohibited

Source:  [generic_args_prohibited.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs#L10) 


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




#### inactive-code

Source:  [inactive_code.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/inactive_code.rs#L6) 


This diagnostic is shown for code with inactive `#[cfg]` attributes.




#### incoherent-impl

Source:  [incoherent_impl.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/incoherent_impl.rs#L6) 


This diagnostic is triggered if the targe type of an impl is from a foreign crate.




#### incorrect-generics-len

Source:  [incorrect_generics_len.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/incorrect_generics_len.rs#L4) 


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




#### incorrect-generics-order

Source:  [incorrect_generics_order.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/incorrect_generics_order.rs#L5) 


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




#### incorrect-ident-case

Source:  [incorrect_case.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/incorrect_case.rs#L13) 


This diagnostic is triggered if an item name doesn't follow [Rust naming convention](https://doc.rust-lang.org/1.0.0/style/style/naming/README.html).




#### invalid-cast

Source:  [invalid_cast.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/invalid_cast.rs#L18) 


This diagnostic is triggered if the code contains an illegal cast




#### invalid-derive-target

Source:  [invalid_derive_target.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/invalid_derive_target.rs#L3) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/macro_error.rs#L25) 


This diagnostic is shown for macro expansion errors.




#### macro-error

Source:  [macro_error.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/macro_error.rs#L3) 


This diagnostic is shown for macro expansion errors.




#### malformed-derive

Source:  [malformed_derive.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/malformed_derive.rs#L3) 


This diagnostic is shown when the derive attribute has invalid input.




#### mismatched-arg-count

Source:  [mismatched_arg_count.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs#L32) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs#L11) 


This diagnostic is triggered if a function is invoked with an incorrect amount of arguments.




#### missing-fields

Source:  [missing_fields.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/missing_fields.rs#L25) 


This diagnostic is triggered if record lacks some fields that exist in the corresponding structure.

Example:

```rust
struct A { a: u8, b: u8 }

let a = A { a: 10 };
```




#### missing-lifetime

Source:  [missing_lifetime.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/missing_lifetime.rs#L3) 


This diagnostic is triggered when a lifetime argument is missing.




#### missing-match-arm

Source:  [missing_match_arms.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/missing_match_arms.rs#L3) 


This diagnostic is triggered if `match` block is missing one or more match arms.




#### missing-unsafe

Source:  [missing_unsafe.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/missing_unsafe.rs#L10) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/moved_out_of_ref.rs#L4) 


This diagnostic is triggered on moving non copy things out of references.




#### need-mut

Source:  [mutability_errors.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/mutability_errors.rs#L8) 


This diagnostic is triggered on mutating an immutable variable.




#### no-such-field

Source:  [no_such_field.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/no_such_field.rs#L15) 


This diagnostic is triggered if created structure does not have field provided in record.




#### non-exhaustive-let

Source:  [non_exhaustive_let.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/non_exhaustive_let.rs#L3) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/parenthesized_generic_args_without_fn_trait.rs#L3) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/private_assoc_item.rs#L3) 


This diagnostic is triggered if the referenced associated item is not visible from the current
module.




#### private-field

Source:  [private_field.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/private_field.rs#L10) 


This diagnostic is triggered if the accessed field is not visible from the current module.




#### proc-macro-disabled

Source:  [macro_error.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/macro_error.rs#L11) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/remove_trailing_return.rs#L8) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/remove_unnecessary_else.rs#L17) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs#L11) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/trait_impl_incorrect_safety.rs#L6) 


Diagnoses incorrect safety annotations of trait impls.




#### trait-impl-missing-assoc_item

Source:  [trait_impl_missing_assoc_item.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/trait_impl_missing_assoc_item.rs#L7) 


Diagnoses missing trait items in a trait impl.




#### trait-impl-orphan

Source:  [trait_impl_orphan.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/trait_impl_orphan.rs#L5) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs#L12) 


Diagnoses redundant trait items in a trait impl.




#### type-mismatch

Source:  [type_mismatch.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/type_mismatch.rs#L19) 


This diagnostic is triggered when the type of an expression or pattern does not match
the expected type.




#### typed-hole

Source:  [typed_hole.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/typed_hole.rs#L20) 


This diagnostic is triggered when an underscore expression is used in an invalid position.




#### undeclared-label

Source:  [undeclared_label.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/undeclared_label.rs#L3) 






#### unimplemented-builtin-macro

Source:  [unimplemented_builtin_macro.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unimplemented_builtin_macro.rs#L3) 


This diagnostic is shown for builtin macros which are not yet implemented by rust-analyzer




#### unlinked-file

Source:  [unlinked_file.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unlinked_file.rs#L20) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/useless_braces.rs#L10) 


Diagnostic for unnecessary braces in `use` items.




#### unreachable-label

Source:  [unreachable_label.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unreachable_label.rs#L3) 






#### unresolved-assoc-item

Source:  [unresolved_assoc_item.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unresolved_assoc_item.rs#L3) 


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




#### unresolved-extern-crate

Source:  [unresolved_extern_crate.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs#L3) 


This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate.




#### unresolved-field

Source:  [unresolved_field.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unresolved_field.rs#L21) 


This diagnostic is triggered if a field does not exist on a given type.




#### unresolved-ident

Source:  [unresolved_ident.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unresolved_ident.rs#L3) 


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




#### unresolved-import

Source:  [unresolved_import.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unresolved_import.rs#L3) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs#L3) 


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](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unresolved_method.rs#L16) 


This diagnostic is triggered if a method does not exist on a given type.




#### unresolved-module

Source:  [unresolved_module.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unresolved_module.rs#L8) 


This diagnostic is triggered if rust-analyzer is unable to discover referred module.




#### unused-mut

Source:  [mutability_errors.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/mutability_errors.rs#L63) 


This diagnostic is triggered when a mutable variable isn't actually mutated.




#### unused-variables

Source:  [unused_variables.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-diagnostics/src/handlers/unused_variables.rs#L13) 


This diagnostic is triggered when a local variable is not used.


