What is the difference between
#[allow(dead_code)]
// ...some code
and
#[allow(unused)]
// ...some code
Disable warnings using allow attribute In this method, we have to add the crate-level allow attribute at the beginning of our code to disable warnings. For unused variables, use #![ allow(unused_variables)] and for unused struct or object variables, use #![ allow(dead_code)] at the start of the program.
The compiler provides a dead_code lint that will warn about unused functions. An attribute can be used to disable the lint. fn used_function() {} // `#[allow(dead_code)]` is an attribute that disables the `dead_code` lint.
dead_code
is one specific lint that is defined as:
declare_lint! {
pub DEAD_CODE,
Warn,
"detect unused, unexported items"
}
unused
is a lint group that is composed of dead_code
and many other lints. It is defined as:
add_lint_group!(
"unused",
UNUSED_IMPORTS,
UNUSED_VARIABLES,
UNUSED_ASSIGNMENTS,
DEAD_CODE,
UNUSED_MUT,
UNREACHABLE_CODE,
UNREACHABLE_PATTERNS,
OVERLAPPING_PATTERNS,
UNUSED_MUST_USE,
UNUSED_UNSAFE,
PATH_STATEMENTS,
UNUSED_ATTRIBUTES,
UNUSED_MACROS,
UNUSED_ALLOCATION,
UNUSED_DOC_COMMENTS,
UNUSED_EXTERN_CRATES,
UNUSED_FEATURES,
UNUSED_LABELS,
UNUSED_PARENS,
UNUSED_BRACES,
REDUNDANT_SEMICOLONS
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With