Repository navigation
feat(ts): compare through a held type's own ne, as std's slices, tuples, and Arcs do - #316
Merged
Merged
Conversation
Quest-Claim: 540569525a39f09e
…es, and Arcs do Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ixture's lines Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
October 31, 2026 01:21
This was referenced Oct 31, 2026
Merged
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.
Problem
==of slices, arrays,Vecs, andVecDeques of a crate's type whosePartialEqoverridesnerefused with "through a held type's own", as did!=of a tuple, anArc, or anRcholding one. The runtime'seqSlice,eqTuple, andeqArcwere handed each item'seq, where std calls itsne. A tuple orVecofReverse<T>refused too, though std's derivedReverse::neis!eq.Approach
One lowering function,
not_ne_fn, gives!<T as PartialEq>::ne. It iseq_fnunlessT'snereaches the crate's own:eqTupleof each field's!ne, so it stops at the first field whoseneis true, as std's||chain doesArc/Rc:eqArcof the inner!ne, keeping the pointer shortcut when the inner type isEq!T::neeq_fn's slices,item_eq(which #313'seqSequses forVecDeques and unlike items), and a direct!=all use it.own_neno longer recurses into slice elements orReverse, since std'snefor both is!eq. The runtime is unchanged.Audit of std's
ne(nightly-2026-10-15library/)ne[T] == [U]!eq;eqchecks lengths, then each*lhs != *rhsin ordercore/src/slice/cmp.rs:14-29, 125-136[T; N]spec_ne→a[..] != b[..];[T; N] != [U]→*self != *b, elsetruecore/src/array/equality.rs:5-37, 141-149Vec(andCow<[T]>against aVec)self[..] != other[..]alloc/src/vec/partial_eq.rs:17VecDeque!eq;eqcompares the slices by==alloc/src/collections/vec_deque/mod.rs:3862,macros.rsself.i != other.ijoined by||core/src/tuple.rs:30-36Arc,Rc**self != **other; forT: Eq,!ptr_eq && **self != **otheralloc/src/rcs/arc.rs:3681-3730,rcs/rc.rs:2758-2815BoxPartialEq::ne(&**self, &**other)alloc/src/boxed.rs:2312-2321&A,&mut APartialEq::ne(*self, *other)core/src/cmp.rs:2445-2460, 2520-2625Option!eq;eqis*l == *rcore/src/option.rs:2439-2450Result,Reverse,Wrapping!eqcore/src/result.rs:554,core/src/cmp.rs:696,core/src/num/wrapping.rs:40Cell,RefCell!eqcore/src/cell.rs:349, 1476Cow!eq;eqisPartialEq::eq(&**self, &**other)alloc/src/borrow.rs:385-394peelsees through&,Box, andNonZero, all of which forwardne.Resultlowers from core's MIR.Cell,RefCell,Cow<[T]>, andWrappingrefuse outright before they reach this code (probed separately), so they produce no wrong output; the follow-ups below cover them.Proof
collections::own_nesruns differentially against native wasm32 on 640 inputs: 128 choices of the positions where aPicky'seq(remainder by 4) andne(remainder by 3) disagree, times lengths 0, 1, 2, 4, and 9, with the right side optionally one shorter. Eacheq/necall adds to an ordered log. The case covers slices, arrays,Vecs, empty and unequal lengths, nestedVec<Vec<_>>, tuples (including short-circuiting at the first field and nesting),Option/Reverse/Box/&inside tuples andVecs,Arc/Rcwith and withoutEq(anArc<(Picky, f32)>compares even against itself),Vec<Arc<_>>, and wrappedVecDeques against each other, aVec, and a slice.Mutation check: lowering a tuple's
!=by its fields'eqmakes the differential test fail on 827 inputs.Cost
The runtime didn't change, and neither did any existing generated code: every snapshot change is new output for the new case. A type with no
neof its own still lowers througheq_fnas before, so I didn't run a benchmark.Impact
Alternatives
neTuple/neArctaking each field'sne. I didn't add them:!=is the negation ofeqTuple/eqArcover each part's!ne, with the same short-circuit order, so the existing functions cover it.Follow-ups
==of either refuses as an unsupported call.Review
quest reviewwith Codex (gpt-6.1-sol, medium effort), reviewed head356590f7e96f464526f73ff6f24e54b6f9e31372:d251a247, found one issue: a zip overread ints/src/lower/iter.rs:877. Refuted: that head predated origin/main's feat(ts): fold a zip of TrustedLen iterators by its size hint #314, so the diff made it look reverted. This PR doesn't touchiter.rs, and after merging origin/main,git diff origin/main -- ts/src/lower/iter.rsis empty.356590f7, found nothing.Local
just cipasses on356590f7.(written by Claude Opus 5.5)
🤖 Generated with Claude Code