Backports for 0.29.3 - #6353
Open
felipebalbi wants to merge 1 commit into
Open
Conversation
…`Copy` classes (PyO3#6309) * fix `clippy::clone_on_copy` firing on `#[pyclass(from_py_object)]` + `Copy` classes Move the clone out of the generated `FromPyObject` impl into a generic helper where the type is only known to be `Clone`, so the lint cannot trigger. Fixes PyO3#6308. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * bless UI test snapshot for trimmed `FromPyObject` diagnostic paths The generated `extract` body no longer references `FromPyObject` items inline, which changes how rustc renders the trait path in unrelated diagnostics in the same crate. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * bless `default` revision UI test snapshot as well Same trimmed-path diagnostic drift as the `inspect` revision; this snapshot only runs without `experimental-inspect` enabled. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit 1914ce3)
felipebalbi
marked this pull request as ready for review
August 26, 2026 16:26
Hooray! CodSpeed harness just leveled up!The base and head of this comparison were measured with different runner settings, so their benchmark values are not directly comparable. What changed between base and head:
Re-run the base with the same settings to get a valid performance comparison. Comparing Footnotes |
32 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running list of things to backport for a 0.29.3:
clippy::clone_on_copyfiring on#[pyclass(from_py_object)]+Copyclasses #6309#6309 fixed #6308 (
clippy::clone_on_copyfiring on theFromPyObjectimplgenerated for
#[pyclass(from_py_object)]types that are alsoCopy). It mergedto
mainon 2026-08-08, three days after 0.29.2 shipped, so it isn't in anyrelease and
release-0.29doesn't have it.Why this might be worth a patch release
When #6308 was filed the lint was nightly-only. It is now in beta: I reproduced
it on
1.99.0-beta.1, which promotes to stable on 2026-10-01. At that point anycrate that puts
#[pyclass(from_py_object)]on aCopytype and runscargo clippy -- -D warningsin CI starts failing. Confirmed affected on thecurrent release (0.29.2, from crates.io), not just older 0.29.x.
Known affected downstreams: pyca/cryptography (the original report) and
OpenDevicePartnership/pico-de-gallo.
I appreciate 0.30 may not be far off. If it is likely to land before 2026-10-01
then this probably isn't worth a patch release, and I'm happy to close this.
The backport
Both source hunks cherry-picked cleanly and are byte-identical to #6309 --
PyClassGuard,PyClassGuardErrorandFromPyObjectall already exist onrelease-0.29, soextract_pyclass_with_clonecompiles there unchanged. Theregression test from #6309 (
CopyonMyEnumintests/test_enum.rs) cameacross too.
The only conflicts were
tests/ui/invalid_pyclass_args.{default,inspect}.stderr,and they conflicted on unrelated divergence between
mainandrelease-0.29rather than on this fix. I did not hand-merge them: I reset both to the
release-0.29baseline and regenerated withUI_TEST=blessacross all threefeature combos from
nox -s update-ui-tests. The result is 6 lines, allpyo3::FromPyObject->FromPyObject, which is just rustc shortening thediagnostic path now that
FromPyObjectis imported insrc/impl_/pyclass.rs.Nothing semantic.
Verified locally on 1.98.0 stable and 1.99.0-beta.1:
exactly the expected file -- so these snapshots are not platform-sensitive here.
macros,full,abi3,full.cargo test --test test_enum --features full: 24 passed.test_enum: clean. Reverting just the macro one-liner bringsback
using 'clone' on type 'MyEnum' which implements the 'Copy' trait, so theregression test is doing real work.
cargo fmt --all --check: clean.Two CI notes
The
changelogcheck will fail. The newsfragment is6309.fixed.md, keeping theoriginal PR number so the entry reads correctly in the 0.29.3 notes, but
check-changeloglooks for a fragment named after this PR. Happy to rename it,add a second one, or you can apply
CI-skip-changelog-- whichever you prefer.Beta clippy also flags
clippy::nonnull_unchecked_on_box_ptrinsrc/internal_tricks.rs:56on this branch. That is pre-existing onrelease-0.29and unrelated to this backport; noting it only so it isn'tattributed to this change. The
clippy/betajob iscontinue-on-error, so itshould not block.
Disclosure per Contributing.md: I used AI assistance to locate the upstream fix,
perform the cherry-pick, and run the verification above. The code is an
unmodified cherry-pick of #6309 with the UI snapshots regenerated by the
project's own bless tooling; authorship on the commit is preserved as
@alex via
cherry-pick -x.