`unused_variables` warns on a binding used only as `..base` when every field is given, and the `_` prefix it suggests leaves `..base` unresolved (E0425)

Abierto
#166,652 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
54/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
compilers

Línea de trabajo

The report points to the unused_variables lint moving to MIR in #142390 and includes a repro.sh script that runs cargo check and cargo fix on a copy of the example crate. Start by running the reproduction and tracing how struct update bases are counted as uses and how the lint suggestion renames bindings. Done means cargo fix no longer produces E0425 for this case, with the partial struct update behavior preserved.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

A-lints A-suggestion-diagnostics C-bug D-invalid-suggestion I-prioritize L-false-positive L-unused_variables regression-from-stable-to-stable S-has-mcve T-compiler
Code

I tried this code (lib.rs of a library crate, edition 2024):

#[derive(Clone, Copy)]
pub struct Margins {
    pub top: i32,
    pub left: i32,
}

pub fn changed(margins: Margins, change: impl Fn(Margins) -> Margins) -> Margins {
    change(margins)
}

pub fn reset(margins: Margins) -> Margins {
    changed(margins, |group| Margins { top: 0, left: 0, ..group })
}

The crate and repro.sh, a script that runs cargo check and then cargo fix --allow-no-vcs on a copy of it, are in a gist: https://gist.github.com/YevheniiKotyrlo/a435bd0806dbf257f4a8375608bf3895

git clone https://gist.github.com/a435bd0806dbf257f4a8375608bf3895.git struct-update-base
cd struct-update-base
bash repro.sh

bash repro.sh exits 1 while cargo fix fails with E0425, 0 once rustc no longer warns or the fix leaves a crate that builds, and 2 otherwise.

I expected to see this happen: no unused_variables warning on group, since ..group names it; or, if the warning stays, a suggestion whose result compiles, renaming the ..group use too or removing the base.

Instead, this happened: cargo check warns

warning: unused variable: `group`
  --> lib.rs:12:23
   |
12 |     changed(margins, |group| Margins { top: 0, left: 0, ..group })
   |                       ^^^^^ help: if this is intentional, prefix it with an underscore: `_group`
   |
   = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

and cargo fix --allow-no-vcs applies the suggestion, gets E0425 and backs it out:

error: errors present after applying fixes to crate `struct_update_base_probe`
 --> lib.rs
  = cause: error[E0425]: cannot find value `group` in this scope
             --> lib.rs:12:60
              |
           12 |     changed(margins, |_group| Margins { top: 0, left: 0, ..group })
              |                                                            ^^^^^ not found in this scope
[…]
           error: aborting due to 1 previous error

A function parameter and a let binding used only as such a base get the same warning and suggestion; a base that still gives a field gets none:

pub fn parameter(group: Margins) -> Margins {
    Margins { top: 0, left: 0, ..group } // warns at `group: Margins`
}

pub fn local(margins: Margins) -> Margins {
    let group = margins;
    Margins { top: 0, left: 0, ..group } // warns at `let group`
}

pub fn partial(margins: Margins) -> Margins {
    let group = margins;
    Margins { top: 0, ..group } // no warning
}
Version it worked on

It most recently worked on: Rust 1.91.0 (rustc 1.91.0 (f8297e351 2025-10-28)), where cargo check gives no warning. 1.92.0 is the first release with it, which fits unused_variables moving to MIR in #142390.

Version with regression

rustc --version --verbose:

rustc 1.100.0 (0ef1bc386 2026-11-09)
binary: rustc
commit-hash: 0ef1bc386059596dada8fb65b50425aab2ea637a
commit-date: 2026-11-09
host: x86_64-pc-windows-msvc
release: 1.100.0
LLVM version: 23.1.5

1.92.0 (rustc 1.92.0 (ded5c06cf 2025-12-08)) and nightly-2026-11-28 (rustc 1.102.0-nightly (c82ce1563 2026-11-27)) give the same warning and the same E0425.

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

Lenguaje dominante
Rust
Estrellas
123k
Forks
16.6k
Merge medio
2 d 17 h
PR fusionados (30 d)
532

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/rust

Todos los issues de rust-lang/rust

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.