Content-Length: 13924 | pFad | https://doc.rust-lang.org/std/pin/../hash/../../std/sync/../../../std/../error_codes/./E0009.html

E0009 - Error codes index

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error code E0009

Note: this error code is no longer emitted by the compiler.

In a pattern, all values that don't implement the Copy trait have to be bound the same way. The goal here is to avoid binding simultaneously by-move and by-ref.

This limitation may be removed in a future version of Rust.

Erroneous code example:

#![allow(unused)]
#![feature(move_ref_pattern)]

fn main() {
struct X { x: (), }

let x = Some((X { x: () }, X { x: () }));
match x {
    Some((y, ref z)) => {}, // error: cannot bind by-move and by-ref in the
                            //        same pattern
    None => panic!()
}
}

You have two solutions:

Solution #1: Bind the pattern's values the same way.

#![allow(unused)]
fn main() {
struct X { x: (), }

let x = Some((X { x: () }, X { x: () }));
match x {
    Some((ref y, ref z)) => {},
    // or Some((y, z)) => {}
    None => panic!()
}
}

Solution #2: Implement the Copy trait for the X structure.

However, please keep in mind that the first solution should be preferred.

#![allow(unused)]
fn main() {
#[derive(Clone, Copy)]
struct X { x: (), }

let x = Some((X { x: () }, X { x: () }));
match x {
    Some((y, ref z)) => {},
    None => panic!()
}
}








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/std/pin/../hash/../../std/sync/../../../std/../error_codes/./E0009.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy