Repository navigation
feat(ts): call a crate's own collect, eq, partial_cmp, by_ref, and is_sorted_by where std does - #513
Merged
Merged
Conversation
Quest-Claim: 3eefa34bae3e9543
…_sorted_by where std does std's FromIterator of Box<[T]>, Rc<[T]>, Arc<[T]>, BTreeMap, BTreeSet, and BinaryHeap now calls the crate's own collect into a Vec first. Iterator's ne, lt, le, gt, and ge join library::Inherited, so they call eq and partial_cmp as resolved: the crate's override, or std's mapping, which drops rt.iterLt, iterLe, iterGt, and iterGe. by_ref is lifted, as only Vec::splice calls it in std. is_sorted_by joins rt.Own like all, so is_sorted calls it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tself Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. CodeRabbit Verify
|
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
rust2-ts refused a crate's own iterator that overrides
collect,eq,partial_cmp,by_ref, oris_sorted_by, as "overriding_, which std calls in place of another method". These are stable, provided methods a crate can override, and std calls each in place of another:FromIteratorofBox<[T]>,Rc<[T]>,Arc<[T]>,BTreeMap,BTreeSet, andBinaryHeapcalls the iterator'scollect::<Vec<_>>()first.necallseq, andlt,le,gt, andgecallpartial_cmp.Vec::splicecallsby_refas it drops.is_sortedcallsis_sorted_by. feat(ts): call a crate's own find, rfind, find_map, for_each, reduce, and all where std does #501 missed this one, and it is the last stable override std calls in place of another, apart from adaptor constructors such asmap.Finishes
quest/m3/ts-iter-own-calls.md. Consumer: theendsfixture now, and any crate whose iterator overrides these.Approach
eqandpartial_cmp: Iterator'sne,lt,le,gt, andgejoinlibrary::Inherited, the pathPartialEq::neandPartialOrd::ltalready take. Each calls the trait'seqorpartial_cmpwith the same generic arguments, which resolves to the crate's override where there is one, and else to std's mapping.rt.iterLt,iterLe,iterGt, anditerGeare deleted, andcompareno longer handlesne.collect:own_collectcalls the crate'scollect::<Vec<T>>instance where std'sFromIteratorof one of those six collections does, then collects from thatVec'sinto_iter. That is identical, since aVec's owncollectfrom itsinto_iteris in place. It applies only to the crate's type itself:&mut IandBox<I>collect by the default, which never calls the crate's.by_ref: the refusal is lifted. std calls it only fromVec::splice, which has no translation, so only the crate's own calls reach it, and those resolve to its override.is_sorted_by: joinsrt.Ownasalldid in feat(ts): call a crate's own find, rfind, find_map, for_each, reduce, and all where std does #501. It is translated once for aBox<dyn FnMut(&T, &T) -> bool>, checked byerases, andrt.iterIsSortedBycalls it by value where std'sis_sorteddoes. One with[u8; N]items stays refused, asfindandrfinddo.Tests: the
endsfixture'sOverridesgains loggedcollect,eq,partial_cmp,by_ref, andis_sorted_by, each reading from the back so a missed call changes the result. A genericPairsadaptor gains a loggedcollect, soBTreeMapis covered. A newcollectedruns every std caller by value, through&mut, and boxed (where neither forwards), and on the plainRunas a control. That is 4 new kinds, for 157,865 cases against native, with no differences. Mutations that skipown_collector theisSortedBydispatch produce 2434 and 128 differences.Impact
rt.iterLt,iterLe,iterGt, anditerGe, which only generated code called. Generated code for an iterator'sltand the others now testsrt.iterCmpinline, as a struct'sltalready does.mapis still refused; the reject fixture'sCollectscase becomesMaps. The[u8; N]refusal now says "closure" rather than "predicate", since it coversis_sorted_bytoo.Alternatives
collect's callers instead of the list of six: it would have to followRcandArc'sToRcSlicespecialization two levels deep. The list is short, cited from std, and complete for stable std.rt.iterLtand the others, and special-casing the crate's override: that adds a branch whereInheritedalready says what std does.Follow-ups
None. With this, the only overrides std calls in place of another that stay refused are adaptor constructors, which can't return without diverging, and nightly-only ones such as
try_fold.Review
quest review, Codexgpt-6.1-solat medium effort, round 3 on head a8c42b9 against base 3025d04: 0 findings.Round 2 on aa7247f had 1 finding:
ts/src/lower/iter.rs(Rc and Arc slices from aTrustedLeniterator): fixed in a8c42b9.own_collectskips them, as std'sToRcSlice/ToArcSlicespecialization reads the iterator itself. No differential case:TrustedLenis#[unstable(feature = "trusted_len")], so no stock crate's own iterator implements it.just cipassed on a8c42b9.Choices made without asking
is_sorted_byis in scope, though the quest named onlycollect,eq,partial_cmp, andby_ref. It is the same problem, the last stable instance of it, and AGENTS.md asks for every instance in one PR.🤖 Generated with Claude Code