Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new clippy warnings from Rust 1.84 #13645

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mtreinish
Copy link
Member

Summary

The recently release Rust 1.84 introduced some new clippy rules that are triggering warnings in the Qiskit rust code. This commit fixes these warnings as the point to real issues most of the time. However in this release a bunch of the warnings are coming from a pyo3 macro that internally had logic for a feature flag that only exists in pyo3. I think this is likely a rule bug in clippy, but in the meantime adding a gil-refs feature to the qiskit crates to match the feature pyo3 is using silences the warnings.

Details and comments

The recently release Rust 1.84 introduced some new clippy rules that are
triggering warnings in the Qiskit rust code. This commit fixes these
warnings as the point to real issues most of the time. However in this
release a bunch of the warnings are coming from a pyo3 macro that
internally had logic for a feature flag that only exists in pyo3. I
think this is likely a rule bug in clippy, but in the meantime adding a
gil-refs feature to the qiskit crates to match the feature pyo3 is using
silences the warnings.
@mtreinish mtreinish added type: qa Issues and PRs that relate to testing and code quality Changelog: None Do not include in changelog Rust This PR or issue is related to Rust code in the repository labels Jan 9, 2025
@mtreinish mtreinish requested a review from a team as a code owner January 9, 2025 21:03
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

})
.all(|ok_to_remove| ok_to_remove);
if remove_s {
let mut successors = dag.quantum_successors(predecessor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come successors is mut now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It failed to compile if I didn't change it :) It looks like it's because .all() takes a mutable reference to self. It wasn't an issue before because the Map returned by the .map() call before was owned.

The error was:

error[E0596]: cannot borrow `successors` as mutable, as it is not declared as mutable
  --> crates/accelerate/src/remove_diagonal_gates_before_measure.rs:70:32
   |
70 | ...                   if successors.all(|s| {
   |                          ^^^^^^^^^^ cannot borrow as mutable
   |
help: consider changing this to be mutable
   |
69 |                             let mut successors = dag.quantum_successors(predecessor);
   |                                 +++

For more information about this error, try `rustc --explain E0596`.
error: could not compile `qiskit-accelerate` (lib) due to 1 previous error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see - I was wondering how it could have compiled before. It's subtle: Iterator::map takes ownership, and you don't have to mark something mut to be able to transfer its ownership. Iterator::all "only" takes a mutable reference, so it was weird to me that you need mut when actually you're now using less permissions on the object, but really that assumption was a faulty abstraction in my head.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this PR required more of successors, but actually it doesn't.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 12698421954

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • 20 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.009%) to 88.924%

Files with Coverage Reduction New Missed Lines %
crates/circuit/src/converters.rs 1 95.65%
crates/accelerate/src/sabre/heuristic.rs 1 32.87%
crates/accelerate/src/basis/basis_translator/mod.rs 1 87.44%
crates/accelerate/src/sabre/mod.rs 2 75.44%
crates/qasm2/src/lex.rs 3 92.48%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 12687984222: -0.009%
Covered Lines: 79425
Relevant Lines: 89318

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to merge as-is, or file a bug against PyO3 / cargo and wait?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog Rust This PR or issue is related to Rust code in the repository type: qa Issues and PRs that relate to testing and code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants