Closed
Description
struct Foo {
int: i32,
text: String,
}
fn foo(foo: &Foo) {
match *foo {
Foo { int, text: ref text } => {
println!("{:?}, {:?}", int, text);
}
}
}
This code gives incorrect warning:
warning: the `text:` in this pattern is redundant
--> src/lib.rs:8:24
|
8 | Foo { int, text: ref text } => {
| -----^^^^^^^^^
| |
| help: remove this
|
= note: `#[warn(non_shorthand_field_patterns)]` on by default
The suggested fix makes text
move, which is impossible since foo
is borrowed.
Using auto borrowing with match foo
instead of match *foo
would make all fields borrowed, but I want most of them moved (copied).
Metadata
Metadata
Assignees
Labels
Area: Lints (warnings about flaws in source code) such as unused_mut.Area: Suggestions generated by the compiler applied by `cargo fix`Category: This is a bug.Diagnostics: A structured suggestion resulting in incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.