From 4d83c653a6069cf103799e378d992c0f1fa275b7 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:19:49 -0700 Subject: [PATCH 01/11] chore(quest): claim quest/m1/ffi-export/iterators.md Quest-Claim: 26762d13f0d22e31 From c943c81be526ccdea2cf617202f01f7ed0de3a34 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:31:42 -0700 Subject: [PATCH 02/11] feat(ffi): return another crate's iterator as the array of its items Co-Authored-By: Claude Opus 5.5 --- ffi/README.md | 3 +- ffi/fixtures/api/examples/transcript.rs | 17 +++++++ ffi/fixtures/api/src/lib.rs | 25 +++++++++ ffi/fixtures/reject/expected.txt | 6 +++ ffi/fixtures/reject/src/lib.rs | 30 +++++++++++ ffi/moq/ffi.toml | 5 +- ffi/src/collect.rs | 68 +++++++++++++++++++++---- ffi/src/glue.rs | 7 ++- ffi/src/ir.rs | 3 ++ ffi/tests/api.c | 42 +++++++++++++++ ffi/tests/api.cpp | 32 ++++++++++++ ffi/tests/api.kt | 6 +++ quest/m1/ffi-export/README.md | 1 - quest/m1/ffi-export/iterators.md | 21 -------- 14 files changed, 228 insertions(+), 38 deletions(-) delete mode 100644 quest/m1/ffi-export/iterators.md diff --git a/ffi/README.md b/ffi/README.md index 95d96f840..5a6d580b2 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -45,7 +45,7 @@ exclude = ["track::Producer::poll_closed"] # Another package exported into the same library, which the package builds with: its # own `exclude` and `rename`, by paths from its crate root. [crates.moq-pattern] -exclude = ["Patterns::iter"] +exclude = ["Pattern::new"] ``` ## Rules @@ -77,6 +77,7 @@ export's, and adds nothing; another crate's type is refused. | `SocketAddr`, `SocketAddrV4`, `SocketAddrV6` | `_socket_addr`: its IP's bytes, port, and whether it is IPv6; one of the other family passed to `V4` or `V6` aborts | | `url::Url` | an object `_url`, made by `_url_parse`, which fails with the parse error's message, and printed by `_to_string` | | `Vec` and `&[T]` of any other `T` | `_vec_`: an array of `T`'s C values, viewed passed in and owned returned, a slice as a clone; of references only returned | +| a returned iterator of another crate's type, such as `slice::Iter` or an `impl Iterator`, that no other rule maps, outside a future | what `collect::>()` makes of it: every item, taken at the call | | `Waker`, taken by value | `_waker`, as a future's poll takes it | | `Range`, `Bound` of an integer | `_range_`, `_bound_`: a `_bound` kind and a value | | `impl RangeBounds` of an integer | `_bounds_`: its start and end bounds | diff --git a/ffi/fixtures/api/examples/transcript.rs b/ffi/fixtures/api/examples/transcript.rs index 5fe4f4b08..7ee00551c 100644 --- a/ffi/fixtures/api/examples/transcript.rs +++ b/ffi/fixtures/api/examples/transcript.rs @@ -378,6 +378,23 @@ fn main() { &["a".to_string(), "b".to_string()], ); println!("trail {:?} {:?}", trail.points(), trail.labels()); + // Returned iterators, each collected at the call: drained labels are gone after. + let mut trail = trail; + println!( + "iterated {:?} {:?} {:?}", + trail.iter().collect::>(), + trail.names().collect::>(), + trail.bytes().collect::>() + ); + println!( + "drained {:?} then {:?}", + trail.drain().collect::>(), + trail.labels() + ); + let numbered: Vec = api_lib::numbered(vec!["p".to_string(), "q".to_string()]) + .map(|c| format!("{} {}", c.name(), c.get())) + .collect(); + println!("numbered {}", numbered.join(", ")); let (v4, v6) = api_lib::nexts("127.0.0.1:8080".parse().unwrap(), "[::1%3]:443".parse().unwrap()); println!("nexts {} {} {} {}", v4.ip(), v4.port(), v6.port(), v6.scope_id()); } diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index fecfcedc5..3ccd3828a 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -1021,6 +1021,31 @@ impl Trail { pub fn labels(&self) -> &[Label] { &self.labels } + + /// Its points one by one, as moq's `Hops::iter` returns them: an array of copies. + pub fn iter(&self) -> std::slice::Iter<'_, Point> { + self.points.iter() + } + + /// Each label's name, through an iterator only its bounds name. + pub fn names(&self) -> impl Iterator { + self.labels.iter().map(|label| label.name.as_str()) + } + + /// The bytes of every name, which cross as a buffer. + pub fn bytes(&self) -> impl Iterator + '_ { + self.labels.iter().flat_map(|label| label.name.bytes()) + } + + /// Its labels, drained: every one is taken at the call, so none are left. + pub fn drain(&mut self) -> std::vec::Drain<'_, Label> { + self.labels.drain(..) + } +} + +/// A counter for each name, counting from its index, made as the iterator is read. +pub fn numbered(names: Vec) -> impl Iterator { + (names.into_iter().enumerate()).map(|(i, name)| Counter::new(&name, i as u64)) } /// Each address at the next port, one IPv4 and one IPv6. diff --git a/ffi/fixtures/reject/expected.txt b/ffi/fixtures/reject/expected.txt index babb04339..76c449510 100644 --- a/ffi/fixtures/reject/expected.txt +++ b/ffi/fixtures/reject/expected.txt @@ -43,6 +43,12 @@ fixtures/reject/src/lib.rs:320:1: rust2-ffi: cannot export fn `count_some`: Vec fixtures/reject/src/lib.rs:325:1: rust2-ffi: cannot export fn `count_slice`: slice of references `&str`; exclude it in the config to leave it out fixtures/reject/src/lib.rs:330:1: rust2-ffi: cannot export fn `peek_all`: reference to a handle inside a value `[Opaque]`; exclude it in the config to leave it out fixtures/reject/src/lib.rs:335:1: rust2-ffi: cannot export fn `none_opaque`: borrowed return that is not Clone `[Opaque]`; exclude it in the config to leave it out +fixtures/reject/src/lib.rs:340:1: rust2-ffi: cannot export fn `alphabet`: Range `char`; exclude it in the config to leave it out +fixtures/reject/src/lib.rs:345:1: rust2-ffi: cannot export fn `naturals`: foreign type `std::ops::RangeFrom`; exclude it in the config to leave it out +fixtures/reject/src/lib.rs:350:1: rust2-ffi: cannot export fn `opaques`: borrowed return that is not Clone `Opaque`; exclude it in the config to leave it out +fixtures/reject/src/lib.rs:355:1: rust2-ffi: cannot export fn `tried`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out +fixtures/reject/src/lib.rs:360:1: rust2-ffi: cannot export fn `eventually`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out +fixtures/reject/src/lib.rs:365:1: rust2-ffi: cannot export trait `Source`: callback signature `items`; exclude it in the config to leave it out fixtures/reject/src/lib.rs:40:1: rust2-ffi: cannot export fn `peek`: reference to a handle inside a value `std::boxed::Box`; exclude it in the config to leave it out fixtures/reject/src/lib.rs:45:1: rust2-ffi: cannot export static `COUNT`: static; exclude it in the config to leave it out fixtures/reject/src/lib.rs:49:1: rust2-ffi: cannot export macro `noop`: macro; exclude it in the config to leave it out diff --git a/ffi/fixtures/reject/src/lib.rs b/ffi/fixtures/reject/src/lib.rs index 86425fb3a..5c192f6ae 100644 --- a/ffi/fixtures/reject/src/lib.rs +++ b/ffi/fixtures/reject/src/lib.rs @@ -335,3 +335,33 @@ pub fn peek_all(values: &[Opaque]) -> usize { pub fn none_opaque() -> &'static [Opaque] { &[] } + +/// A range is a value, not an iterator to collect: one that maps to no range is refused. +pub fn alphabet() -> std::ops::Range { + 'a'..'z' +} + +/// A range with no end, which collecting would never finish. +pub fn naturals() -> std::ops::RangeFrom { + 0.. +} + +/// An iterator of handles with no clone to return. +pub fn opaques() -> std::slice::Iter<'static, Opaque> { + [].iter() +} + +/// An iterator inside a `Result`, which crosses only as a whole return. +pub fn tried() -> Result, String> { + Ok(Vec::new().into_iter()) +} + +/// An iterator a future resolves to. +pub async fn eventually() -> std::vec::IntoIter { + Vec::new().into_iter() +} + +/// A callback returning an iterator, which C would have to make. +pub trait Source: Send + Sync { + fn items(&self) -> std::vec::IntoIter; +} diff --git a/ffi/moq/ffi.toml b/ffi/moq/ffi.toml index 3ad8a54b0..97d4116e5 100644 --- a/ffi/moq/ffi.toml +++ b/ffi/moq/ffi.toml @@ -12,11 +12,9 @@ exclude = [ "Consume", "DecodeError", "Driver", - "Hops::iter", "IntoBytes", "InvalidEpoch", "Path::from_static", - "Path::parts", "Server::accept", "Server::accept_request", "Timed", @@ -24,7 +22,6 @@ exclude = [ "Timestamp::as_millis", "Timestamp::as_nanos", "Timestamp::as_scale", - "Versions::iter", "announce::Announce", "announce::Consumer::poll_synced", "auth::EmptyToken", @@ -84,7 +81,7 @@ exclude = [ # Exported with moq-net, whose signatures name their types, such as `Patterns` and `Instant`. [crates.moq-pattern] -exclude = ["Pattern::captures", "Pattern::new", "Patterns::iter"] +exclude = ["Pattern::captures", "Pattern::new"] [crates.moq-clock] exclude = [ diff --git a/ffi/src/collect.rs b/ffi/src/collect.rs index 7a541d07e..23e5be354 100644 --- a/ffi/src/collect.rs +++ b/ffi/src/collect.rs @@ -901,6 +901,7 @@ impl<'tcx> Collector<'tcx> { err: Some(Type::String), future: false, eager: false, + collect: false, access: Access::Parse, instance: None, }], @@ -1343,6 +1344,7 @@ impl<'tcx> Collector<'tcx> { err: None, future: false, eager: false, + collect: false, access: Access::Field { shared, set }, instance: None, }; @@ -1707,6 +1709,16 @@ impl<'tcx> Collector<'tcx> { output = normalize(inner); future = true; } + // An iterator no other rule maps crosses as the array of its items, all taken at + // the call, as `collect` takes them; a future's stays refused. + let mut collect = false; + if !future + && self.ret(output).is_err() + && let Some(items) = self.items(output, env).and_then(|item| self.vec_of(normalize(item))) + { + output = items; + collect = true; + } let (ok, err) = match output.kind() { ty::Adt(adt, args) if tcx.is_diagnostic_item(sym::Result, adt.did()) => { (self.ret(args.type_at(0)), Some(self.ty(args.type_at(1), Pos::Return))) @@ -1733,6 +1745,7 @@ impl<'tcx> Collector<'tcx> { err, future, eager: future && eager, + collect, access: Access::Call, instance, }), @@ -1890,16 +1903,7 @@ impl<'tcx> Collector<'tcx> { if let Some(bytes) = self.bytes { candidates.push(Ty::new_adt(tcx, tcx.adt_def(bytes), ty::List::empty())); } - if let Some(vec) = tcx.get_diagnostic_item(sym::Vec) { - let alloc = tcx.lang_items().global_alloc_ty(); - if let Some(alloc) = alloc { - let args = tcx.mk_args(&[ - tcx.types.u8.into(), - Ty::new_adt(tcx, tcx.adt_def(alloc), ty::List::empty()).into(), - ]); - candidates.push(Ty::new_adt(tcx, tcx.adt_def(vec), args)); - } - } + candidates.extend(self.vec_of(tcx.types.u8)); // `impl Into>` takes a `String` too, which maps where `Arc` does not. candidates .retain(|&candidate| self.at(def_id, param, base, candidate).is_some() && self.maps(candidate, Pos::Param)); @@ -2169,6 +2173,49 @@ impl<'tcx> Collector<'tcx> { } } + /// `Vec`. + fn vec_of(&self, item: Ty<'tcx>) -> Option> { + let tcx = self.tcx; + let vec = tcx.get_diagnostic_item(sym::Vec)?; + let alloc = tcx.lang_items().global_alloc_ty()?; + let alloc = Ty::new_adt(tcx, tcx.adt_def(alloc), ty::List::empty()); + Some(Ty::new_adt( + tcx, + tcx.adt_def(vec), + tcx.mk_args(&[item.into(), alloc.into()]), + )) + } + + /// What `ty` yields, if it is another crate's iterator, which a return crosses as what + /// `collect` takes from it. A range is a value, which crosses as itself or not at all. + fn items(&self, ty: Ty<'tcx>, env: TypingEnv<'tcx>) -> Option> { + let tcx = self.tcx; + let ty::Adt(adt, _) = ty.kind() else { + return None; + }; + let lang = tcx.lang_items(); + let ranges = [ + lang.range_struct(), + lang.range_inclusive_struct(), + lang.range_from_struct(), + ]; + if self.exported(adt.did().krate) || ranges.contains(&Some(adt.did())) { + return None; + } + let iterator = tcx.get_diagnostic_item(sym::Iterator)?; + let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(env); + if !infcx + .type_implements_trait(iterator, [ty], param_env) + .must_apply_modulo_regions() + { + return None; + } + let item = tcx.get_diagnostic_item(sym::IteratorItem)?; + let projection = Ty::new_projection(tcx, ty::IsRigid::No, item, [ty]); + tcx.try_normalize_erasing_regions(env, ty::Unnormalized::new_wip(projection)) + .ok() + } + /// What `ty` resolves to when awaited, if it is a future. fn future_output(&self, ty: Ty<'tcx>, env: TypingEnv<'tcx>) -> Option> { let tcx = self.tcx; @@ -2423,6 +2470,7 @@ impl<'tcx> Collector<'tcx> { err: None, future: false, eager: false, + collect: false, access: Access::Const, instance: None, }), diff --git a/ffi/src/glue.rs b/ffi/src/glue.rs index dd0084e2f..df82288a8 100644 --- a/ffi/src/glue.rs +++ b/ffi/src/glue.rs @@ -1092,8 +1092,13 @@ impl Gen<'_> { None => self.finish(function, ("", "", "")), }; self.line(format!( - "#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn {name}({}) -> {ret} {{\n\tlet w = \"{name}\";\n\tlet _ = w;\n\t{body}\n\tlet result = {call};\n\t{finish}\n}}\n", + "#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn {name}({}) -> {ret} {{\n\tlet w = \"{name}\";\n\tlet _ = w;\n\t{body}\n\tlet result = {};\n\t{finish}\n}}\n", params.join(", "), + match function.collect { + // An iterator's items, all taken now. + true => format!("::std::iter::Iterator::collect::<::std::vec::Vec<_>>({call})"), + false => call, + }, )); } } diff --git a/ffi/src/ir.rs b/ffi/src/ir.rs index f06bbb401..fb80ecd1a 100644 --- a/ffi/src/ir.rs +++ b/ffi/src/ir.rs @@ -157,6 +157,9 @@ pub struct Function { /// For a future, whether the call itself runs code, as a function that is not /// `async` returning one does: the export calls it at once, and polls what it returns. pub eager: bool, + /// Whether it returns another crate's iterator, whose items the export collects into + /// the array it returns. + pub collect: bool, /// What it reads: Rust's function, a field it reads or writes, or a constant named as it is. pub access: Access, /// The instance it is, if a type parameter exports at several. diff --git a/ffi/tests/api.c b/ffi/tests/api.c index 6a87018d5..0da7660da 100644 --- a/ffi/tests/api.c +++ b/ffi/tests/api.c @@ -678,7 +678,49 @@ static int script(void) { } printf("]\n"); api_vec_label_free(labels); + /* Returned iterators, each collected at the call: drained labels are gone after. */ + api_vec_point iter_points = api_trail_iter(trail); + printf("iterated ["); + for (size_t i = 0; i < iter_points.len; i++) { + print(i == 0 ? "" : ", ", api_point_debug(&iter_points.ptr[i]), ""); + } + api_vec_point_free(iter_points); + api_vec_string iter_names = api_trail_names(trail); + printf("] ["); + for (size_t i = 0; i < iter_names.len; i++) { + printf("%s\"%.*s\"", i == 0 ? "" : ", ", (int)iter_names.ptr[i].len, (const char *)iter_names.ptr[i].ptr); + } + api_vec_string_free(iter_names); + api_buf iter_bytes = api_trail_bytes(trail); + printf("] ["); + for (size_t i = 0; i < iter_bytes.len; i++) { + printf("%s%u", i == 0 ? "" : ", ", iter_bytes.ptr[i]); + } + printf("]\n"); + api_buf_free(iter_bytes); + api_vec_label drained = api_trail_drain(trail); + printf("drained ["); + for (size_t i = 0; i < drained.len; i++) { + print(i == 0 ? "" : ", ", api_label_debug(&drained.ptr[i]), ""); + } + api_vec_label_free(drained); + api_vec_label left = api_trail_labels(trail); + printf("] then ["); + for (size_t i = 0; i < left.len; i++) { + print(i == 0 ? "" : ", ", api_label_debug(&left.ptr[i]), ""); + } + printf("]\n"); + api_vec_label_free(left); api_trail_free(trail); + api_buf numbered_names[] = {str("p"), str("q")}; + api_vec_counter numbered = api_numbered((api_vec_string){.ptr = numbered_names, .len = 2}); + printf("numbered"); + for (size_t i = 0; i < numbered.len; i++) { + print(i == 0 ? " " : ", ", api_counter_name(numbered.ptr[i]), " "); + printf("%llu", (unsigned long long)api_counter_get(numbered.ptr[i])); + } + printf("\n"); + api_vec_counter_free(numbered); api_socket_addr at4 = {.ip = {127, 0, 0, 1}, .port = 8080}; api_socket_addr at6 = {.ip = {[15] = 1}, .port = 443, .v6 = true, .scope_id = 3}; api_socket_addr next4, next6; diff --git a/ffi/tests/api.cpp b/ffi/tests/api.cpp index 7f04c6159..dfa17b2f0 100644 --- a/ffi/tests/api.cpp +++ b/ffi/tests/api.cpp @@ -529,6 +529,38 @@ int script() { print(i == 0 ? "" : ", ", labels[i].debug(), ""); } std::printf("]\n"); + // Returned iterators, each collected at the call: drained labels are gone after. + auto iter_points = trail.iter(); + std::printf("iterated ["); + for (std::size_t i = 0; i < iter_points.size(); i++) { + print(i == 0 ? "" : ", ", iter_points[i].debug(), ""); + } + std::printf("] "); + print_strings(trail.names()); + auto iter_bytes = trail.bytes(); + std::printf(" ["); + for (std::size_t i = 0; i < iter_bytes.size(); i++) { + std::printf("%s%u", i == 0 ? "" : ", ", iter_bytes.data()[i]); + } + std::printf("]\n"); + auto drained = trail.drain(); + std::printf("drained ["); + for (std::size_t i = 0; i < drained.size(); i++) { + print(i == 0 ? "" : ", ", drained[i].debug(), ""); + } + auto left = trail.labels(); + std::printf("] then ["); + for (std::size_t i = 0; i < left.size(); i++) { + print(i == 0 ? "" : ", ", left[i].debug(), ""); + } + std::printf("]\n"); + auto numbered = api::numbered({"p", "q"}); + std::printf("numbered"); + for (std::size_t i = 0; i < numbered.size(); i++) { + print(i == 0 ? " " : ", ", numbered[i].name(), " "); + std::printf("%llu", static_cast(numbered[i].get())); + } + std::printf("\n"); api::socket_addr at4{}; at4.ip[0] = 127; at4.ip[3] = 1; diff --git a/ffi/tests/api.kt b/ffi/tests/api.kt index 4671d0a58..bcdf043aa 100644 --- a/ffi/tests/api.kt +++ b/ffi/tests/api.kt @@ -310,7 +310,13 @@ fun script() { println("shapes ${Shape.ALL.joinToString(", ", "[", "]") { it.debug() }} greetings ${GREETINGS.joinToString(", ", "[", "]") { "\"$it\"" }}") Trail.new(listOf(Point(1, 2), Point(3, 4)), listOf("a", "b")).use { trail -> println("trail ${trail.points().joinToString(", ", "[", "]") { it.debug() }} ${trail.labels().joinToString(", ", "[", "]") { it.debug() }}") + // Returned iterators, each collected at the call: drained labels are gone after. + println("iterated ${trail.iter().joinToString(", ", "[", "]") { it.debug() }} ${trail.names().joinToString(", ", "[", "]") { "\"$it\"" }} ${trail.bytes().joinToString(", ", "[", "]") { it.toUByte().toString() }}") + println("drained ${trail.drain().joinToString(", ", "[", "]") { it.debug() }} then ${trail.labels().joinToString(", ", "[", "]") { it.debug() }}") } + val numbered = numbered(listOf("p", "q")) + println("numbered ${numbered.joinToString(", ") { "${it.name()} ${it.get()}" }}") + numbered.forEach { it.close() } val at4 = java.net.InetSocketAddress(java.net.InetAddress.getByAddress(byteArrayOf(127, 0, 0, 1)), 8080) val at6 = java.net.InetSocketAddress(java.net.Inet6Address.getByAddress(null, loopback, 3), 443) val (next4, next6) = nexts(at4, at6) diff --git a/quest/m1/ffi-export/README.md b/quest/m1/ffi-export/README.md index 689e7faf2..620d9fd33 100644 --- a/quest/m1/ffi-export/README.md +++ b/quest/m1/ffi-export/README.md @@ -49,7 +49,6 @@ Every generator on the C ABI: - [Payloads cross as bytes](/quest/m1/ffi-export/payload-bytes.md) - a payload that is not UTF-8 crosses unchanged, where today it aborts from C, C++, and Kotlin - [Iterator and JSON arguments the exporter can't map yet](/quest/m1/ffi-export/instance-keys.md) - `IntoIterator` as a `Vec`, and `serde_json::Value` -- [Returned iterators cross as arrays](/quest/m1/ffi-export/iterators.md) - `Hops::iter`, `Versions::iter`, and `Patterns::iter` export, returning arrays as `&[T]` does - [moq-clock's C names once it moves into kio](/quest/m1/ffi-export/crates.md) - `moq_now` and `moq_origin` become the clock's, after moq moves it into `kio::clock` - [Sessions on moq-tokio](/quest/m1/ffi-export/session-tokio.md) - bindings connect and accept with one call, the library running moq-tokio inside - [Sessions on sans-IO QUIC](/quest/m1/ffi-export/session-quic.md) - bindings move UDP datagrams and drive the session's poll themselves diff --git a/quest/m1/ffi-export/iterators.md b/quest/m1/ffi-export/iterators.md deleted file mode 100644 index b97b06bfd..000000000 --- a/quest/m1/ffi-export/iterators.md +++ /dev/null @@ -1,21 +0,0 @@ -# [S] Returned iterators cross as arrays - -## Goal - -moq-net's `Hops::iter` and `Versions::iter` and moq-pattern's `Patterns::iter` export -without being excluded in `ffi/moq/ffi.toml`, each returning what it iterates as an array, -as a `&[T]` return crosses. This comes from a fixed rule, with no config. - -## Plan - -Found by [#205](https://github.com/kixelated/rust2/pull/205) on 2026-10-28, which exports -`&[T]` of any type. - -- `std::slice::Iter<'_, T>` is a borrowed slice, so it crosses exactly as `&[T]` does. -- `Versions::iter` returns `impl Iterator`. Collecting it at the return is - exact only for an iterator that reads borrowed data, with no side effect and an end; - decide which `impl Iterator` returns the rule takes when the quest starts, and refuse the - rest with a span. -- Report moq-ffi's coverage and the census before and after. - -Public API: the C names and types these methods export with. From 59aa0cf32b59ca3fdd4b911e06bdea796cdc6793 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:45:10 -0700 Subject: [PATCH 03/11] fix(ffi): collect only iterators no caller could tell apart from lazy ones Co-Authored-By: Claude Opus 5.5 --- ffi/README.md | 2 +- ffi/fixtures/api/src/lib.rs | 23 ++++++---- ffi/fixtures/reject/expected.txt | 6 +++ ffi/fixtures/reject/src/lib.rs | 54 ++++++++++++++++++++++++ ffi/src/collect.rs | 72 +++++++++++++++++++++++++++----- 5 files changed, 138 insertions(+), 19 deletions(-) diff --git a/ffi/README.md b/ffi/README.md index 5a6d580b2..3597aeace 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -77,7 +77,7 @@ export's, and adds nothing; another crate's type is refused. | `SocketAddr`, `SocketAddrV4`, `SocketAddrV6` | `_socket_addr`: its IP's bytes, port, and whether it is IPv6; one of the other family passed to `V4` or `V6` aborts | | `url::Url` | an object `_url`, made by `_url_parse`, which fails with the parse error's message, and printed by `_to_string` | | `Vec` and `&[T]` of any other `T` | `_vec_`: an array of `T`'s C values, viewed passed in and owned returned, a slice as a clone; of references only returned | -| a returned iterator of another crate's type, such as `slice::Iter` or an `impl Iterator`, that no other rule maps, outside a future | what `collect::>()` makes of it: every item, taken at the call | +| a returned iterator, such as `slice::Iter` or an `impl Iterator`, that no other rule maps, outside a future, built only of core's and alloc's iterators over no closure, function, or trait object, and not endless (`repeat`, `cycle`, `RangeFrom`) | what `collect::>()` makes of it: every item, taken at the call | | `Waker`, taken by value | `_waker`, as a future's poll takes it | | `Range`, `Bound` of an integer | `_range_`, `_bound_`: a `_bound` kind and a value | | `impl RangeBounds` of an integer | `_bounds_`: its start and end bounds | diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index 3ccd3828a..ff8259c09 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -994,6 +994,7 @@ pub const GREETINGS: &[&str] = &["hi", "hello"]; pub struct Trail { points: Vec, labels: Vec