Skip to content

Unhelpful (incorrect?) match_default_bindings hint #45925

Closed
@mark-i-m

Description

@mark-i-m

Here is the whole error output:

error: non-reference pattern used to match a reference (see issue #42640)
   --> src/coord.rs:194:23
    |
194 |             .filter(|&(ref k, _)| self.hash(k) == server)
    |                       ^^^^^^^^^^ help: consider using: `&(ref k, _)`
    |
    = help: add #![feature(match_default_bindings)] to the crate attributes to enable

error: aborting due to previous error

error: Could not compile `kv_2pc`.

To learn more, run the command again with --verbose.

Specifically, notice the hint:

help: consider using: `&(ref k, _)`

which suggests doing something I am already doing 😛 ...

The code snippet in question:

    fn send_prepare(&self, server: &str, txn: TxnId, staged: &Vec<(String, String)>) -> Flags {
        // Only send to the server the items on that server!
        let mut staged = staged
            .iter()
            .filter(|&(ref k, _)| self.hash(k) == server)
            .collect();

        retry_forever!{
            do {
                //     SendToServer(s, {Prepare})
                let server = SyncClient::connect(server, client::Options::default()).unwrap();
                server.send_to_server(txn, Flags::PREPARE, Some(staged.clone()))
            },

            retry if Err(tarpc::Error::Io(_)),

            match {
                Ok(flags) => flags,
                err => panic!("Error with (de)serialization: {:?}", err)
            }
        }
    }

Changing .filter(|&(ref k, _)| self.hash(k) == server) to .filter(|pair| self.hash(&pair.0) == server) sidesteps the problem.

$ rustc --version --verbose
rustc 1.23.0-nightly (a35a3abcd 2017-11-10)
binary: rustc
commit-hash: a35a3abcda67a729edbb7d649dbc663c6feabd4c
commit-date: 2017-11-10
host: x86_64-unknown-linux-gnu
release: 1.23.0-nightly
LLVM version: 4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions