From 2904dd7f5684c901f21ae470391b4389c3e7b412 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:02:02 -0700 Subject: [PATCH 1/3] chore(quest): claim quest/m3/ts-next-return.md Quest-Claim: cabcf1da3bd9ef9d From 2691e229100799f460b1fb5a7afa0b517d6f7aac Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:15:40 -0700 Subject: [PATCH 2/3] fix(ts): return std's next from a function other than next as an Option Co-Authored-By: Claude Opus 5.5 --- quest/m3/README.md | 2 +- quest/m3/ts-next-return.md | 15 --- quest/m3/ts-option-items.md | 17 +++ ts/fixtures/lang/expected/core/option.ts | 7 + ts/fixtures/lang/expected/core/result.ts | 7 + ts/fixtures/lang/expected/harness.ts | 108 +++++++-------- ts/fixtures/lang/expected/iters.ts | 159 ++++++++++++++++++++++- ts/fixtures/lang/src/harness.rs | 1 + ts/fixtures/lang/src/iters.rs | 85 ++++++++++++ ts/src/lower/mir/mod.rs | 6 +- 10 files changed, 335 insertions(+), 72 deletions(-) delete mode 100644 quest/m3/ts-next-return.md create mode 100644 quest/m3/ts-option-items.md diff --git a/quest/m3/README.md b/quest/m3/README.md index 845f5374f..fcdb6f56f 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -26,5 +26,5 @@ generic std gap is planned here even when moq never calls it. - [Binding gaps](/quest/m3/ts-bind-gaps.md) - bound types as keys, unit returns checked, renamed dependencies - [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's folds, zips, flattens, and collects drop as std's do - [Slice windows and chunks, Vec drain, and the order of byte arrays](/quest/m3/ts-slice-gaps.md) - `windows`, `chunks`, `Vec::drain`, and byte arrays' order translate -- [Return a std iterator's next from a generic function](/quest/m3/ts-next-return.md) - `it.next()` returned from a generic function is an `Option`, as `tsc` expects +- [Iterator consumers over items whose None is rt.None](/quest/m3/ts-option-items.md) - `nth`, `last`, and `find` of an iterator of `Option` keep `None` apart from `Some(None)` - [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does diff --git a/quest/m3/ts-next-return.md b/quest/m3/ts-next-return.md deleted file mode 100644 index 8fe098f83..000000000 --- a/quest/m3/ts-next-return.md +++ /dev/null @@ -1,15 +0,0 @@ -# [S] Return a std iterator's next from a generic function - -## Goal - -rust2-ts translates a generic function that returns `next` of a std iterator it was given, -`fn first>(mut it: I) -> Option { it.next() }` with `I` a -`Copied>`, proven by a differential test against native Rust. - -## Plan - -Found while testing `&mut &mut I` on 2026-10-29: the translation is `return it.next();`, -the protocol's item or `rt.DONE` rather than the `Option` the signature declares, so `tsc` -refuses it. A `next` read into a local first, as `it.next().unwrap_or(0)`, converts. - -Public API: the translator's output. diff --git a/quest/m3/ts-option-items.md b/quest/m3/ts-option-items.md new file mode 100644 index 000000000..1cfa9fada --- /dev/null +++ b/quest/m3/ts-option-items.md @@ -0,0 +1,17 @@ +# [S] Iterator consumers over items whose None is rt.None + +## Goal + +`nth`, `last`, `find`, `max`, `min`, and std's other iterator consumers that return an +`Option` of the item translate over an iterator whose item's `None` is `rt.None`, such as +`Option`, keeping `None` apart from `Some(None)`, proven by a differential test against +native Rust. + +## Plan + +Found while fixing a returned `next` on 2026-10-30: `it.nth(n)` and `it.last()` of an +iterator of `Option` are refused at their span, as `src/lower/library.rs`'s +`takes_none` lists only `next`, `next_back`, and `nth_back` among iterator methods. +Each runtime consumer needs the item's `None` passed in, as `rt.iterToOption` takes it. + +Public API: the translator's output. diff --git a/ts/fixtures/lang/expected/core/option.ts b/ts/fixtures/lang/expected/core/option.ts index c8f418edb..686188d60 100644 --- a/ts/fixtures/lang/expected/core/option.ts +++ b/ts/fixtures/lang/expected/core/option.ts @@ -525,6 +525,13 @@ export function mapOr$Option_Vec_u8_u8_library_closure5(self: rt.ByteVec | undef return f(self); } +export function mapOr$Option_char_u32_from(self: rt.char | undefined, default_: rt.u32, _: (a0: rt.char) => rt.u32): rt.u32 { + if (self === undefined) { + return default_; + } + return self as rt.u32; +} + export function mapOr$Option_u16_u16_edits_closure21(self: rt.u16 | undefined, default_: rt.u16, f: (a0: rt.u16) => rt.u16): rt.u16 { if (self === undefined) { return default_; diff --git a/ts/fixtures/lang/expected/core/result.ts b/ts/fixtures/lang/expected/core/result.ts index 3773d001a..2580eb80e 100644 --- a/ts/fixtures/lang/expected/core/result.ts +++ b/ts/fixtures/lang/expected/core/result.ts @@ -207,6 +207,13 @@ export function unwrapOr$Result_isize_isize(self: rt.Result, return default_; } +export function unwrapOr$Result_str_Utf8Error(self: rt.Result, default_: string): string { + if (self.ok) { + return self.value; + } + return default_; +} + export function unwrapOr$Result_u16_TryFromIntError(self: rt.Result, default_: rt.u16): rt.u16 { if (self.ok) { return self.value; diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 87f6e9468..2aed013db 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -22,7 +22,7 @@ import { ints, strings, derived, written, counts, rounding, panics, wrapped } fr import { methods } from "./generics.ts"; import { holds } from "./holds.ts"; import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast as ints_cast, convert } from "./ints.ts"; -import { adaptors, consumers, skips, ranked, ranges, options, own, values } from "./iters.ts"; +import { adaptors, consumers, skips, ranked, ranges, options, own, values, returned } from "./iters.ts"; import { keys, overrides } from "./keys.ts"; import { locals } from "./locals.ts"; import { locks, relock, rwlocks } from "./locks.ts"; @@ -43,109 +43,111 @@ import { wrappers } from "./wrappers.ts"; * case added at the end moves no other. */ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void][] { - return copy$str_forabfnu8au8bmutstdvecVecu8s([["ints::u8_op", u8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u16_op", u16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u32_op", u32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u64_op", u64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u128_op", u128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::usize_op", usizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i8_op", i8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i16_op", i16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i32_op", i32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i64_op", i64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i128_op", i128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::isize_op", isizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::neg", neg] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::cast", cast] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::convert", (_291: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void => { + return copy$str_forabfnu8au8bmutstdvecVecu8s([["ints::u8_op", u8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u16_op", u16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u32_op", u32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u64_op", u64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u128_op", u128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::usize_op", usizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i8_op", i8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i16_op", i16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i32_op", i32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i64_op", i64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i128_op", i128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::isize_op", isizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::neg", neg] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::cast", cast] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::convert", (_294: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void => { convert(data, out); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::copies", (_292: rt.u8, data2: rt.ByteSlice, out2: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::copies", (_295: rt.u8, data2: rt.ByteSlice, out2: rt.ByteVec): void => { shapes_copies(data2, out2); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::loops", (_293: rt.u8, data3: rt.ByteSlice, out3: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::loops", (_296: rt.u8, data3: rt.ByteSlice, out3: rt.ByteVec): void => { loops(data3, out3); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::patterns", (_294: rt.u8, data4: rt.ByteSlice, out4: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::patterns", (_297: rt.u8, data4: rt.ByteSlice, out4: rt.ByteVec): void => { patterns(data4, out4); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::closures", (_295: rt.u8, data5: rt.ByteSlice, out5: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::closures", (_298: rt.u8, data5: rt.ByteSlice, out5: rt.ByteVec): void => { closures(data5, out5); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::discriminants", (_296: rt.u8, data6: rt.ByteSlice, out6: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::discriminants", (_299: rt.u8, data6: rt.ByteSlice, out6: rt.ByteVec): void => { discriminants(data6, out6); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::library", (_297: rt.u8, data7: rt.ByteSlice, out7: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::library", (_2100: rt.u8, data7: rt.ByteSlice, out7: rt.ByteVec): void => { library(data7, out7); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::ints", ints] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::strings", (_298: rt.u8, data8: rt.ByteSlice, out8: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::ints", ints] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::strings", (_2101: rt.u8, data8: rt.ByteSlice, out8: rt.ByteVec): void => { strings(data8, out8); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::derived", (_299: rt.u8, data9: rt.ByteSlice, out9: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::derived", (_2102: rt.u8, data9: rt.ByteSlice, out9: rt.ByteVec): void => { derived(data9, out9); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::written", (_2100: rt.u8, data10: rt.ByteSlice, out10: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::written", (_2103: rt.u8, data10: rt.ByteSlice, out10: rt.ByteVec): void => { written(data10, out10); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::panics", panics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["generics::methods", (_2101: rt.u8, data11: rt.ByteSlice, out11: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::panics", panics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["generics::methods", (_2104: rt.u8, data11: rt.ByteSlice, out11: rt.ByteVec): void => { methods(data11, out11); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::adaptors", adaptors] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::consumers", consumers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranges", (_2102: rt.u8, data12: rt.ByteSlice, out12: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::adaptors", adaptors] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::consumers", consumers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranges", (_2105: rt.u8, data12: rt.ByteSlice, out12: rt.ByteVec): void => { ranges(data12, out12); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::options", (_2103: rt.u8, data13: rt.ByteSlice, out13: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::options", (_2106: rt.u8, data13: rt.ByteSlice, out13: rt.ByteVec): void => { options(data13, out13); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::own", (_2104: rt.u8, data14: rt.ByteSlice, out14: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::own", (_2107: rt.u8, data14: rt.ByteSlice, out14: rt.ByteVec): void => { own(data14, out14); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::values", (_2105: rt.u8, data15: rt.ByteSlice, out15: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::values", (_2108: rt.u8, data15: rt.ByteSlice, out15: rt.ByteVec): void => { values(data15, out15); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::order", (_2106: rt.u8, data16: rt.ByteSlice, out16: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::order", (_2109: rt.u8, data16: rt.ByteSlice, out16: rt.ByteVec): void => { order(data16, out16); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::hash_maps", hashMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::sets", sets] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::btree_maps", btreeMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::deques", (_2107: rt.u8, data17: rt.ByteSlice, out17: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::hash_maps", hashMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::sets", sets] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::btree_maps", btreeMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::deques", (_2110: rt.u8, data17: rt.ByteSlice, out17: rt.ByteVec): void => { deques(data17, out17); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::flows", (_2108: rt.u8, data18: rt.ByteSlice, out18: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::flows", (_2111: rt.u8, data18: rt.ByteSlice, out18: rt.ByteVec): void => { flows(data18, out18); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::keys", keys] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chars::chars", chars] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::strs", strs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::vecs", (_2109: rt.u8, data19: rt.ByteSlice, out19: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::keys", keys] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chars::chars", chars] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::strs", strs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::vecs", (_2112: rt.u8, data19: rt.ByteSlice, out19: rt.ByteVec): void => { vecs(data19, out19); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::slices", slices] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::stores", (_2110: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::slices", slices] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::stores", (_2113: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): void => { stores(data20, out20); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chunks::chunks", chunks] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cows::cows", cows] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["durations::durations", durations] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["combinators::combinators", combinators] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["splits::splits", splits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["nested::nested", nested] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::refs", (_2111: rt.u8, data21: rt.ByteSlice, out21: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chunks::chunks", chunks] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cows::cows", cows] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["durations::durations", durations] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["combinators::combinators", combinators] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["splits::splits", splits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["nested::nested", nested] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::refs", (_2114: rt.u8, data21: rt.ByteSlice, out21: rt.ByteVec): void => { refs(data21, out21); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2112: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2115: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => { counts(data22, out22); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2113: rt.u8, _310: rt.ByteSlice, out23: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2116: rt.u8, _310: rt.ByteSlice, out23: rt.ByteVec): void => { rounding(out23); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::skips", skips] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["wrappers::wrappers", wrappers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::edits", edits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["utf8::decodes", decodes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::floats", floats] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["atomics::atomics", atomics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::overrides", overrides] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::dyns", (_2114: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::skips", skips] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["wrappers::wrappers", wrappers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::edits", edits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["utf8::decodes", decodes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::floats", floats] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["atomics::atomics", atomics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::overrides", overrides] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::dyns", (_2117: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { dyns(data23, out24); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cells::cells", cells] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::shared", (_2115: rt.u8, data24: rt.ByteSlice, out25: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cells::cells", cells] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::shared", (_2118: rt.u8, data24: rt.ByteSlice, out25: rt.ByteVec): void => { shared(data24, out25); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranked", ranked] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["captures::captures", captures] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::locks", (_2116: rt.u8, data25: rt.ByteSlice, out26: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranked", ranked] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["captures::captures", captures] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::locks", (_2119: rt.u8, data25: rt.ByteSlice, out26: rt.ByteVec): void => { locks(data25, out26); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::relock", (_2117: rt.u8, data26: rt.ByteSlice, out27: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::relock", (_2120: rt.u8, data26: rt.ByteSlice, out27: rt.ByteVec): void => { relock(data26, out27); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locals::locals", (_2118: rt.u8, data27: rt.ByteSlice, out28: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locals::locals", (_2121: rt.u8, data27: rt.ByteSlice, out28: rt.ByteVec): void => { locals(data27, out28); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["statics::statics", (_2119: rt.u8, data28: rt.ByteSlice, out29: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["statics::statics", (_2122: rt.u8, data28: rt.ByteSlice, out29: rt.ByteVec): void => { statics(data28, out29); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::rwlocks", (_2120: rt.u8, data29: rt.ByteSlice, out30: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::rwlocks", (_2123: rt.u8, data29: rt.ByteSlice, out30: rt.ByteVec): void => { rwlocks(data29, out30); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["borrows::borrows", (_2121: rt.u8, data30: rt.ByteSlice, out31: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["borrows::borrows", (_2124: rt.u8, data30: rt.ByteSlice, out31: rt.ByteVec): void => { borrows(data30, out31); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["defaults::defaults", (_2122: rt.u8, data31: rt.ByteSlice, out32: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["defaults::defaults", (_2125: rt.u8, data31: rt.ByteSlice, out32: rt.ByteVec): void => { defaults(data31, out32); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::arcs", (_2123: rt.u8, data32: rt.ByteSlice, out33: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::arcs", (_2126: rt.u8, data32: rt.ByteSlice, out33: rt.ByteVec): void => { arcs(data32, out33); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::rcs", (_2124: rt.u8, data33: rt.ByteSlice, out34: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::rcs", (_2127: rt.u8, data33: rt.ByteSlice, out34: rt.ByteVec): void => { rcs(data33, out34); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_arcs", (_2125: rt.u8, data34: rt.ByteSlice, out35: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_arcs", (_2128: rt.u8, data34: rt.ByteSlice, out35: rt.ByteVec): void => { cyclicArcs(data34, out35); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_rcs", (_2126: rt.u8, data35: rt.ByteSlice, out36: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_rcs", (_2129: rt.u8, data35: rt.ByteSlice, out36: rt.ByteVec): void => { cyclicRcs(data35, out36); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_arcs", (_2127: rt.u8, data36: rt.ByteSlice, out37: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_arcs", (_2130: rt.u8, data36: rt.ByteSlice, out37: rt.ByteVec): void => { uniqueArcs(data36, out37); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_rcs", (_2128: rt.u8, data37: rt.ByteSlice, out38: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_rcs", (_2131: rt.u8, data37: rt.ByteSlice, out38: rt.ByteVec): void => { uniqueRcs(data37, out38); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::anys", (_2129: rt.u8, data38: rt.ByteSlice, out39: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::anys", (_2132: rt.u8, data38: rt.ByteSlice, out39: rt.ByteVec): void => { anys(data38, out39); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::fns", (_2130: rt.u8, data39: rt.ByteSlice, out40: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::fns", (_2133: rt.u8, data39: rt.ByteSlice, out40: rt.ByteVec): void => { fns(data39, out40); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::copies", (_2131: rt.u8, data40: rt.ByteSlice, out41: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::copies", (_2134: rt.u8, data40: rt.ByteSlice, out41: rt.ByteVec): void => { copies(data40, out41); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::lists", (_2132: rt.u8, data41: rt.ByteSlice, out42: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::lists", (_2135: rt.u8, data41: rt.ByteSlice, out42: rt.ByteVec): void => { lists(data41, out42); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::nested", (_2133: rt.u8, data42: rt.ByteSlice, out43: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::nested", (_2136: rt.u8, data42: rt.ByteSlice, out43: rt.ByteVec): void => { pointers_nested(data42, out43); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::places", (_2134: rt.u8, data43: rt.ByteSlice, out44: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::places", (_2137: rt.u8, data43: rt.ByteSlice, out44: rt.ByteVec): void => { places(data43, out44); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::sentinels", (_2135: rt.u8, data44: rt.ByteSlice, out45: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::sentinels", (_2138: rt.u8, data44: rt.ByteSlice, out45: rt.ByteVec): void => { sentinels(data44, out45); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::shared", (_2136: rt.u8, data45: rt.ByteSlice, out46: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::shared", (_2139: rt.u8, data45: rt.ByteSlice, out46: rt.ByteVec): void => { pointers_shared(data45, out46); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::unchecked", (_2137: rt.u8, data46: rt.ByteSlice, out47: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::unchecked", (_2140: rt.u8, data46: rt.ByteSlice, out47: rt.ByteVec): void => { unchecked(data46, out47); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::bytes", bytes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::from_fns", (_2138: rt.u8, data47: rt.ByteSlice, out48: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::bytes", bytes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::from_fns", (_2141: rt.u8, data47: rt.ByteSlice, out48: rt.ByteVec): void => { fromFns(data47, out48); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::optionals", optionals] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["objects::objects", (_2139: rt.u8, data48: rt.ByteSlice, out49: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::optionals", optionals] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["objects::objects", (_2142: rt.u8, data48: rt.ByteSlice, out49: rt.ByteVec): void => { objects(data48, out49); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["holds::holds", holds] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::wrapped", (_2140: rt.u8, data49: rt.ByteSlice, out50: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["holds::holds", holds] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::wrapped", (_2143: rt.u8, data49: rt.ByteSlice, out50: rt.ByteVec): void => { wrapped(data49, out50); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::to_refs", (_2141: rt.u8, data50: rt.ByteSlice, out51: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::to_refs", (_2144: rt.u8, data50: rt.ByteSlice, out51: rt.ByteVec): void => { toRefs(data50, out51); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["orders::orders", orders] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]).map(copy$str_forabfnu8au8bmutstdvecVecu8); + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["orders::orders", orders] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::returned", (_2145: rt.u8, data51: rt.ByteSlice, out52: rt.ByteVec): void => { + returned(data51, out52); + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]).map(copy$str_forabfnu8au8bmutstdvecVecu8); } /** Run one case. */ diff --git a/ts/fixtures/lang/expected/iters.ts b/ts/fixtures/lang/expected/iters.ts index 3ee3ec3d6..eccf6d73a 100644 --- a/ts/fixtures/lang/expected/iters.ts +++ b/ts/fixtures/lang/expected/iters.ts @@ -3,7 +3,8 @@ import * as rt from "./rt.ts"; import { copy$Bumped, copy$Option_u8_Reverse_Option_u8, copy$Option_usize_u8, copy$u8_u8 } from "./lib.ts"; import { thenSome$bool_u16, thenSome$bool_u8 } from "./core/bool.ts"; -import { unwrapOr$Option_NonZero_u64, unwrapOr$Option_i64, unwrapOr$Option_u8, unwrapOr$Option_usize_u8, map$Option_u8_u8_elements_closure8, mapOr$Option_Tilt_u8_ranked_closure11_closure0, mapOr$Option_Vec_u16_u8_consumers_closure23, mapOr$Option_u8_u8_btree_maps_closure5, mapOr$Option_u8_u8_u8_btree_maps_closure0, mapOr$Option_u8_usize_iters_closure1, mapOr$Option_u8s_u8_skips_closure44, mapOr$Option_usize_u8_consumers_closure8, mapOr$Option_usize_u8_u8_heaps_closure0, filter$Option_u8_combinators_closure0 } from "./core/option.ts"; +import { unwrapOr$Option_NonZero_u64, unwrapOr$Option_i64, unwrapOr$Option_u8, unwrapOr$Option_usize_u8, map$Option_u8_u8_elements_closure8, mapOr$Option_Tilt_u8_ranked_closure11_closure0, mapOr$Option_Vec_u16_u8_consumers_closure23, mapOr$Option_char_u32_from, mapOr$Option_u8_u8_btree_maps_closure5, mapOr$Option_u8_u8_u8_btree_maps_closure0, mapOr$Option_u8_usize_iters_closure1, mapOr$Option_u8s_u8_skips_closure44, mapOr$Option_usize_u8_consumers_closure8, mapOr$Option_usize_u8_u8_heaps_closure0, filter$Option_u8_combinators_closure0 } from "./core/option.ts"; +import { unwrapOr$Result_str_Utf8Error } from "./core/result.ts"; import * as Bumped from "./iters.Bumped.ts"; import * as Countdown from "./iters.Countdown.ts"; import * as Doubled from "./iters.Doubled.ts"; @@ -1213,4 +1214,160 @@ export function values(data: rt.ByteSlice, out: rt.ByteVec): void { })); } +/** + * What std's `Option`-returning calls give, returned as is: an `Option`, whose `None` + * stays apart from an item's own. + */ +export function returned(data: rt.ByteSlice, out: rt.ByteVec): void { + const _3: (a0: rt.u8 | undefined, a1: rt.ByteVec) => void = (b: rt.u8 | undefined, out2: rt.ByteVec): void => { + rt.byteVecPush(out2, mapOr$Option_u8_u8_btree_maps_closure5(b, 170, (b2: rt.u8): rt.u8 => { + return b2; + })); + }; + const _4: (a0: rt.u8 | undefined | rt.None, a1: rt.ByteVec) => void = (b3: rt.u8 | undefined | rt.None, out3: rt.ByteVec): void => { + if (b3 === rt.None) { + rt.byteVecPush(out3, 187); + } else if (b3 === undefined) { + rt.byteVecPush(out3, 204); + } else { + rt.byteVecPush(out3, b3); + } + }; + const n: rt.usize = mapOr$Option_u8_usize_iters_closure1(rt.byteSliceFirst(data), 0, (_2: rt.u8): rt.usize => { + return rt.u8Rem(_2, 4) as rt.usize; + }); + const part = first$Copied_Iter_u8(rt.iterSlice(rt.byteSliceView(data))); + _3(part, out); + const part2 = back$Copied_Iter_u8(rt.iterSlice(rt.byteSliceView(data))); + _3(part2, out); + const part3 = nth$Copied_Iter_u8(rt.iterSlice(rt.byteSliceView(data)), n); + _3(part3, out); + const part4 = last$Copied_Iter_u8(rt.iterSlice(rt.byteSliceView(data))); + _3(part4, out); + const part5 = first$Map_Iter_u8_returned_closure0(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (b6: rt.u8): rt.u8 | undefined => { + if (!(rt.u8Rem(b6, 3) === 0)) { + return b6; + } + return undefined; + })); + _4(part5, out); + const part6 = back$Map_Iter_u8_returned_closure0(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (b7: rt.u8): rt.u8 | undefined => { + if (!(rt.u8Rem(b7, 3) === 0)) { + return b7; + } + return undefined; + })); + _4(part6, out); + const part7 = first$Gaps({ data, at: n }); + _4(part7, out); + const part8 = first$Countdown({ left: n & 0xff, step: 1 }); + _3(part8, out); + rt.iterExtendBytes(out, rt.iterSlice(rt.u32ToBeBytes(mapOr$Option_char_u32_from(first$Chars(rt.strChars(unwrapOr$Result_str_Utf8Error(rt.strFromUtf8(data), "é"))), 0, (a0: rt.char): rt.u32 => { + return a0 as rt.u32; + })).reverse())); + const part9 = byMut$Copied_Iter_u8(rt.iterSlice(rt.byteSliceView(data))); + _3(part9, out); + const gaps: Gaps.Gaps = { data, at: 0 }; + const part10 = byMut$Gaps(gaps); + _4(part10, out); + const part11 = byMut$Gaps(gaps); + _4(part11, out); + const it: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); + const part12 = borrowed(it); + _3(part12, out); + const part13 = borrowed(it); + _3(part13, out); + const part14 = secondOf(data); + _3(part14, out); + const part15 = fromOne(n & 0xff); + _3(part15, out); + const part16 = peeked$Copied_Iter_u8(rt.iterPeekable(rt.iterSlice(rt.byteSliceView(data)))); + _3(part16, out); + const part17 = at$u8(data, n); + _3(part17, out); + const part18 = at$Option_u8(rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (b8: rt.u8): rt.u8 | undefined => { + if (!(rt.u8Rem(b8, 3) === 0)) { + return b8; + } + return undefined; + })), n); + _4(part18, out); +} + +export function first$Chars(it: rt.Iter): rt.char | undefined { + return rt.iterToOption(it.next()); +} + +export function first$Copied_Iter_u8(it: rt.Iter): rt.u8 | undefined { + return rt.iterToOption(it.next()); +} + +export function first$Countdown(it: Countdown.Countdown): rt.u8 | undefined { + return rt.iterToOption(Countdown.next$Iterator(it)); +} + +export function first$Gaps(it: Gaps.Gaps): rt.u8 | undefined | rt.None { + return rt.iterToOption(Gaps.next$Iterator(it), rt.None); +} + +export function first$Map_Iter_u8_returned_closure0(it: rt.Iter): rt.u8 | undefined | rt.None { + return rt.iterToOption(it.next(), rt.None); +} + +export function back$Copied_Iter_u8(it: rt.Iter): rt.u8 | undefined { + return rt.iterToOption(it.nextBack()); +} + +export function back$Map_Iter_u8_returned_closure0(it: rt.Iter): rt.u8 | undefined | rt.None { + return rt.iterToOption(it.nextBack(), rt.None); +} + +export function nth$Copied_Iter_u8(it: rt.Iter, n: rt.usize): rt.u8 | undefined { + return rt.iterNth(it, n); +} + +export function last$Copied_Iter_u8(it: rt.Iter): rt.u8 | undefined { + return rt.iterLast(it); +} + +/** Through a `&mut` to the iterator. */ +export function byMut$Copied_Iter_u8(it: rt.Iter): rt.u8 | undefined { + return rt.iterToOption(it.next()); +} + +/** Through a `&mut` to the iterator. */ +export function byMut$Gaps(it: Gaps.Gaps): rt.u8 | undefined | rt.None { + return rt.iterToOption(Gaps.next$Iterator(it), rt.None); +} + +/** Through a borrow of a std iterator the function is not generic over. */ +export function borrowed(it: rt.Iter): rt.u8 | undefined { + return rt.iterToOption(it.next()); +} + +/** Of a slice's iterator the function makes. */ +export function secondOf(data: rt.ByteSlice): rt.u8 | undefined { + const it: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); + it.next(); + return rt.iterToOption(it.next()); +} + +/** Of a small range the function makes. */ +export function fromOne(n: rt.u8): rt.u8 | undefined { + const range: rt.Range = new rt.Range(1, n); + return range.start < range.end ? range.start++ : undefined; +} + +export function peeked$Copied_Iter_u8(it: rt.Peekable): rt.u8 | undefined { + return rt.peekablePeek(it); +} + +export function at$Option_u8(items: Array, i: rt.usize): rt.u8 | undefined | rt.None { + return rt.sliceGet(items, i, rt.None); +} + +export function at$u8(items: rt.ByteSlice, i: rt.usize): rt.u8 | undefined { + return rt.byteSliceGet(items, i); +} + //# sourceMappingURL=iters.ts.map diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index 61de0367b..202519001 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -119,6 +119,7 @@ fn cases() -> Vec<(&'static str, Case)> { ("fmt::wrapped", |_, data, out| fmt::wrapped(data, out)), ("refs::to_refs", |_, data, out| refs::to_refs(data, out)), ("orders::orders", orders::orders), + ("iters::returned", |_, data, out| iters::returned(data, out)), ] } diff --git a/ts/fixtures/lang/src/iters.rs b/ts/fixtures/lang/src/iters.rs index b405de074..b9f89605f 100644 --- a/ts/fixtures/lang/src/iters.rs +++ b/ts/fixtures/lang/src/iters.rs @@ -791,3 +791,88 @@ impl fmt::Debug for Doubled<'_> { f.debug_list().entries(self.0.iter().map(|&b| b as u16 * 2)).finish() } } + +/// What std's `Option`-returning calls give, returned as is: an `Option`, whose `None` +/// stays apart from an item's own. +pub fn returned(data: &[u8], out: &mut Vec) { + let maybe = |b: &u8| if b % 3 == 0 { None } else { Some(*b) }; + let push = |b: Option, out: &mut Vec| out.push(b.map_or(0xaa, |b| b)); + let nested = |b: Option>, out: &mut Vec| match b { + None => out.push(0xbb), + Some(None) => out.push(0xcc), + Some(Some(b)) => out.push(b), + }; + let n = data.first().map_or(0, |&b| usize::from(b % 4)); + push(first(data.iter().copied()), out); + push(back(data.iter().copied()), out); + push(nth(data.iter().copied(), n), out); + push(last(data.iter().copied()), out); + nested(first(data.iter().map(maybe)), out); + nested(back(data.iter().map(maybe)), out); + nested(first(Gaps { data, at: n }), out); + push(first(Countdown { left: n as u8, step: 1 }), out); + let text = std::str::from_utf8(data).unwrap_or("é"); + out.extend(first(text.chars()).map_or(0, u32::from).to_le_bytes()); + let mut copied = data.iter().copied(); + push(by_mut(&mut copied), out); + let mut gaps = Gaps { data, at: 0 }; + nested(by_mut(&mut gaps), out); + nested(by_mut(&mut gaps), out); + let mut it = data.iter(); + push(borrowed(&mut it).copied(), out); + push(borrowed(&mut it).copied(), out); + push(second_of(data).copied(), out); + push(from_one(n as u8), out); + let mut peekable = data.iter().copied().peekable(); + push(peeked(&mut peekable).copied(), out); + push(at(data, n).copied(), out); + let maybes: Vec> = data.iter().map(maybe).collect(); + nested(at(&maybes, n).copied(), out); +} + +fn first(mut it: I) -> Option { + it.next() +} + +fn back(mut it: I) -> Option { + it.next_back() +} + +fn nth(mut it: I, n: usize) -> Option { + it.nth(n) +} + +fn last(it: I) -> Option { + it.last() +} + +/// Through a `&mut` to the iterator. +fn by_mut(it: &mut I) -> Option { + it.next() +} + +/// Through a borrow of a std iterator the function is not generic over. +fn borrowed<'a>(it: &mut std::slice::Iter<'a, u8>) -> Option<&'a u8> { + it.next() +} + +/// Of a slice's iterator the function makes. +fn second_of(data: &[u8]) -> Option<&u8> { + let mut it = data.iter(); + it.next(); + it.next() +} + +/// Of a small range the function makes. +fn from_one(n: u8) -> Option { + let mut range = 1..n; + range.next() +} + +fn peeked(it: &mut std::iter::Peekable) -> Option<&I::Item> { + it.peek() +} + +fn at(items: &[T], i: usize) -> Option<&T> { + items.get(i) +} diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index e0ae013af..f3917655a 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -1087,7 +1087,9 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let Some(local) = destination.as_local() else { continue; }; - if crate::lower::iter::is_next(tcx, def_id) && self.defs[local] == 1 { + // The return place leaves as the `Option` the signature declares, unless this is a + // `next` itself, which returns the protocol's item or `rt.DONE` below. + if crate::lower::iter::is_next(tcx, def_id) && self.defs[local] == 1 && local != mir::RETURN_PLACE { nexts.push((local, gargs.skip_binder().type_at(0))); } if crate::lower::library::key(tcx, def_id).is_some_and(|(o, n)| o == "Try" && n == "branch") @@ -1129,7 +1131,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { continue; } self.next_results.insert(to); - } else if local != mir::RETURN_PLACE && small_range(tcx, iter_ty) { + } else if small_range(tcx, iter_ty) { self.range_nexts.insert(local); } self.next_results.insert(local); From b524ab60a739af404c530d5f1bcb237923b4b939 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:26:19 -0700 Subject: [PATCH 3/3] test(ts): refuse a returned next of another crate's trait object at its call Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/reject/census.md | 21 +++++++++++---------- ts/fixtures/reject/expected.txt | 1 + 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index a46d31dbc..f5a5be6da 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,6 +1,6 @@ # Census of `reject-fixture` -- Refusals: 99 +- Refusals: 100 - Function instances: 115 - Generic functions no instance reached, lowered over their type parameters: 7 @@ -17,6 +17,7 @@ | 3 | unsupported type `_` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | fixtures/reject/src/lib.rs:16:15 | | 2 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | fixtures/reject/src/lib.rs:250:16 | +| 2 | `_`, a trait object of another crate's trait, which is not supported yet | fixtures/reject/src/lib.rs:11:16 | | 2 | `_`, a trait object of the generic trait `_`, which is not supported yet | fixtures/reject/src/lib.rs:518:23 | | 2 | a coercion to `_`, which is not supported yet | fixtures/reject/src/lib.rs:509:40 | | 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:169:1 | @@ -36,7 +37,6 @@ | 1 | `_` of `_`, which is not supported yet | fixtures/reject/src/lib.rs:599:4 | | 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:321:2 | | 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | fixtures/reject/src/lib.rs:575:12 | -| 1 | `_`, a trait object of another crate's trait, which is not supported yet | fixtures/reject/src/lib.rs:11:16 | | 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:297:9 | | 1 | `_`, which reads a capacity that depends on whether the other handles of its storage dropped, which is not supported | fixtures/reject/src/lib.rs:437:6 | | 1 | `f64::mul_add`, which rounds once, where JS would round twice | fixtures/reject/src/lib.rs:488:4 | @@ -92,6 +92,7 @@ The type or module each refused type or path belongs to. | 2 | `Scaled` | fixtures/reject/src/lib.rs:518:23 | | 2 | `dyn Scaled` | fixtures/reject/src/lib.rs:518:23 | | 2 | `dyn std::any::Any` | fixtures/reject/src/lib.rs:593:32 | +| 2 | `dyn std::iter::Iterator` | fixtures/reject/src/lib.rs:11:16 | | 2 | `std::any::TypeId` | fixtures/reject/src/lib.rs:599:2 | | 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:53:13 | | 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:250:16 | @@ -122,7 +123,6 @@ The type or module each refused type or path belongs to. | 1 | `Waiting` | fixtures/reject/src/lib.rs:556:2 | | 1 | `[u8; 4]` | fixtures/reject/src/lib.rs:535:26 | | 1 | `dyn Keyed` | fixtures/reject/src/lib.rs:593:32 | -| 1 | `dyn std::iter::Iterator` | fixtures/reject/src/lib.rs:11:16 | | 1 | `f64` | fixtures/reject/src/lib.rs:493:2 | | 1 | `into_keys` | fixtures/reject/src/lib.rs:53:13 | | 1 | `poll` | fixtures/reject/src/lib.rs:556:2 | @@ -150,6 +150,7 @@ The type or module each refused type or path belongs to. | 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:385:2 | | 3 | unsupported type `_` | `f32` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | `Option` | fixtures/reject/src/lib.rs:16:15 | +| 2 | `_`, a trait object of another crate's trait, which is not supported yet | `dyn std::iter::Iterator` | fixtures/reject/src/lib.rs:11:16 | | 2 | `_`, a trait object of the generic trait `_`, which is not supported yet | `dyn Scaled`, `Scaled` | fixtures/reject/src/lib.rs:518:23 | | 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:126:2 | | 2 | replacing the value behind a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:110:2 | @@ -171,7 +172,6 @@ The type or module each refused type or path belongs to. | 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::filter` | fixtures/reject/src/lib.rs:250:16 | | 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:321:2 | | 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::sync::Mutex::get_mut` | fixtures/reject/src/lib.rs:575:12 | -| 1 | `_`, a trait object of another crate's trait, which is not supported yet | `dyn std::iter::Iterator` | fixtures/reject/src/lib.rs:11:16 | | 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:297:9 | | 1 | `_`, which reads a capacity that depends on whether the other handles of its storage dropped, which is not supported | `BytesMut::capacity` | fixtures/reject/src/lib.rs:437:6 | | 1 | a `zip` of `_` and `_`, which std reads by index, of items that drop, which is not supported yet | `std::iter::Map`, `std::ops::Range` | fixtures/reject/src/lib.rs:231:30 | @@ -315,6 +315,13 @@ The type or module each refused type or path belongs to. +
`_`, a trait object of another crate's trait, which is not supported yet (2) + +- fixtures/reject/src/lib.rs:11:16: `dyn std::iter::Iterator`, a trait object of another crate's trait, which is not supported yet +- fixtures/reject/src/lib.rs:12:4: `dyn std::iter::Iterator`, a trait object of another crate's trait, which is not supported yet + +
+
`_`, a trait object of the generic trait `_`, which is not supported yet (2) - fixtures/reject/src/lib.rs:518:23: `dyn Scaled`, a trait object of the generic trait `Scaled`, which is not supported yet @@ -435,12 +442,6 @@ The type or module each refused type or path belongs to.
-
`_`, a trait object of another crate's trait, which is not supported yet (1) - -- fixtures/reject/src/lib.rs:11:16: `dyn std::iter::Iterator`, a trait object of another crate's trait, which is not supported yet - -
-
`_`, which is not supported yet (1) - fixtures/reject/src/lib.rs:297:9: `Hasher::write`, which is not supported yet diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 6891e21fc..747c80ea8 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -7,6 +7,7 @@ a scalar constant of type `f32` at fixtures/reject/src/lib.rs:8:2 arithmetic on `f32` at fixtures/reject/src/lib.rs:8:2 unsupported type `f32` at fixtures/reject/src/lib.rs:7:25 `dyn std::iter::Iterator`, a trait object of another crate's trait, which is not supported yet at fixtures/reject/src/lib.rs:11:16 +`dyn std::iter::Iterator`, a trait object of another crate's trait, which is not supported yet at fixtures/reject/src/lib.rs:12:4 `Option>>` is not supported: its `None` and `Some` would both be `rt.None` at fixtures/reject/src/lib.rs:17:2 `Option>>` is not supported: its `None` and `Some` would both be `rt.None` at fixtures/reject/src/lib.rs:16:15 unsupported call to `core::slice::::rotate_left` at fixtures/reject/src/lib.rs:21:4