Confusing report for `let guard` borrows of owned values used in match expression
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
- 48/100
Hướng nghiên cứu
Start by reproducing the supplied example with rustc and inspect the borrow-checker diagnostic code that reports E0505, especially how it labels borrows and moves in if let match guards. Compare the current spans with the expected output and check nearby diagnostic tests for similar cases. Done means the diagnostic points to both relevant locations and includes the suggested borrowing help without applying it automatically.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Code
pub fn foo(v: Option<Vec<u8>>) {
match v {
Some(v) if let Some(r) = v.strip_prefix(b"foo ") => {
println!("{:?}", r);
}
_ => ()
}
}
Current output
error[E0505]: cannot move out of `v.0` because it is borrowed
--> src/lib.rs:3:14
|
3 | Some(v) if let Some(r) = v.strip_prefix(b"foo ") => {
| ^
| |
| move out of `v.0` occurs here
| borrow of `v.0` occurs here
4 | println!("{:?}", r);
| - borrow later used here
Desired output
error[E0505]: cannot move out of `v.0` because it is borrowed
--> src/lib.rs:3:14
|
3 | Some(v) if let Some(r) = v.strip_prefix(b"foo ") => {
| ^ ^
| | |
| borrow of `v.0` occurs here move out of `v.0` occurs here
4 | println!("{:?}", r);
| - borrow later used here
help: try borrowing the value here:
| Some(ref v) if let Some(r) = v.strip_prefix(b"foo ") => {
Rationale and extra context
Currently the error is quite opaque and points to entirely the wrong location.
What's doing the borrow is pretty easy to infer but why the value is being moved out is not as easy, especially since having to think about the data flow of patterns has become a lot less routine since match ergonomics.
I would assume before if_let_guard the only (easy?) way to get this error was using at-patterns which mixed moving things and creating overlapping references, then trying to use those references in the expression, which would be why the compiler points everything into the pattern.
The suggestion would not be machine applicable, as there could also be a legitimate borrow error (e.g. the expression tries to use both the owned value and its sub-borrow), in which case the suggestion is incorrect
Rust Version
rustc 1.100.0 (0ef1bc386 2026-11-09)
binary: rustc
commit-hash: 0ef1bc386059596dada8fb65b50425aab2ea637a
commit-date: 2026-11-09
host: x86_64-unknown-linux-gnu
release: 1.100.0
LLVM version: 23.1.5
- Ngôn ngữ chính
- Rust
- Star
- 122k
- Fork
- 16.7k
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 515
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
-
Remove unnecessary parentheses when suggesting to remove '&' from a patternCó thể đã có người làm @BartSimpson001 đã nhận 1 ngày trước. Đang mởA-diagnostics D-invalid-suggestion T-compiler
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows `File::set_permissions` silently does nothing when clearing `readonly` leaves `FileAttributes == 0`Có thể đã có người làm @ChrisDenton đã nhận 11 ngày trước. Đang mởA-filesystem C-bug O-windows T-libs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
rust-lang/rust#165504 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
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 72/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ự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
antithesishq/bombadil#473 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bench/api.sh exec test fails with curl exit 52, and --ignore-failure still records the timingsĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
libracoder/kiri#669 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 5 ngày
-
autofixer: follow-up
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
tursodatabase/turso#12217 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Declare the CMS schema library in the optional recipients extraCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởarea:python in-progress
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
yhay81/pyropdf#1005 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày