Static rustc_lint_defs::builtin::DEAD_CODE

source ·
pub static DEAD_CODE: &Lint
Expand description

The dead_code lint detects unused, unexported items.

§Example

fn foo() {}

{{produces}}

§Explanation

Dead code may signal a mistake or unfinished code. To silence the warning for individual items, prefix the name with an underscore such as _foo. If it was intended to expose the item outside of the crate, consider adding a visibility modifier like pub.

To preserve the numbering of tuple structs with unused fields, change the unused fields to have unit type or use PhantomData.

Otherwise consider removing the unused code.

§Limitations

Removing fields that are only used for side-effects and never read will result in behavioral changes. Examples of this include:

  • If a field’s value performs an action when it is dropped.
  • If a field’s type does not implement an auto trait (e.g. Send, Sync, Unpin).

For side-effects from dropping field values, this lint should be allowed on those fields. For side-effects from containing field types, PhantomData should be used.