Repository navigation
Conversation
lucic71
marked this pull request as draft
October 16, 2026 14:19
lucic71
marked this pull request as ready for review
October 16, 2026 18:37
This branch has not been deployed
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.
Closes #539.
A rule for a container iterator such as
std::vector<T, A>::iteratorcannot match a usage, becauseTandAcannot be deduced from the iterator type (see #539).This PR matches iterator types by their iterator category instead. The category is read from
std::iterator_traits<It>, which every standard iterator provides, so the rules do not depend on how a particular standard library implements its iterators.This also removes duplicate rules. One rule for random access iterators replaces one rule per container that has a random access iterator.
rules/iterator_category/shim.rsdefines the Rust types for the iterator categories used in translated code: iterator, input, output, bidirectional, and random access.
rules/iterator_category/src.cppdefines a type rule for each category plus rules for its operations.For example, this is the rule for an iterator that is bidirectional but not random access:
Itis deduced directly from the usage, andT1and theenable_ifcondition are computed from it using only standard names. This rule matchesstd::map<K, V>::iterator,std::set<T>::iterator,std::list<T>::iterator, and so on, without naming any of them.The existing vector and map iterator rules are rewritten in terms of
RandomAccessIteratorandBidirectionalIterator.RandomAccessIterator<T>is aPtr<T>, which is what vector iterators already translated to, so the change is small.RefcountMapIterandUnsafeMapIteratorwereMapIter<K, MapRef>, which has two type parameters. A category rule only knowsT, the iterator'svalue_type, which for a map isstd::pair<const K, V>. The Rust iterator type therefore has to depend onTalone. The new map iterator is built onMapNode<T>. The map itself still owns aBTreeMap.The converter special cases for map iterators (
GetStrongestIteratorCategory,PushSuppressIteratorClone, and theVec</BTreeMap<checks inRecordHasCopyableFields) are removed, since the rules now handle these types.Function rules that take the container as an argument already work, even when they also spell a container member type. For example
std::map::erase:std::map<T1, T2>::const_iteratoris still a non-deduced context, but that does not matter here:T1andT2are deduced from the first parametero, and Clang then substitutes them into the second parameter. Deduction only fails when the iterator is the only place the template parameters appear, as in the type ruleusing t = typename std::map<T1, T2>::iterator;. Those are the rules this PR replaces.