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

Đang mở
#166,652 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
54/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Rust
Star
123k
Fork
16.6k
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
532

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/rust

Tất cả issue của rust-lang/rust

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.