`unused_variables` warns on a binding used only as `..base` when every field is given, and the `_` prefix it suggests leaves `..base` unresolved (E0425)
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
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ả
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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/rust
-
strictly_dominates missing a `=`Đang mởC-bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
rust-lang/rust#166722 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A-attributes relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-lang
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
A-run-make C-bug T-bootstrap
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Tracking issue for release notes of #161531: Remove `T: Send + Sync` bound from `Arc::downcast`Đang mởrelnotes relnotes-tracking-issue T-libs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
A-str A-Unicode relnotes relnotes-tracking-issue T-libs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rust-lang/rust
Issue tương tự
-
bug P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows microphone listing treats words in a device name as DirectShow labelsCó thể đã có người làm @Sujal-chaudhary đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
clipy-recorder/clipy#447 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
nightly-cleanup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
max-sixty/worktrunk#4939 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursĐang mởflaky
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
stacks-network/stacks-core#7918 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày