Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the dead_code and unused lints?

What is the difference between

#[allow(dead_code)]
// ...some code

and

#[allow(unused)]
// ...some code
like image 384
109149 Avatar asked Oct 27 '20 14:10

109149


People also ask

How do you turn off unused code warnings in Rust?

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.

What is#[ allow dead_ code)] in Rust?

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.


1 Answers

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
);
like image 69
Shepmaster Avatar answered Oct 23 '22 16:10

Shepmaster