oxc-project/oxc · warning · OxcDiagnostic

{pronoun} '{name}' is assigned a value but never used.{suffi

Error message

{pronoun} '{name}' is assigned a value but never used.{suffix}

What it means

no-unused-vars dead-store message: a value is assigned to an already-declared variable and that particular value is never read afterward (it is overwritten first, or its scope/function ends). Distinct from 'never used': the variable exists, but this stored value is wasted. Two labels point at the declaration and at the dead assignment.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_unused_vars/diagnostic.rs:101

    })
    .with_label(symbol.span().label(format!("'{name}' is declared here")))
    .with_help(help)
}

/// Variable 'x' is assigned a value but never used.
pub fn assign<R>(
    symbol: &Symbol<'_, '_>,
    assign_span: Span,
    pat: &IgnorePattern<R>,
) -> OxcDiagnostic
where
    R: fmt::Display,
{
    let name = symbol.name();
    let (pronoun, pronoun_plural) = pronoun_for_symbol(symbol.flags());
    let suffix = pat.diagnostic_help(pronoun_plural);

    OxcDiagnostic::warn(format!("{pronoun} '{name}' is assigned a value but never used.{suffix}"))
        .with_labels([
            symbol.span().label(format!("'{name}' is declared here")),
            assign_span.label("it was last assigned here"),
        ])
        .with_help("Did you mean to use this variable?")
}

/// Parameter 'x' is declared but never used.
pub fn param<R>(
    symbol: &Symbol<'_, '_>,
    pat: &IgnorePattern<R>,
    only_used_as_type: bool,
) -> OxcDiagnostic
where
    R: fmt::Display,
{
    let name = symbol.name();
    let suffix = if name == "_" && pat.is_default() {

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Delete the assignment whose stored value is never read.
  2. Hoist to a single const at the point of first use.
  3. If the right-hand side has needed side effects, keep the call but discard its result deliberately and visibly.

Example fix

// before
let total;
total = computeBase();
total = computeBase() + extra;
use(total);
// after
const total = computeBase() + extra;
use(total);
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: let x = 1; x = compute(); use(x); where the first store is dead; an assignment immediately before a return/throw that never reads it; assignments in a branch that then exits without merging.

Common situations: Accumulator variables rebuilt by wholesale reassignment; initialization 'just in case'; assignments left behind after the last consumer was removed.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/8fca36b1d88d3839. Report an issue: GitHub.