Confusing report for `let guard` borrows of owned values used in match expression
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
- 48/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Rust
- Estrellas
- 122k
- Forks
- 16.7k
- Merge medio
- 2 d 16 h
- PR fusionados (30 d)
- 515
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-lang/rust
-
Remove unnecessary parentheses when suggesting to remove '&' from a patternPosiblemente ocupada @BartSimpson001 la tomó hace 1 día. AbiertoA-diagnostics D-invalid-suggestion T-compiler
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Windows `File::set_permissions` silently does nothing when clearing `readonly` leaves `FileAttributes == 0`Posiblemente ocupada @ChrisDenton la tomó hace 11 días. AbiertoA-filesystem C-bug O-windows T-libs
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
rust-lang/rust#165504 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
relnotes relnotes-tracking-issue T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
Todos los issues de rust-lang/rust
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
antithesishq/bombadil#473 ·
Los mantenedores suelen responder en 2 días
-
bench/api.sh exec test fails with curl exit 52, and --ignore-failure still records the timingsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
libracoder/kiri#669 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 5 días
-
autofixer: follow-up
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
tursodatabase/turso#12217 ·
Los mantenedores suelen responder en 1 día
-
Declare the CMS schema library in the optional recipients extraPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoarea:python in-progress
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
yhay81/pyropdf#1005 · 2 comentarios ·
Los mantenedores suelen responder en 1 día