From c062dd6cf22558f630903d530728f2e1b60dacc3 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 6 May 2024 15:08:19 -0400 Subject: [PATCH] Fix Rustfmt and clippy with latest rust stable (#12339) * Fix Rustfmt and clippy with latest rust stable Running `cargo fmt` with a newer version of rust than what we use in CI (1.77.2 and 1.78.0 locally for me) is triggering the formatting updates in this commit. To ensure developers don't have to worry about commiting an accidental formatting change in their commits this commit proactively makes the change. Similarly the recent Rust 1.78 release included new clippy rules which are flagging some small issues that our MSRV of clippy doesn't have. This commit also fixes these as the suggestions are good and are compatible with our MSRV of 1.70. * Rename deprecated config file name * Remove dead code --- .cargo/{config => config.toml} | 0 crates/accelerate/src/sparse_pauli_op.rs | 4 +++- crates/circuit/src/circuit_data.rs | 2 +- crates/qasm3/src/circuit.rs | 10 ---------- 4 files changed, 4 insertions(+), 12 deletions(-) rename .cargo/{config => config.toml} (100%) diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml diff --git a/crates/accelerate/src/sparse_pauli_op.rs b/crates/accelerate/src/sparse_pauli_op.rs index 5d6a82df7940..808269d8ab90 100644 --- a/crates/accelerate/src/sparse_pauli_op.rs +++ b/crates/accelerate/src/sparse_pauli_op.rs @@ -141,7 +141,9 @@ impl ZXPaulis { phases: &Bound>, coeffs: &Bound>, ) -> PyResult { - let &[num_ops, num_qubits] = x.shape() else { unreachable!("PyArray2 must be 2D") }; + let &[num_ops, num_qubits] = x.shape() else { + unreachable!("PyArray2 must be 2D") + }; if z.shape() != [num_ops, num_qubits] { return Err(PyValueError::new_err(format!( "'x' and 'z' have different shapes: {:?} and {:?}", diff --git a/crates/circuit/src/circuit_data.rs b/crates/circuit/src/circuit_data.rs index 590fc07e8f8b..944565cf36d8 100644 --- a/crates/circuit/src/circuit_data.rs +++ b/crates/circuit/src/circuit_data.rs @@ -324,7 +324,7 @@ impl CircuitData { 0, )?; res.intern_context = self.intern_context.clone(); - res.data = self.data.clone(); + res.data.clone_from(&self.data); Ok(res) } diff --git a/crates/qasm3/src/circuit.rs b/crates/qasm3/src/circuit.rs index 747980819a0e..330805fa2f86 100644 --- a/crates/qasm3/src/circuit.rs +++ b/crates/qasm3/src/circuit.rs @@ -16,7 +16,6 @@ use pyo3::types::{PyList, PyString, PyTuple, PyType}; use crate::error::QASM3ImporterError; pub trait PyRegister { - fn bit(&self, py: Python, index: usize) -> PyResult>; // This really should be // fn iter<'a>(&'a self, py: Python<'a>) -> impl Iterator; // or at a minimum @@ -39,15 +38,6 @@ macro_rules! register_type { } impl PyRegister for $name { - /// Get an individual bit from the register. - fn bit(&self, py: Python, index: usize) -> PyResult> { - // Unfortunately, `PyList::get_item_unchecked` isn't usable with the stable ABI. - self.items - .bind(py) - .get_item(index) - .map(|item| item.into_py(py)) - } - fn bit_list<'a>(&'a self, py: Python<'a>) -> &Bound<'a, PyList> { self.items.bind(py) }