diff --git a/quest/m2/README.md b/quest/m2/README.md index 14ab2f892..5e8ee43bb 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -32,7 +32,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md); - [Drop in the TypeScript translator](/quest/m2/ts-drop.md) - every value that drops in moq-net and kio drops where Rust drops it - [Async in the TypeScript translator](/quest/m2/ts-async.md) - moq-net's and kio's async code translates with Rust's lazy futures - [Shared ownership](/quest/m2/ts-shared.md) - `Arc`/`Rc`/`Weak` keep exact counts, and locks and atomics become plain values -- [Translate char and vec![x]](/quest/m2/ts-char-vec.md) - `char` values and `vec![x]` translate, unblocking moq-net's refused sites - [Firefox in the TS benchmark](/quest/m2/ts-bench-firefox.md) - SpiderMonkey joins Chrome, Bun, and Node in `just ts bench` - [Translate moq-net's model to TypeScript](/quest/m2/ts-model.md) - the driver grows from moq-net's codec to its model, for moq to compare against WASM - [Symlinked paths](/quest/m2/uniffi-symlink-path.md) - the fork builds when a consumer reaches it through a symlink, as on macOS's `/var` diff --git a/quest/m2/ts-char-vec.md b/quest/m2/ts-char-vec.md deleted file mode 100644 index 6bfbbb53e..000000000 --- a/quest/m2/ts-char-vec.md +++ /dev/null @@ -1,21 +0,0 @@ -# [S] Translate char and vec![x] - -## Goal - -rust2-ts translates `char` values and `vec![x]` on the pinned nightly, proven by -differential tests against native Rust, which unblocks moq-net's 6 refused `char` -switches and 17 refused `vec![x]` sites. - -## Plan - -Decided with the maintainer on 2026-10-26, from -[#78](https://github.com/kixelated/rust2/pull/78)'s census. - -- **`char`:** a number holding the Unicode scalar value, so it switches, compares, - and orders like Rust's. Conversions keep Rust's rules: `as u8` truncates, - `char::from_u32` rejects surrogates and values past `0x10FFFF`, and formatting - writes UTF-8 or UTF-16 as the target needs. -- **`vec![x]`:** lower the nightly's expansion (`from_elem` or the boxed-slice - route), including `vec![x; n]` with `Clone` semantics for each element. - -Public API: the translator's output. diff --git a/ts/README.md b/ts/README.md index 77230df98..fb5a6c960 100644 --- a/ts/README.md +++ b/ts/README.md @@ -56,6 +56,7 @@ runtime: what std does that JS does not, with iterators in `rt/iter.ts`, collect | Rust | TypeScript | | --- | --- | | `bool`, `str`, `String` | `boolean`, `string` | +| `char` | `rt.char`: a `number` branded so, its Unicode scalar value | | `u8`-`u32`, `i8`-`i32`, `usize`, `isize` | `rt.u8` and so on: a `number` branded with its type, checked: overflow panics | | `u64`, `i64`, `u128`, `i128` | `rt.u64` and so on: a branded `number` while a safe integer, 32-bit limbs past 2^53, checked the same way | | `struct` | a plain object, typed by an interface; a class if it may drop | @@ -105,9 +106,9 @@ runtime ports `core::fmt`, so the text matches native Rust's byte for byte. A pl becomes a function writing its value, and `fmt::Arguments` an array of literal pieces and such functions: `rt.fmtWriteFmt(f, ["code=", (f) => rt.u16Display(code, f)])`. A `&dyn Debug` or `&dyn Display` is such a function too. Format specs take fill, alignment, -width, `#`, `0`, `x`, `X`, and `?`. `Debug` of a string escapes by the JS engine's -Unicode tables, so a character newer than its Unicode version is escaped where Rust -prints it. A caller prints a `printable` type as `to_string()` and `format!("{err:?}")` +width, `#`, `0`, `x`, `X`, and `?`. `Debug` of a string or `char` escapes by the JS +engine's Unicode tables, so a character newer than its Unicode version is escaped where +Rust prints it. A caller prints a `printable` type as `to_string()` and `format!("{err:?}")` would: `rt.fmtToString((f) => DecodeError.fmt$Display(err, f))` and `rt.fmtFormat([(f) => DecodeError.fmt$Debug(err, f)])`, after `import * as DecodeError from "./coding/decode.DecodeError.ts"`. @@ -283,7 +284,7 @@ bind to hand-written TS through config ([model](/quest/m2/ts-model.md)). ## Not yet -These fail translation: floats, `char`, statics, async blocks that borrow a number +These fail translation: floats, statics, async blocks that borrow a number mutably and async closures, values that drop in a closure dropped without a call that takes it, in an iterator, in an enum or generic `Drop` type, passed to a std function that may discard them (`unwrap_or`), borrowed in an `Arc` or `Mutex`, or in a @@ -319,10 +320,11 @@ built natively for wasm32 and run beside its translation on the same inputs by `bench::run` and then with it as the first root, which must keep every line in order. Bun bundles a caller of `Decoder.u8` and `Decoder.new` through `import * as Decoder`, which must keep only those and what they call. -- `lang` covers every integer width's arithmetic and casts, control flow, patterns, - `Copy` aggregates, formatting, methods on generic types, iterators, with closures - that log what each adaptor reads, and std's collections, over keys whose own `Hash`, - `Eq`, and `Ord` disagree with JS's. Its differential test runs through `caller.ts`, a +- `lang` covers every integer width's arithmetic and casts, `char`s next to each + encoding's edges and the surrogates, control flow, patterns, `Copy` aggregates, + formatting, methods on generic types, iterators, with closures that log what each + adaptor reads, and std's collections, over keys whose own `Hash`, `Eq`, and `Ord` + disagree with JS's, and `vec![x; n]` of types whose `Clone` counts its clones. Its differential test runs through `caller.ts`, a hand-written caller that also prints a `printable` error nothing translated prints, and adds every 64- and 128-bit case over each pair of values next to a power of two, where the runtime switches between numbers and limbs, and its limbs carry and borrow, diff --git a/ts/fixtures/lang/expected/chars.ts b/ts/fixtures/lang/expected/chars.ts new file mode 100644 index 000000000..5b36bf8a6 --- /dev/null +++ b/ts/fixtures/lang/expected/chars.ts @@ -0,0 +1,165 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import { put } from "./fmt.ts"; + +/** The scalars to try: the edges, then each big-endian `u32` in `data`, zero-padded. */ +export function scalars(data: Uint8Array): rt.u32[] { + const all: rt.u32[] = [0, 127, 128, 255, 256, 2047, 2048, 55295, 55296, 56319, 56320, 57343, 57344, 65533, 65535, 65536, 1114109, 1114111, 1114112, 4294967295].slice(); + let rest: Uint8Array = data; + while (true) { + if (!((rest.length === 0))) { + const buf: Uint8Array = rt.bytes(4); + const n: rt.usize = rt.min(rest.length, 4); + const _13: Uint8Array = rt.sliceRange(buf, 0, n); + const _17: Uint8Array = rest; + rt.sliceCopyFromSlice(_13, rt.sliceRange(_17, 0, n)); + all.push(rt.u32FromBeBytes(buf)); + const _24: Uint8Array = rest; + rest = rt.sliceRange(_24, n); + } else { + return all; + } + } +} + +/** A char's class, by a switch on its value and ranges of it. */ +export function class_(c: rt.char): rt.u8 { + b1: { + if (c === 0) { + return 0; + } + if (c !== 95) { + if (c === 47 || c === 92) { + return 4; + } + if (97 <= c) { + if (c <= 122) { + return 1; + } + } + if (65 <= c) { + if (c <= 90) { + break b1; + } + } + if (48 <= c) { + if (c <= 57) { + return 3; + } + } + if (128 <= c) { + if (c <= 2047) { + return 5; + } + } + if (57344 <= c) { + if (c <= 63743) { + return 6; + } + } + if (!(65536 <= c)) { + return 8; + } + return 7; + } + } + return 2; +} + +export function chars(kind: rt.u8, data: Uint8Array, out: rt.ByteVec): void { + const _4: rt.u8 = rt.u8Rem(kind, 4); + if (_4 === 0) { + const iterS: rt.u32[] = scalars(data); + let iterI: number = 0; + while (true) { + const _10: rt.u32 | rt.Done = iterI < iterS.length ? iterS[iterI++] : rt.DONE; + if (_10 === rt.DONE) { + break; + } + const _14: rt.char | undefined = rt.charFromU32(_10); + if (_14 === undefined) { + rt.byteVecPush(out, 255); + } else { + const c: rt.char = _14; + rt.byteVecPush(out, class_(c)); + rt.byteVecExtendFromSlice(out, rt.u32ToBeBytes(c as rt.u32)); + } + } + } else if (_4 === 1) { + const iterS2: rt.u32[] = scalars(data); + let iterI2: number = 0; + while (true) { + const _27: rt.u32 | rt.Done = iterI2 < iterS2.length ? iterS2[iterI2++] : rt.DONE; + if (_27 === rt.DONE) { + break; + } + const n2: rt.u32 = _27; + const c2: rt.char = rt.optionUnwrapOr(rt.charFromU32(n2), (n2 & 0xff) as rt.char); + rt.byteVecPush(out, c2 & 0xff); + rt.byteVecExtendFromSlice(out, rt.u16ToBeBytes(c2 & 0xffff)); + rt.byteVecPush(out, ((c2 << 24) >> 24) & 0xff); + rt.byteVecExtendFromSlice(out, rt.i16ToBeBytes((c2 << 16) >> 16)); + rt.byteVecExtendFromSlice(out, rt.i32ToBeBytes(c2 as rt.i32)); + rt.byteVecExtendFromSlice(out, rt.u64ToBeBytes(c2 as rt.u64)); + rt.byteVecExtendFromSlice(out, rt.i128ToBeBytes(c2 as rt.i128)); + rt.byteVecPush(out, ((n2 & 0xff) as rt.char) & 0xff); + rt.byteVecExtendFromSlice(out, rt.u16ToBeBytes(((c2 as rt.u32) & 0xff) as rt.u16)); + } + } else if (_4 === 2) { + const cs: rt.char[] = rt.iterToArray(rt.iterFilterMap(rt.iterSlice(scalars(data)), (a0: rt.u32): rt.char | undefined => { + return rt.charFromU32(a0); + })); + const sorted: rt.BTreeSet = rt.btreeNew(rt.cmp) as rt.BTreeSet; + const seen: rt.HashSet = rt.hashNew() as rt.HashSet; + const iter3: rt.Iter<[rt.usize, rt.char]> = rt.iterEnumerate(rt.iterSlice(cs)); + while (true) { + const _88: [rt.usize, rt.char] | rt.Done = iter3.next(); + if (_88 === rt.DONE) { + break; + } + const i: rt.usize = _88[0]; + const c3: rt.char = _88[1]; + const _96: rt.usize = rt.usizeRem(rt.usizeAdd(rt.usizeMul(i, 7), 3), cs.length); + const at = rt.idx(cs, _96); + const d: rt.char = cs[at]; + rt.byteVecPush(out, (c3 < d ? 1 : 0) | (((c3 === d ? 1 : 0) << 1) & 0xff) | (((c3 >= 122 ? 1 : 0) << 2) & 0xff)); + rt.byteVecPush(out, rt.hashAdd(seen, c3) ? 1 : 0); + rt.btreeAdd(sorted, c3); + } + const iter4: rt.Iter = rt.btreeKeys(sorted); + while (true) { + const _128: rt.char | rt.Done = iter4.next(); + if (_128 === rt.DONE) { + break; + } + rt.byteVecExtendFromSlice(out, rt.u32ToBeBytes(_128 as rt.u32)); + } + } else { + const iterS3: rt.u32[] = scalars(data); + let iterI3: number = 0; + while (true) { + const _140: rt.u32 | rt.Done = iterI3 < iterS3.length ? iterS3[iterI3++] : rt.DONE; + if (_140 === rt.DONE) { + break; + } + const _144: rt.char | undefined = rt.charFromU32(_140); + if (_144 !== undefined) { + const arg = ([_144] as [rt.char])[0]; + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtCharDisplay(arg, f)]; + put(out, rt.fmtFormat([args2[0], "|", rt.fmtSpec({ align: ">", width: 3 }, args2[0]), "|", rt.fmtSpec({ fill: "*", align: "^", width: 4 }, args2[0]), "|", rt.fmtSpec({ align: "<", width: 2 }, args2[0])])); + } + } + const iter6: rt.Iter = rt.iterSlice([97, 39, 34, 92, 10, 0, 127, 233, 769, 173, 57344, 128512, 65438, 65439, 4447, 4448, 12644, 65440]); + while (true) { + const _161: rt.char | rt.Done = iter6.next(); + if (_161 === rt.DONE) { + break; + } + const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtCharDebug(_161, f), (f: rt.Formatter) => rt.fmtCharDisplay(_161, f)]; + put(out, rt.fmtFormat([args4[0], "|", rt.fmtSpec({ align: ">", width: 6 }, args4[0]), "|", args4[1]])); + } + } +} + +//# sourceMappingURL=chars.ts.map diff --git a/ts/fixtures/lang/expected/collections.Cloned.ts b/ts/fixtures/lang/expected/collections.Cloned.ts new file mode 100644 index 000000000..3331d4d0c --- /dev/null +++ b/ts/fixtures/lang/expected/collections.Cloned.ts @@ -0,0 +1,18 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +/** + * A value that counts how far it is cloned from the one `vec!` was given, which + * `vec![x; n]` clones for every element but the last, which is `x` itself. + */ +export interface Cloned { + depth: rt.u8; + name: string; +} + +export function clone$Clone(self: Cloned): Cloned { + return { depth: rt.u8Add(self.depth, 1), name: self.name }; +} + +//# sourceMappingURL=collections.Cloned.ts.map diff --git a/ts/fixtures/lang/expected/collections.ts b/ts/fixtures/lang/expected/collections.ts index 29c5762fc..a2e86b57a 100644 --- a/ts/fixtures/lang/expected/collections.ts +++ b/ts/fixtures/lang/expected/collections.ts @@ -1,14 +1,16 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { copy$Clash, copy$Rank, copy$Tally, copy$u8_Tally } from "./lib.ts"; +import { copy$Bumped, copy$Clash, copy$Rank, copy$Tally, copy$u8_Tally, copy$u8_u16, copy$u8_u8 } from "./lib.ts"; import * as Clash from "./collections.Clash.ts"; +import * as Cloned from "./collections.Cloned.ts"; import * as Dir from "./collections.Dir.ts"; import * as Fussy from "./collections.Fussy.ts"; import * as Nibble from "./collections.Nibble.ts"; import * as Pair from "./collections.Pair.ts"; import * as Rank from "./collections.Rank.ts"; import * as Tally from "./collections.Tally.ts"; +import * as Bumped from "./iters.Bumped.ts"; /** A 64-bit key: small, or past 2^53, where it is no longer a JS number. */ export function wide(b: rt.u8): rt.u64 { @@ -1015,4 +1017,88 @@ export function deques(data: Uint8Array, out: rt.ByteVec): void { rt.byteVecPush(out, rt.dequeIndex(q2, b2)); } +/** `vec![a, b]` and `vec![x; n]`, of bytes, numbers, `Copy` tuples, and types that clone. */ +export function vecs(data: Uint8Array, out: rt.ByteVec): void { + let name!: string; + const a: rt.u8 = rt.optionUnwrapOr(rt.sliceFirst(data), 0); + const b: rt.u8 = rt.optionUnwrapOr(rt.sliceGet(data, 1), 0); + const n: rt.usize = rt.usizeRem(rt.optionUnwrapOr(rt.sliceGet(data, 2), 0) as rt.usize, 5); + const _16: rt.Result = rt.stringFromUtf8(rt.sliceToByteVec(data)); + if (_16.ok) { + const s: string = _16.value; + name = s; + } else { + name = "?"; + } + rt.byteVecExtendFromSlice(out, rt.byteVecView(rt.byteVecFrom(Uint8Array.of(a, b, 66)))); + const pairs: [rt.u8, rt.u16][] = [[a, b as rt.u16] as [rt.u8, rt.u16]].map(copy$u8_u16); + pairs.push([b, a as rt.u16] as [rt.u8, rt.u16]); + const at = rt.idx(pairs, 0); + pairs[at][0] = pairs[at][0] ^ 255; + const iterS: [rt.u8, rt.u16][] = pairs; + let iterI: number = 0; + while (true) { + const _39: [rt.u8, rt.u16] | rt.Done = iterI < iterS.length ? iterS[iterI++] : rt.DONE; + if (_39 === rt.DONE) { + break; + } + rt.byteVecPush(out, _39[0] ^ (_39[1] & 0xff)); + } + rt.byteVecPush(out, [name, "x", name].length & 0xff); + const one: Cloned.Cloned[] = [{ depth: a, name: name }]; + const at2 = rt.idx(one, 0); + rt.byteVecPush(out, one[at2].depth); + rt.byteVecExtendFromSlice(out, rt.byteVecView(rt.byteVecOf(b, n))); + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(rt.vecFromElem(rt.u16Mul(a as rt.u16, 257), n, undefined)), (w: rt.u16): rt.u8 => { + return rt.u16Shr(w, 4) & 0xff; + })); + const tuples: [rt.u8, rt.u8][] = rt.vecFromElem(copy$u8_u8([a, b] as [rt.u8, rt.u8]), n, copy$u8_u8); + if (n > 0) { + const at3 = rt.idx(tuples, 0); + tuples[at3][0] = 238; + } + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(tuples), (t: [rt.u8, rt.u8]): rt.u8 => { + return t[0] ^ t[1]; + })); + rt.byteVecPush(out, rt.vecFromElem(name, n, undefined).length & 0xff); + const cloned: Cloned.Cloned[] = rt.vecFromElem({ depth: 0, name }, n, Cloned.clone$Clone); + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(cloned), (c: Cloned.Cloned): rt.u8 => { + return c.depth; + })); + const _113: rt.Iter = rt.iterSlice(cloned); + rt.byteVecPush(out, rt.iterAll(_113, (c2: Cloned.Cloned): boolean => { + return rt.stringLen(c2.name) === data.length; + }) ? 1 : 0); + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(rt.vecFromElem(copy$Bumped({ _0: b }), n, Bumped.clone$Clone)), (o: Bumped.Bumped): rt.u8 => { + return o._0; + })); + const pair: [rt.u8, rt.u8] = [a, b]; + const held: Bumped.Bumped = { _0: a }; + const listed: [rt.u8, rt.u8][] = [pair, pair].map(copy$u8_u8); + const at4 = rt.idx(listed, 0); + listed[at4][0] = listed[at4][0] ^ 255; + const repeated: [rt.u8, rt.u8][] = rt.vecFromElem(copy$u8_u8(pair), n, copy$u8_u8); + const again: [rt.u8, rt.u8][] = rt.vecFromElem(copy$u8_u8(pair), n, copy$u8_u8); + const bumps: Bumped.Bumped[] = rt.vecFromElem(copy$Bumped(held), n, Bumped.clone$Clone); + const kept: Bumped.Bumped[] = rt.vecFromElem(copy$Bumped(held), n, Bumped.clone$Clone); + if (n > 0) { + const _137: rt.usize = rt.usizeSub(n, 1); + const at5 = rt.idx(repeated, _137); + repeated[at5][1] = repeated[at5][1] ^ 255; + const _141: rt.usize = rt.usizeSub(n, 1); + const at6 = rt.idx(bumps, _141); + bumps[at6]._0 = bumps[at6]._0 ^ 255; + } + const _147: rt.u8 = a; + const _148: rt.u8 = b; + const at7 = rt.idx(listed, 1); + rt.byteVecExtendFromSlice(out, Uint8Array.of(_147, _148, listed[at7][0], a)); + rt.iterExtendBytes(out, rt.iterMap(rt.iterChain(rt.iterSlice(repeated), rt.iterSlice(again)), (t2: [rt.u8, rt.u8]): rt.u8 => { + return t2[1]; + })); + rt.iterExtendBytes(out, rt.iterMap(rt.iterChain(rt.iterSlice(bumps), rt.iterSlice(kept)), (o2: Bumped.Bumped): rt.u8 => { + return o2._0; + })); +} + //# sourceMappingURL=collections.ts.map diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 4abae8dd5..5816022d6 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -1,7 +1,8 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { hashMaps, sets, btreeMaps, deques } from "./collections.ts"; +import { chars } from "./chars.ts"; +import { hashMaps, sets, btreeMaps, deques, vecs } from "./collections.ts"; import { ints, strings, derived, written, panics } from "./fmt.ts"; import { methods } from "./generics.ts"; import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast, convert } from "./ints.ts"; @@ -18,7 +19,7 @@ export function run(input: Uint8Array): rt.ByteVec { const _10: [rt.u8, rt.u8] = [input[0], input[1]]; const op: rt.u8 = _10[0]; const kind: rt.u8 = _10[1]; - const _14: rt.u8 = rt.u8Rem(op, 40); + const _14: rt.u8 = rt.u8Rem(op, 42); if (_14 === 0) { u8Op(kind, input.subarray(2, input.length - 0), out); } else if (_14 === 1) { @@ -115,8 +116,12 @@ export function run(input: Uint8Array): rt.ByteVec { deques(input.subarray(2, input.length - 0), out); } else if (_14 === 38) { flows(input.subarray(2, input.length - 0), out); - } else { + } else if (_14 === 39) { keys(kind, input.subarray(2, input.length - 0), out); + } else if (_14 === 40) { + chars(kind, input.subarray(2, input.length - 0), out); + } else { + vecs(input.subarray(2, input.length - 0), out); } return out; } diff --git a/ts/fixtures/lang/expected/iters.ts b/ts/fixtures/lang/expected/iters.ts index 37199d91e..d88607685 100644 --- a/ts/fixtures/lang/expected/iters.ts +++ b/ts/fixtures/lang/expected/iters.ts @@ -285,7 +285,7 @@ export function consumers(kind: rt.u8, data: Uint8Array, out: rt.ByteVec): void rt.byteVecExtendFromSlice(out, rt.u32ToBeBytes(rt.iterFold(rt.iterSlice(data), 0, (acc: rt.u32, _34: rt.u8): rt.u32 => { const b8: rt.u8 = _34; const _510: rt.u32 = (acc << 3) >>> 0; - return rt.u32WrappingAdd(_510, (b8 as rt.u32 ^ acc) >>> 0); + return rt.u32WrappingAdd(_510, ((b8 as rt.u32) ^ acc) >>> 0); }))); rt.iterForEach(rt.iterSlice(data), (_216: rt.u8): void => { rt.byteVecPush(log, rotateFree$RotateFree_u8(_216)); diff --git a/ts/fixtures/lang/expected/lib.ts b/ts/fixtures/lang/expected/lib.ts index 64b392a6f..626711d8d 100644 --- a/ts/fixtures/lang/expected/lib.ts +++ b/ts/fixtures/lang/expected/lib.ts @@ -135,6 +135,10 @@ export function copy$u8_Tally(v: [rt.u8, Tally.Tally]): [rt.u8, Tally.Tally] { return [v[0], copy$Tally(v[1])]; } +export function copy$u8_u16(v: [rt.u8, rt.u16]): [rt.u8, rt.u16] { + return [v[0], v[1]]; +} + export function copy$u8_u8(v: [rt.u8, rt.u8]): [rt.u8, rt.u8] { return [v[0], v[1]]; } diff --git a/ts/fixtures/lang/src/chars.rs b/ts/fixtures/lang/src/chars.rs new file mode 100644 index 000000000..3f7b37d34 --- /dev/null +++ b/ts/fixtures/lang/src/chars.rs @@ -0,0 +1,125 @@ +//! `char`: a Unicode scalar value, switched on, ordered, converted, and printed. + +use std::collections::{BTreeSet, HashSet}; + +use crate::fmt::put; + +/// Values next to where a scalar's UTF-8 or UTF-16 length changes, the surrogates that +/// are no char, and past the last char. +const EDGES: [u32; 20] = [ + 0, + 0x7f, + 0x80, + 0xff, + 0x100, + 0x7ff, + 0x800, + 0xd7ff, + 0xd800, + 0xdbff, + 0xdc00, + 0xdfff, + 0xe000, + 0xfffd, + 0xffff, + 0x10000, + 0x10fffd, + 0x10ffff, + 0x110000, + u32::MAX, +]; + +/// Chars `Debug` escapes, or writes as they are. The halfwidth katakana marks extend +/// graphemes but print; the Hangul fillers are default-ignorable. +const SHOWN: [char; 18] = [ + 'a', '\'', '"', '\\', '\n', '\0', '\u{7f}', 'é', '\u{301}', '\u{ad}', '\u{e000}', '😀', '\u{ff9e}', '\u{ff9f}', + '\u{115f}', '\u{1160}', '\u{3164}', '\u{ffa0}', +]; + +/// The scalars to try: the edges, then each big-endian `u32` in `data`, zero-padded. +fn scalars(data: &[u8]) -> Vec { + let mut all = EDGES.to_vec(); + let mut rest = data; + while !rest.is_empty() { + let mut buf = [0u8; 4]; + let n = rest.len().min(4); + buf[..n].copy_from_slice(&rest[..n]); + all.push(u32::from_be_bytes(buf)); + rest = &rest[n..]; + } + all +} + +/// A char's class, by a switch on its value and ranges of it. +fn class(c: char) -> u8 { + match c { + '\0' => 0, + 'a'..='z' => 1, + 'A'..='Z' | '_' => 2, + '0'..='9' => 3, + '/' | '\\' => 4, + '\u{80}'..='\u{7ff}' => 5, + '\u{e000}'..='\u{f8ff}' => 6, + '\u{10000}'.. => 7, + _ => 8, + } +} + +pub fn chars(kind: u8, data: &[u8], out: &mut Vec) { + match kind % 4 { + 0 => { + for n in scalars(data) { + match char::from_u32(n) { + Some(c) => { + out.push(class(c)); + out.extend_from_slice(&u32::from(c).to_be_bytes()); + } + None => out.push(0xff), + } + } + } + 1 => { + // Casts truncate, as `as` does, and widen. + for n in scalars(data) { + let c = char::from_u32(n).unwrap_or(char::from(n as u8)); + out.push(c as u8); + out.extend_from_slice(&(c as u16).to_be_bytes()); + out.push(c as i8 as u8); + out.extend_from_slice(&(c as i16).to_be_bytes()); + out.extend_from_slice(&(c as i32).to_be_bytes()); + out.extend_from_slice(&(c as u64).to_be_bytes()); + out.extend_from_slice(&(c as i128).to_be_bytes()); + out.push((n as u8 as char) as u8); + // A cast of a cast, whose `as` must not read on into the mask. + out.extend_from_slice(&(c as u32 as u8 as u16).to_be_bytes()); + } + } + 2 => { + // Ordered and equal as their values, and as keys. + let cs: Vec = scalars(data).into_iter().filter_map(char::from_u32).collect(); + let mut sorted = BTreeSet::new(); + let mut seen = HashSet::new(); + for (i, &c) in cs.iter().enumerate() { + let d = cs[(i * 7 + 3) % cs.len()]; + out.push((c < d) as u8 | ((c == d) as u8) << 1 | ((c >= 'z') as u8) << 2); + out.push(seen.insert(c) as u8); + sorted.insert(c); + } + for c in sorted { + out.extend_from_slice(&(c as u32).to_be_bytes()); + } + } + _ => { + // `Display` writes the char, padded only with a width; `Debug` escapes it and + // ignores the width. + for n in scalars(data) { + if let Some(c) = char::from_u32(n) { + put(out, &format!("{c}|{c:>3}|{c:*^4}|{c:<2}")); + } + } + for c in SHOWN { + put(out, &format!("{c:?}|{c:>6?}|{c}")); + } + } + } +} diff --git a/ts/fixtures/lang/src/collections.rs b/ts/fixtures/lang/src/collections.rs index 10cab499e..e96042b47 100644 --- a/ts/fixtures/lang/src/collections.rs +++ b/ts/fixtures/lang/src/collections.rs @@ -7,6 +7,8 @@ use std::cmp::Ordering; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque, btree_map, hash_map}; use std::hash::{DefaultHasher, Hash, Hasher}; +use crate::iters::Bumped; + /// A key whose `Eq`, `Hash`, and `Ord` see only its low nibble, so two keys can be equal /// while their bytes differ, and which sorts by that nibble, descending. #[derive(Clone, Copy)] @@ -661,3 +663,80 @@ pub fn deques(data: &[u8], out: &mut Vec) { out.extend(q.iter()); out.push(q[b]); } + +/// A value that counts how far it is cloned from the one `vec!` was given, which +/// `vec![x; n]` clones for every element but the last, which is `x` itself. +struct Cloned { + depth: u8, + name: String, +} + +impl Clone for Cloned { + fn clone(&self) -> Self { + Cloned { + depth: self.depth + 1, + name: self.name.clone(), + } + } +} + +/// `vec![a, b]` and `vec![x; n]`, of bytes, numbers, `Copy` tuples, and types that clone. +pub fn vecs(data: &[u8], out: &mut Vec) { + let a = data.first().copied().unwrap_or(0); + let b = data.get(1).copied().unwrap_or(0); + let n = data.get(2).copied().unwrap_or(0) as usize % 5; + let name = match String::from_utf8(data.to_vec()) { + Ok(s) => s, + Err(_) => "?".to_string(), + }; + + let bytes = vec![a, b, 0x42]; + out.extend_from_slice(&bytes); + let mut pairs = vec![(a, b as u16)]; + pairs.push((b, a as u16)); + pairs[0].0 ^= 0xff; + for (x, y) in &pairs { + out.push(x ^ *y as u8); + } + let names = vec![name.clone(), "x".to_string(), name.clone()]; + out.push(names.len() as u8); + let one = vec![Cloned { + depth: a, + name: name.clone(), + }]; + out.push(one[0].depth); + + out.extend_from_slice(&vec![b; n]); + let wide = vec![a as u16 * 0x101; n]; + out.extend(wide.iter().map(|w| (w >> 4) as u8)); + let mut tuples = vec![(a, b); n]; + if n > 0 { + tuples[0].0 = 0xee; + } + out.extend(tuples.iter().map(|t| t.0 ^ t.1)); + let strings = vec![name.clone(); n]; + out.push(strings.len() as u8); + let cloned = vec![Cloned { depth: 0, name }; n]; + out.extend(cloned.iter().map(|c| c.depth)); + out.push(cloned.iter().all(|c| c.name.len() == data.len()) as u8); + // A `Copy` type's own `Clone` runs too. + let bumped = vec![Bumped(b); n]; + out.extend(bumped.iter().map(|o| o.0)); + + // Each element is a copy of what it was given, apart from it and from each other. + let pair = (a, b); + let held = Bumped(a); + let mut listed = vec![pair, pair]; + listed[0].0 ^= 0xff; + let mut repeated = vec![pair; n]; + let again = vec![pair; n]; + let mut bumps = vec![held; n]; + let kept = vec![held; n]; + if n > 0 { + repeated[n - 1].1 ^= 0xff; + bumps[n - 1].0 ^= 0xff; + } + out.extend_from_slice(&[pair.0, pair.1, listed[1].0, held.0]); + out.extend(repeated.iter().chain(&again).map(|t| t.1)); + out.extend(bumps.iter().chain(&kept).map(|o| o.0)); +} diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index effc9f712..39c51e2e7 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -1,7 +1,7 @@ //! The entry point both sides of the differential test run. The first byte picks a //! case and the rest is its input. -use crate::{collections, fmt, generics, ints, iters, keys, shapes}; +use crate::{chars, collections, fmt, generics, ints, iters, keys, shapes}; /// The native side's entry: [`run`], except that a case starting with 0xff prints a /// [`fmt::Fault`], which the translated side prints from TypeScript in `caller.ts`. @@ -19,7 +19,7 @@ pub fn run(input: &[u8]) -> Vec { return out; }; let (op, kind) = (*op, *kind); - match op % 40 { + match op % 42 { 0 => ints::u8_op(kind, data, &mut out), 1 => ints::u16_op(kind, data, &mut out), 2 => ints::u32_op(kind, data, &mut out), @@ -69,7 +69,9 @@ pub fn run(input: &[u8]) -> Vec { 36 => collections::btree_maps(kind, data, &mut out), 37 => collections::deques(data, &mut out), 38 => shapes::flows(data, &mut out), - _ => keys::keys(kind, data, &mut out), + 39 => keys::keys(kind, data, &mut out), + 40 => chars::chars(kind, data, &mut out), + _ => collections::vecs(data, &mut out), } out } diff --git a/ts/fixtures/lang/src/iters.rs b/ts/fixtures/lang/src/iters.rs index be5240292..d63ef607d 100644 --- a/ts/fixtures/lang/src/iters.rs +++ b/ts/fixtures/lang/src/iters.rs @@ -585,7 +585,7 @@ struct Wrapper(T); /// A `Copy` type whose `Clone` does more than copy. #[derive(Copy)] -struct Bumped(u8); +pub struct Bumped(pub u8); impl Clone for Bumped { fn clone(&self) -> Self { diff --git a/ts/fixtures/lang/src/lib.rs b/ts/fixtures/lang/src/lib.rs index 285a39b1c..e87d789aa 100644 --- a/ts/fixtures/lang/src/lib.rs +++ b/ts/fixtures/lang/src/lib.rs @@ -1,10 +1,12 @@ //! The language the driver translates, exercised against native Rust: every integer -//! width's arithmetic and casts, control flow, patterns, `Copy` aggregates, closures, -//! traits, generic types, formatting, collections, and the standard library calls it maps. +//! width's arithmetic and casts, `char`s, control flow, patterns, `Copy` aggregates, +//! closures, traits, generic types, formatting, collections, and the standard library +//! calls it maps. //! //! `harness::run` is the entry point both sides of the differential test run, and //! `fmt::Fault` an error only `caller.ts` prints. +mod chars; mod collections; mod fmt; mod generics; diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index eefcf4f6a..f572dd6a0 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,57 +1,56 @@ # Census of `reject-fixture` -- Refusals: 77 -- Function instances: 65 +- Refusals: 75 +- Function instances: 64 - Generic functions no instance reached, lowered over their type parameters: 3 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 7 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:20:2 | -| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:31:15 | -| 5 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:19:13 | -| 5 | unsupported call to `_` | fixtures/reject/src/lib.rs:36:4 | -| 5 | unsupported type `_` | fixtures/reject/src/lib.rs:6:14 | -| 3 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:59:2 | -| 3 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:123:2 | -| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:149:20 | -| 2 | a field of `_` | fixtures/reject/src/lib.rs:316:7 | -| 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:208:1 | -| 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:194:23 | -| 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:188:2 | -| 2 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:280:4 | -| 1 | `Binary` formatting, as in `{:b}`, is not supported | fixtures/reject/src/lib.rs:100:3 | -| 1 | `LowerExp` formatting, as in `{:e}`, is not supported | fixtures/reject/src/lib.rs:102:3 | -| 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:101:3 | -| 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:105:3 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:326:6 | -| 1 | `_` is generic and implements `Drop`, which is not supported yet | fixtures/reject/src/lib.rs:65:1 | -| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:361:6 | -| 1 | `_` of `_`, which may drop a `_`, which is not supported yet | fixtures/reject/src/lib.rs:344:6 | -| 1 | `_` of `_`, which may drop what it holds, which is not supported yet | fixtures/reject/src/lib.rs:321:6 | -| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:393:2 | -| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | fixtures/reject/src/lib.rs:403:6 | -| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:369:9 | -| 1 | a `_` cast from `_` to `_` | fixtures/reject/src/lib.rs:134:2 | -| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:221:51 | -| 1 | a cast from `_` | fixtures/reject/src/lib.rs:11:2 | -| 1 | a constant of type `_` | fixtures/reject/src/lib.rs:118:2 | -| 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:310:14 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:285:13 | -| 1 | a precision, as in `{:.2}`, is not supported | fixtures/reject/src/lib.rs:97:3 | -| 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:130:1 | +| 7 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:16:2 | +| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:27:15 | +| 5 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:15:13 | +| 5 | unsupported call to `_` | fixtures/reject/src/lib.rs:32:4 | +| 4 | unsupported type `_` | fixtures/reject/src/lib.rs:6:14 | +| 3 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:55:2 | +| 3 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:119:2 | +| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:145:20 | +| 2 | a field of `_` | fixtures/reject/src/lib.rs:312:7 | +| 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:204:1 | +| 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:190:23 | +| 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:184:2 | +| 2 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:276:4 | +| 1 | `Binary` formatting, as in `{:b}`, is not supported | fixtures/reject/src/lib.rs:96:3 | +| 1 | `LowerExp` formatting, as in `{:e}`, is not supported | fixtures/reject/src/lib.rs:98:3 | +| 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:97:3 | +| 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:101:3 | +| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:322:6 | +| 1 | `_` is generic and implements `Drop`, which is not supported yet | fixtures/reject/src/lib.rs:61:1 | +| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:357:6 | +| 1 | `_` of `_`, which may drop a `_`, which is not supported yet | fixtures/reject/src/lib.rs:340:6 | +| 1 | `_` of `_`, which may drop what it holds, which is not supported yet | fixtures/reject/src/lib.rs:317:6 | +| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:389:2 | +| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | fixtures/reject/src/lib.rs:399:6 | +| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:365:9 | +| 1 | a `_` cast from `_` to `_` | fixtures/reject/src/lib.rs:130:2 | +| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:217:51 | +| 1 | a constant of type `_` | fixtures/reject/src/lib.rs:114:2 | +| 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:306:14 | +| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:281:13 | +| 1 | a precision, as in `{:.2}`, is not supported | fixtures/reject/src/lib.rs:93:3 | +| 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:126:1 | | 1 | a scalar constant of type `_` | fixtures/reject/src/lib.rs:7:2 | -| 1 | a width or precision from an argument, as in `{:1$}`, is not supported | fixtures/reject/src/lib.rs:104:3 | -| 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:90:2 | +| 1 | a width or precision from an argument, as in `{:1$}`, is not supported | fixtures/reject/src/lib.rs:100:3 | +| 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:86:2 | | 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:7:2 | -| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:331:52 | -| 1 | dropping `_`, which is not supported yet | fixtures/reject/src/lib.rs:141:1 | -| 1 | dropping a closure that owns a value that drops, which is not supported yet | fixtures/reject/src/lib.rs:54:1 | -| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:331:52 | -| 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:103:3 | -| 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:98:3 | -| 1 | the `-` flag of a format spec is not supported | fixtures/reject/src/lib.rs:99:3 | +| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:327:52 | +| 1 | dropping `_`, which is not supported yet | fixtures/reject/src/lib.rs:137:1 | +| 1 | dropping a closure that owns a value that drops, which is not supported yet | fixtures/reject/src/lib.rs:50:1 | +| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:327:52 | +| 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:99:3 | +| 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:94:3 | +| 1 | the `-` flag of a format spec is not supported | fixtures/reject/src/lib.rs:95:3 | ## By API @@ -59,332 +58,322 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | -| 7 | `Option` | fixtures/reject/src/lib.rs:31:15 | +| 7 | `Option` | fixtures/reject/src/lib.rs:27:15 | | 6 | `f64` | fixtures/reject/src/lib.rs:6:14 | -| 6 | `u8` | fixtures/reject/src/lib.rs:80:10 | -| 4 | `std::sync::Arc` | fixtures/reject/src/lib.rs:141:1 | -| 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:59:2 | -| 4 | `u32` | fixtures/reject/src/lib.rs:19:13 | -| 3 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:321:6 | -| 3 | `std::option::Option` | fixtures/reject/src/lib.rs:280:4 | -| 2 | `HashMap` | fixtures/reject/src/lib.rs:321:6 | -| 2 | `Iterator` | fixtures/reject/src/lib.rs:188:2 | -| 2 | `Meters` | fixtures/reject/src/lib.rs:123:2 | -| 2 | `Poll` | fixtures/reject/src/lib.rs:149:20 | -| 2 | `char` | fixtures/reject/src/lib.rs:10:18 | -| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:165:2 | -| 2 | `std::string::String` | fixtures/reject/src/lib.rs:110:16 | -| 1 | `Boxed` | fixtures/reject/src/lib.rs:65:1 | -| 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:208:1 | -| 1 | `FusedIterator` | fixtures/reject/src/lib.rs:262:1 | -| 1 | `HashSet` | fixtures/reject/src/lib.rs:344:6 | -| 1 | `Hasher` | fixtures/reject/src/lib.rs:369:9 | -| 1 | `IntToFloat` | fixtures/reject/src/lib.rs:134:2 | -| 1 | `Loud` | fixtures/reject/src/lib.rs:344:6 | -| 1 | `Noisy` | fixtures/reject/src/lib.rs:275:20 | -| 1 | `Ord` | fixtures/reject/src/lib.rs:398:4 | -| 1 | `[u8; 1]` | fixtures/reject/src/lib.rs:299:22 | -| 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:14:16 | -| 1 | `std::collections::HashSet` | fixtures/reject/src/lib.rs:344:6 | -| 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:221:51 | -| 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:194:23 | -| 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:215:14 | -| 1 | `std::mem` | fixtures/reject/src/lib.rs:52:18 | -| 1 | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:316:48 | -| 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:316:7 | -| 1 | `std::ops::Range` | fixtures/reject/src/lib.rs:229:8 | -| 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:175:11 | -| 1 | `std::slice` | fixtures/reject/src/lib.rs:36:4 | -| 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:170:2 | -| 1 | `u64` | fixtures/reject/src/lib.rs:134:2 | -| 1 | `{async closure}` | fixtures/reject/src/lib.rs:90:2 | +| 6 | `u8` | fixtures/reject/src/lib.rs:76:10 | +| 4 | `std::sync::Arc` | fixtures/reject/src/lib.rs:137:1 | +| 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:55:2 | +| 4 | `u32` | fixtures/reject/src/lib.rs:15:13 | +| 3 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:317:6 | +| 3 | `std::option::Option` | fixtures/reject/src/lib.rs:276:4 | +| 2 | `HashMap` | fixtures/reject/src/lib.rs:317:6 | +| 2 | `Iterator` | fixtures/reject/src/lib.rs:184:2 | +| 2 | `Meters` | fixtures/reject/src/lib.rs:119:2 | +| 2 | `Poll` | fixtures/reject/src/lib.rs:145:20 | +| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:161:2 | +| 2 | `std::string::String` | fixtures/reject/src/lib.rs:106:16 | +| 1 | `Boxed` | fixtures/reject/src/lib.rs:61:1 | +| 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:204:1 | +| 1 | `FusedIterator` | fixtures/reject/src/lib.rs:258:1 | +| 1 | `HashSet` | fixtures/reject/src/lib.rs:340:6 | +| 1 | `Hasher` | fixtures/reject/src/lib.rs:365:9 | +| 1 | `IntToFloat` | fixtures/reject/src/lib.rs:130:2 | +| 1 | `Loud` | fixtures/reject/src/lib.rs:340:6 | +| 1 | `Noisy` | fixtures/reject/src/lib.rs:271:20 | +| 1 | `Ord` | fixtures/reject/src/lib.rs:394:4 | +| 1 | `[u8; 1]` | fixtures/reject/src/lib.rs:295:22 | +| 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:10:16 | +| 1 | `std::collections::HashSet` | fixtures/reject/src/lib.rs:340:6 | +| 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:217:51 | +| 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:190:23 | +| 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:211:14 | +| 1 | `std::mem` | fixtures/reject/src/lib.rs:48:18 | +| 1 | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:312:48 | +| 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:312:7 | +| 1 | `std::ops::Range` | fixtures/reject/src/lib.rs:225:8 | +| 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:171:11 | +| 1 | `std::slice` | fixtures/reject/src/lib.rs:32:4 | +| 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:166:2 | +| 1 | `u64` | fixtures/reject/src/lib.rs:130:2 | +| 1 | `{async closure}` | fixtures/reject/src/lib.rs:86:2 | ## By type or path | Count | Construct | Type or path | First | | ---: | --- | --- | --- | -| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:31:15 | +| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:27:15 | | 3 | unsupported type `_` | `f64` | fixtures/reject/src/lib.rs:6:14 | -| 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:149:20 | -| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u32`, `u32` | fixtures/reject/src/lib.rs:19:13 | -| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:80:10 | -| 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:165:2 | -| 2 | an assignment through a reference to `_` | `u8` | fixtures/reject/src/lib.rs:81:3 | -| 2 | an iterator that owns `_`, which drops, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:59:2 | -| 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:123:2 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:326:6 | -| 1 | `_` is generic and implements `Drop`, which is not supported yet | `Boxed` | fixtures/reject/src/lib.rs:65:1 | -| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:361:6 | -| 1 | `_` of `_`, which may drop a `_`, which is not supported yet | `HashSet::remove`, `std::collections::HashSet`, `Loud` | fixtures/reject/src/lib.rs:344:6 | -| 1 | `_` of `_`, which may drop what it holds, which is not supported yet | `HashMap::clear`, `std::collections::HashMap` | fixtures/reject/src/lib.rs:321:6 | -| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:393:2 | -| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | `std::option::Option` | fixtures/reject/src/lib.rs:403:6 | -| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:369:9 | -| 1 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut std::string::String`, `std::string::String` | fixtures/reject/src/lib.rs:110:16 | -| 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:134:2 | -| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:221:51 | -| 1 | a cast from `_` | `char` | fixtures/reject/src/lib.rs:11:2 | -| 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:118:2 | -| 1 | a field of `_` | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:316:48 | -| 1 | a field of `_` | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:316:7 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:285:13 | +| 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:145:20 | +| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u32`, `u32` | fixtures/reject/src/lib.rs:15:13 | +| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:76:10 | +| 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:161:2 | +| 2 | an assignment through a reference to `_` | `u8` | fixtures/reject/src/lib.rs:77:3 | +| 2 | an iterator that owns `_`, which drops, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:55:2 | +| 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:119:2 | +| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:322:6 | +| 1 | `_` is generic and implements `Drop`, which is not supported yet | `Boxed` | fixtures/reject/src/lib.rs:61:1 | +| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:357:6 | +| 1 | `_` of `_`, which may drop a `_`, which is not supported yet | `HashSet::remove`, `std::collections::HashSet`, `Loud` | fixtures/reject/src/lib.rs:340:6 | +| 1 | `_` of `_`, which may drop what it holds, which is not supported yet | `HashMap::clear`, `std::collections::HashMap` | fixtures/reject/src/lib.rs:317:6 | +| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:389:2 | +| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | `std::option::Option` | fixtures/reject/src/lib.rs:399:6 | +| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:365:9 | +| 1 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut std::string::String`, `std::string::String` | fixtures/reject/src/lib.rs:106:16 | +| 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:130:2 | +| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:217:51 | +| 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:114:2 | +| 1 | a field of `_` | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:312:48 | +| 1 | a field of `_` | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:312:7 | +| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:281:13 | | 1 | a scalar constant of type `_` | `f64` | fixtures/reject/src/lib.rs:7:2 | -| 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:90:2 | -| 1 | an assignment through a reference to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:145:2 | -| 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:170:2 | -| 1 | an assignment through a reference to `_` | `u32` | fixtures/reject/src/lib.rs:20:2 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:208:1 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:262:1 | -| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:275:20 | +| 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:86:2 | +| 1 | an assignment through a reference to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:141:2 | +| 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:166:2 | +| 1 | an assignment through a reference to `_` | `u32` | fixtures/reject/src/lib.rs:16:2 | +| 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:204:1 | +| 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:258:1 | +| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:271:20 | | 1 | arithmetic on `_` | `f64` | fixtures/reject/src/lib.rs:7:2 | -| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:331:52 | -| 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:194:23 | -| 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:215:14 | -| 1 | dropping `_`, which is not supported yet | `std::sync::Arc` | fixtures/reject/src/lib.rs:141:1 | -| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:331:52 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:188:2 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:242:2 | -| 1 | passing `_`, which drops, to `_`, which is not supported yet | `std::option::Option`, `Option::unwrap_or` | fixtures/reject/src/lib.rs:280:4 | -| 1 | passing `_`, which drops, to `_`, which is not supported yet | `std::sync::Arc`, `Ord::max` | fixtures/reject/src/lib.rs:398:4 | -| 1 | replacing the value behind a reference to `_` | `[u8; 1]` | fixtures/reject/src/lib.rs:299:22 | -| 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:175:11 | -| 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:112:10 | -| 1 | unsupported call to `_` | `std::mem::size_of_val` | fixtures/reject/src/lib.rs:52:18 | -| 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:229:8 | -| 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:36:4 | -| 1 | unsupported type `_` | `char` | fixtures/reject/src/lib.rs:10:18 | -| 1 | unsupported type `_` | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:14:16 | +| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:327:52 | +| 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:190:23 | +| 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:211:14 | +| 1 | dropping `_`, which is not supported yet | `std::sync::Arc` | fixtures/reject/src/lib.rs:137:1 | +| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:327:52 | +| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:184:2 | +| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:238:2 | +| 1 | passing `_`, which drops, to `_`, which is not supported yet | `std::option::Option`, `Option::unwrap_or` | fixtures/reject/src/lib.rs:276:4 | +| 1 | passing `_`, which drops, to `_`, which is not supported yet | `std::sync::Arc`, `Ord::max` | fixtures/reject/src/lib.rs:394:4 | +| 1 | replacing the value behind a reference to `_` | `[u8; 1]` | fixtures/reject/src/lib.rs:295:22 | +| 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:171:11 | +| 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:108:10 | +| 1 | unsupported call to `_` | `std::mem::size_of_val` | fixtures/reject/src/lib.rs:48:18 | +| 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:225:8 | +| 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:32:4 | +| 1 | unsupported type `_` | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:10:16 | ## Spans
an assignment through a reference to `_` (7) -- fixtures/reject/src/lib.rs:20:2: an assignment through a reference to `u32` -- fixtures/reject/src/lib.rs:81:3: an assignment through a reference to `u8` -- fixtures/reject/src/lib.rs:145:2: an assignment through a reference to `std::sync::Arc` -- fixtures/reject/src/lib.rs:165:2: an assignment through a reference to `std::pin::Pin>` -- fixtures/reject/src/lib.rs:170:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` -- fixtures/reject/src/lib.rs:293:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>` -- fixtures/reject/src/lib.rs:404:3: an assignment through a reference to `u8` +- fixtures/reject/src/lib.rs:16:2: an assignment through a reference to `u32` +- fixtures/reject/src/lib.rs:77:3: an assignment through a reference to `u8` +- fixtures/reject/src/lib.rs:141:2: an assignment through a reference to `std::sync::Arc` +- fixtures/reject/src/lib.rs:161:2: an assignment through a reference to `std::pin::Pin>` +- fixtures/reject/src/lib.rs:166:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` +- fixtures/reject/src/lib.rs:289:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>` +- fixtures/reject/src/lib.rs:400:3: an assignment through a reference to `u8`
`_` is not supported: its `None` and `Some` would both be `undefined` (6) -- fixtures/reject/src/lib.rs:31:15: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:32:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:40:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:40:42: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:154:19: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:326:2: `Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:27:15: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:28:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:36:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:36:42: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:150:19: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:322:2: `Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined`
`_`: a JS value of `_` is a copy, so a reference can't change it (5) -- fixtures/reject/src/lib.rs:19:13: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:25:2: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:80:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:110:16: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:403:29: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:15:13: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:21:2: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:76:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:106:16: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:399:29: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it
unsupported call to `_` (5) -- fixtures/reject/src/lib.rs:36:4: unsupported call to `std::slice::::sort` -- fixtures/reject/src/lib.rs:52:18: unsupported call to `std::mem::size_of_val::` -- fixtures/reject/src/lib.rs:112:10: unsupported call to `::write_fmt` -- fixtures/reject/src/lib.rs:175:11: unsupported call to ` as std::iter::Iterator>::cycle` -- fixtures/reject/src/lib.rs:229:8: unsupported call to `std::ops::Range::::contains::` +- fixtures/reject/src/lib.rs:32:4: unsupported call to `std::slice::::sort` +- fixtures/reject/src/lib.rs:48:18: unsupported call to `std::mem::size_of_val::` +- fixtures/reject/src/lib.rs:108:10: unsupported call to `::write_fmt` +- fixtures/reject/src/lib.rs:171:11: unsupported call to ` as std::iter::Iterator>::cycle` +- fixtures/reject/src/lib.rs:225:8: unsupported call to `std::ops::Range::::contains::`
-
unsupported type `_` (5) +
unsupported type `_` (4) - fixtures/reject/src/lib.rs:6:14: unsupported type `f64` - fixtures/reject/src/lib.rs:6:25: unsupported type `f64` -- fixtures/reject/src/lib.rs:10:18: unsupported type `char` -- fixtures/reject/src/lib.rs:14:16: unsupported type `dyn std::ops::Fn(u8) -> u8` -- fixtures/reject/src/lib.rs:132:51: unsupported type `f64` +- fixtures/reject/src/lib.rs:10:16: unsupported type `dyn std::ops::Fn(u8) -> u8` +- fixtures/reject/src/lib.rs:128:51: unsupported type `f64`
an iterator that owns `_`, which drops, which is not supported yet (3) -- fixtures/reject/src/lib.rs:59:2: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:270:4: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:275:20: an iterator that owns `Noisy`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:55:2: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:266:4: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:271:20: an iterator that owns `Noisy`, which drops, which is not supported yet
replacing the value behind a reference to `_` (3) +- fixtures/reject/src/lib.rs:119:2: replacing the value behind a reference to `Meters` - fixtures/reject/src/lib.rs:123:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:127:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:299:22: replacing the value behind a reference to `[u8; 1]` +- fixtures/reject/src/lib.rs:295:22: replacing the value behind a reference to `[u8; 1]`
`_` is not supported: it would be pending two ways with one value (2) -- fixtures/reject/src/lib.rs:149:20: `Poll>>` is not supported: it would be pending two ways with one value -- fixtures/reject/src/lib.rs:159:54: `Poll>` is not supported: it would be pending two ways with one value +- fixtures/reject/src/lib.rs:145:20: `Poll>>` is not supported: it would be pending two ways with one value +- fixtures/reject/src/lib.rs:155:54: `Poll>` is not supported: it would be pending two ways with one value
a field of `_` (2) -- fixtures/reject/src/lib.rs:316:7: a field of `std::ops::RangeTo` -- fixtures/reject/src/lib.rs:316:48: a field of `std::ops::RangeFrom` +- fixtures/reject/src/lib.rs:312:7: a field of `std::ops::RangeTo` +- fixtures/reject/src/lib.rs:312:48: a field of `std::ops::RangeFrom`
an iterator of the crate implementing `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:208:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet -- fixtures/reject/src/lib.rs:262:1: an iterator of the crate implementing `FusedIterator`, which is not supported yet +- fixtures/reject/src/lib.rs:204:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet +- fixtures/reject/src/lib.rs:258:1: an iterator of the crate implementing `FusedIterator`, which is not supported yet
constructing `_` from another crate (2) -- fixtures/reject/src/lib.rs:194:23: constructing `std::iter::Map` from another crate -- fixtures/reject/src/lib.rs:215:14: constructing `std::iter::Rev` from another crate +- fixtures/reject/src/lib.rs:190:23: constructing `std::iter::Map` from another crate +- fixtures/reject/src/lib.rs:211:14: constructing `std::iter::Rev` from another crate
overriding `_`, which std's adaptors call in place of `next` or beside it (2) -- fixtures/reject/src/lib.rs:188:2: overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it -- fixtures/reject/src/lib.rs:242:2: overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it +- fixtures/reject/src/lib.rs:184:2: overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it +- fixtures/reject/src/lib.rs:238:2: overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it
passing `_`, which drops, to `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:280:4: passing `std::option::Option`, which drops, to `Option::unwrap_or`, which is not supported yet -- fixtures/reject/src/lib.rs:398:4: passing `std::sync::Arc`, which drops, to `Ord::max`, which is not supported yet +- fixtures/reject/src/lib.rs:276:4: passing `std::option::Option`, which drops, to `Option::unwrap_or`, which is not supported yet +- fixtures/reject/src/lib.rs:394:4: passing `std::sync::Arc`, which drops, to `Ord::max`, which is not supported yet
`Binary` formatting, as in `{:b}`, is not supported (1) -- fixtures/reject/src/lib.rs:100:3: `Binary` formatting, as in `{:b}`, is not supported +- fixtures/reject/src/lib.rs:96:3: `Binary` formatting, as in `{:b}`, is not supported
`LowerExp` formatting, as in `{:e}`, is not supported (1) -- fixtures/reject/src/lib.rs:102:3: `LowerExp` formatting, as in `{:e}`, is not supported +- fixtures/reject/src/lib.rs:98:3: `LowerExp` formatting, as in `{:e}`, is not supported
`Octal` formatting, as in `{:o}`, is not supported (1) -- fixtures/reject/src/lib.rs:101:3: `Octal` formatting, as in `{:o}`, is not supported +- fixtures/reject/src/lib.rs:97:3: `Octal` formatting, as in `{:o}`, is not supported
`Pointer` formatting, as in `{:p}`, is not supported (1) -- fixtures/reject/src/lib.rs:105:3: `Pointer` formatting, as in `{:p}`, is not supported +- fixtures/reject/src/lib.rs:101:3: `Pointer` formatting, as in `{:p}`, is not supported
`_` holds `_`, which is `undefined` as `None` is, which is not supported (1) -- fixtures/reject/src/lib.rs:326:6: `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported +- fixtures/reject/src/lib.rs:322:6: `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported
`_` is generic and implements `Drop`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:65:1: `Boxed` is generic and implements `Drop`, which is not supported yet +- fixtures/reject/src/lib.rs:61:1: `Boxed` is generic and implements `Drop`, which is not supported yet
`_` of `_` by `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:361:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet +- fixtures/reject/src/lib.rs:357:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet
`_` of `_`, which may drop a `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:344:6: `HashSet::remove` of `std::collections::HashSet`, which may drop a `Loud`, which is not supported yet +- fixtures/reject/src/lib.rs:340:6: `HashSet::remove` of `std::collections::HashSet`, which may drop a `Loud`, which is not supported yet
`_` of `_`, which may drop what it holds, which is not supported yet (1) -- fixtures/reject/src/lib.rs:321:6: `HashMap::clear` of `std::collections::HashMap`, which may drop what it holds, which is not supported yet +- fixtures/reject/src/lib.rs:317:6: `HashMap::clear` of `std::collections::HashMap`, which may drop what it holds, which is not supported yet
`_` through a held type's own, which is not supported yet (1) -- fixtures/reject/src/lib.rs:393:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet +- fixtures/reject/src/lib.rs:389:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet
`_`, a mutable reference to a value a map holds, kept other than to read and write it (1) -- fixtures/reject/src/lib.rs:403:6: `std::option::Option<&mut u8>`, a mutable reference to a value a map holds, kept other than to read and write it +- fixtures/reject/src/lib.rs:399:6: `std::option::Option<&mut u8>`, a mutable reference to a value a map holds, kept other than to read and write it
`_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:369:9: `Hasher::write`, which is not supported yet +- fixtures/reject/src/lib.rs:365:9: `Hasher::write`, which is not supported yet
a `_` cast from `_` to `_` (1) -- fixtures/reject/src/lib.rs:134:2: a `IntToFloat` cast from `u64` to `f64` +- fixtures/reject/src/lib.rs:130:2: a `IntToFloat` cast from `u64` to `f64`
a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` (1) -- fixtures/reject/src/lib.rs:221:51: a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:221:15: 221:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` - -
- -
a cast from `_` (1) - -- fixtures/reject/src/lib.rs:11:2: a cast from `char` +- fixtures/reject/src/lib.rs:217:51: a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:217:15: 217:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold`
a constant of type `_` (1) -- fixtures/reject/src/lib.rs:118:2: a constant of type `&u8` +- fixtures/reject/src/lib.rs:114:2: a constant of type `&u8`
a copy of a closure that changes what it captured (1) -- fixtures/reject/src/lib.rs:310:14: a copy of a closure that changes what it captured +- fixtures/reject/src/lib.rs:306:14: a copy of a closure that changes what it captured
a mutable borrow of a subslice of `_`, which JS would copy, having no views (1) -- fixtures/reject/src/lib.rs:285:13: a mutable borrow of a subslice of `u32`, which JS would copy, having no views +- fixtures/reject/src/lib.rs:281:13: a mutable borrow of a subslice of `u32`, which JS would copy, having no views
a precision, as in `{:.2}`, is not supported (1) -- fixtures/reject/src/lib.rs:97:3: a precision, as in `{:.2}`, is not supported +- fixtures/reject/src/lib.rs:93:3: a precision, as in `{:.2}`, is not supported
a printable type must implement `Display` or `Debug` (1) -- fixtures/reject/src/lib.rs:130:1: a printable type must implement `Display` or `Debug` +- fixtures/reject/src/lib.rs:126:1: a printable type must implement `Display` or `Debug`
@@ -396,13 +385,13 @@ The type or module each refused type or path belongs to.
a width or precision from an argument, as in `{:1$}`, is not supported (1) -- fixtures/reject/src/lib.rs:104:3: a width or precision from an argument, as in `{:1$}`, is not supported +- fixtures/reject/src/lib.rs:100:3: a width or precision from an argument, as in `{:1$}`, is not supported
a zero-sized constant of type `_` (1) -- fixtures/reject/src/lib.rs:90:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:89:10: 89:18}` +- fixtures/reject/src/lib.rs:86:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:85:10: 85:18}`
@@ -414,42 +403,42 @@ The type or module each refused type or path belongs to.
comparing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:331:52: comparing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:327:52: comparing `std::vec::Vec` as a key, which is not supported yet
dropping `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:141:1: dropping `std::sync::Arc<&Noisy>`, which is not supported yet +- fixtures/reject/src/lib.rs:137:1: dropping `std::sync::Arc<&Noisy>`, which is not supported yet
dropping a closure that owns a value that drops, which is not supported yet (1) -- fixtures/reject/src/lib.rs:54:1: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:50:1: dropping a closure that owns a value that drops, which is not supported yet
hashing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:331:52: hashing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:327:52: hashing `std::vec::Vec` as a key, which is not supported yet
hex `Debug`, as in `{:x?}`, is not supported (1) -- fixtures/reject/src/lib.rs:103:3: hex `Debug`, as in `{:x?}`, is not supported +- fixtures/reject/src/lib.rs:99:3: hex `Debug`, as in `{:x?}`, is not supported
the `+` flag of a format spec is not supported (1) -- fixtures/reject/src/lib.rs:98:3: the `+` flag of a format spec is not supported +- fixtures/reject/src/lib.rs:94:3: the `+` flag of a format spec is not supported
the `-` flag of a format spec is not supported (1) -- fixtures/reject/src/lib.rs:99:3: the `-` flag of a format spec is not supported +- fixtures/reject/src/lib.rs:95:3: the `-` flag of a format spec is not supported
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 875bd6c42..7b4e23b6d 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -1,73 +1,71 @@ -a root must not be generic at fixtures/reject/src/lib.rs:132:1 +a root must not be generic at fixtures/reject/src/lib.rs:128:1 no item `missing` in the crate -a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:130:1 +a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:126:1 unsupported type `f64` at fixtures/reject/src/lib.rs:6:14 a scalar constant of type `f64` at fixtures/reject/src/lib.rs:7:2 arithmetic on `f64` at fixtures/reject/src/lib.rs:7:2 unsupported type `f64` at fixtures/reject/src/lib.rs:6:25 -unsupported type `char` at fixtures/reject/src/lib.rs:10:18 -a cast from `char` at fixtures/reject/src/lib.rs:11:2 -unsupported type `dyn std::ops::Fn(u8) -> u8` at fixtures/reject/src/lib.rs:14:16 -`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:19:13 -an assignment through a reference to `u32` at fixtures/reject/src/lib.rs:20:2 -`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:25:11 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:32:2 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:31:15 -unsupported call to `std::slice::::sort` at fixtures/reject/src/lib.rs:36:4 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:40:2 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:40:42 -unsupported call to `std::mem::size_of_val::` at fixtures/reject/src/lib.rs:52:18 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:54:1 -an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:59:11 -`Boxed` is generic and implements `Drop`, which is not supported yet at fixtures/reject/src/lib.rs:73:10 -`&mut u8`: a JS value of `u8` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:80:10 -an assignment through a reference to `u8` at fixtures/reject/src/lib.rs:81:3 -a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:89:10: 89:18}` at fixtures/reject/src/lib.rs:90:2 -a precision, as in `{:.2}`, is not supported at fixtures/reject/src/lib.rs:97:3 -the `+` flag of a format spec is not supported at fixtures/reject/src/lib.rs:98:3 -the `-` flag of a format spec is not supported at fixtures/reject/src/lib.rs:99:3 -`Binary` formatting, as in `{:b}`, is not supported at fixtures/reject/src/lib.rs:100:12 -`Octal` formatting, as in `{:o}`, is not supported at fixtures/reject/src/lib.rs:101:12 -`LowerExp` formatting, as in `{:e}`, is not supported at fixtures/reject/src/lib.rs:102:12 -hex `Debug`, as in `{:x?}`, is not supported at fixtures/reject/src/lib.rs:103:3 -a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:104:15 -a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:104:3 -`Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:105:12 -`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:110:16 -unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:112:10 -a constant of type `&u8` at fixtures/reject/src/lib.rs:118:2 +unsupported type `dyn std::ops::Fn(u8) -> u8` at fixtures/reject/src/lib.rs:10:16 +`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:15:13 +an assignment through a reference to `u32` at fixtures/reject/src/lib.rs:16:2 +`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:21:11 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:28:2 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:27:15 +unsupported call to `std::slice::::sort` at fixtures/reject/src/lib.rs:32:4 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:36:2 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:36:42 +unsupported call to `std::mem::size_of_val::` at fixtures/reject/src/lib.rs:48:18 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:50:1 +an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:55:11 +`Boxed` is generic and implements `Drop`, which is not supported yet at fixtures/reject/src/lib.rs:69:10 +`&mut u8`: a JS value of `u8` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:76:10 +an assignment through a reference to `u8` at fixtures/reject/src/lib.rs:77:3 +a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:85:10: 85:18}` at fixtures/reject/src/lib.rs:86:2 +a precision, as in `{:.2}`, is not supported at fixtures/reject/src/lib.rs:93:3 +the `+` flag of a format spec is not supported at fixtures/reject/src/lib.rs:94:3 +the `-` flag of a format spec is not supported at fixtures/reject/src/lib.rs:95:3 +`Binary` formatting, as in `{:b}`, is not supported at fixtures/reject/src/lib.rs:96:12 +`Octal` formatting, as in `{:o}`, is not supported at fixtures/reject/src/lib.rs:97:12 +`LowerExp` formatting, as in `{:e}`, is not supported at fixtures/reject/src/lib.rs:98:12 +hex `Debug`, as in `{:x?}`, is not supported at fixtures/reject/src/lib.rs:99:3 +a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:100:15 +a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:100:3 +`Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:101:12 +`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:106:16 +unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:108:10 +a constant of type `&u8` at fixtures/reject/src/lib.rs:114:2 +replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:119:2 replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:123:2 -replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:127:2 -dropping `std::sync::Arc<&Noisy>`, which is not supported yet at fixtures/reject/src/lib.rs:141:1 -an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:145:2 -`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:149:20 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:154:19 -`Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:159:54 -an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:165:2 -an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:170:2 -unsupported call to ` as std::iter::Iterator>::cycle` at fixtures/reject/src/lib.rs:175:11 -constructing `std::iter::Map` from another crate at fixtures/reject/src/lib.rs:194:23 -constructing `std::iter::Rev` from another crate at fixtures/reject/src/lib.rs:215:14 -a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:221:15: 221:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` at fixtures/reject/src/lib.rs:221:51 -unsupported call to `std::ops::Range::::contains::` at fixtures/reject/src/lib.rs:229:8 -an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:270:4 -an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:275:20 -passing `std::option::Option`, which drops, to `Option::unwrap_or`, which is not supported yet at fixtures/reject/src/lib.rs:280:4 -a mutable borrow of a subslice of `u32`, which JS would copy, having no views at fixtures/reject/src/lib.rs:285:13 -an assignment through a reference to `std::pin::Pin<&mut Noisy>` at fixtures/reject/src/lib.rs:293:2 -replacing the value behind a reference to `[u8; 1]` at fixtures/reject/src/lib.rs:299:22 -a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:310:14 -a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:316:7 -a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:316:48 -`HashMap::clear` of `std::collections::HashMap`, which may drop what it holds, which is not supported yet at fixtures/reject/src/lib.rs:321:6 -`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:326:2 -`std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:326:6 -hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:331:52 -comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:331:52 -`HashSet::remove` of `std::collections::HashSet`, which may drop a `Loud`, which is not supported yet at fixtures/reject/src/lib.rs:344:6 -`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:361:6 -overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:188:2 -an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:208:1 -overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:242:2 -an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:262:1 -`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:369:9 +dropping `std::sync::Arc<&Noisy>`, which is not supported yet at fixtures/reject/src/lib.rs:137:1 +an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:141:2 +`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:145:20 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:150:19 +`Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:155:54 +an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:161:2 +an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:166:2 +unsupported call to ` as std::iter::Iterator>::cycle` at fixtures/reject/src/lib.rs:171:11 +constructing `std::iter::Map` from another crate at fixtures/reject/src/lib.rs:190:23 +constructing `std::iter::Rev` from another crate at fixtures/reject/src/lib.rs:211:14 +a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:217:15: 217:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` at fixtures/reject/src/lib.rs:217:51 +unsupported call to `std::ops::Range::::contains::` at fixtures/reject/src/lib.rs:225:8 +an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:266:4 +an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:271:20 +passing `std::option::Option`, which drops, to `Option::unwrap_or`, which is not supported yet at fixtures/reject/src/lib.rs:276:4 +a mutable borrow of a subslice of `u32`, which JS would copy, having no views at fixtures/reject/src/lib.rs:281:13 +an assignment through a reference to `std::pin::Pin<&mut Noisy>` at fixtures/reject/src/lib.rs:289:2 +replacing the value behind a reference to `[u8; 1]` at fixtures/reject/src/lib.rs:295:22 +a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:306:14 +a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:312:7 +a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:312:48 +`HashMap::clear` of `std::collections::HashMap`, which may drop what it holds, which is not supported yet at fixtures/reject/src/lib.rs:317:6 +`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:322:2 +`std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:322:6 +hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:327:52 +comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:327:52 +`HashSet::remove` of `std::collections::HashSet`, which may drop a `Loud`, which is not supported yet at fixtures/reject/src/lib.rs:340:6 +`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:357:6 +overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:184:2 +an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:204:1 +overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:238:2 +an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:258:1 +`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:365:9 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index be2980ecb..046534bb6 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -7,10 +7,6 @@ pub fn float(a: f64) -> f64 { a * 2.0 } -pub fn character(c: char) -> u32 { - c as u32 -} - pub fn dynamic(f: &dyn Fn(u8) -> u8) -> u8 { f(1) } diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index 6a5f4cd73..07bbf9212 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -1,7 +1,6 @@ package = "reject-fixture" roots = [ "float", - "character", "dynamic", "bump", "increment", diff --git a/ts/runtime/rt.ts b/ts/runtime/rt.ts index 94763b370..4ab4d44d8 100644 --- a/ts/runtime/rt.ts +++ b/ts/runtime/rt.ts @@ -5,7 +5,7 @@ // left only where a call dispatches on its receiver: an iterator's `next`, a writer's // `writeStr`, a future's `poll`, a waker's, and `[Symbol.dispose]`. -import { type TryFromIntError, u8Display, usizeDisplay } from "./rt/int.ts"; +import { type char, type TryFromIntError, type u32, u8Display, usizeDisplay } from "./rt/int.ts"; export * from "./rt/collections.ts"; export * from "./rt/int.ts"; @@ -230,6 +230,14 @@ export function sliceToByteVec(s: Uint8Array): ByteVec { return byteVecFrom(s); } +/** `vec![value; n]`: `n - 1` clones of `value`, in order, then `value` itself; `clone` is `undefined` where a clone is the value. */ +export function vecFromElem(value: T, n: number, clone: ((value: T) => T) | undefined): T[] { + const v: T[] = []; + for (let i = 1; i < n; i++) v.push(clone === undefined ? value : clone(value)); + if (n > 0) v.push(value); + return v; +} + const SLAB = 8192; let slab = /* @__PURE__ */ new ArrayBuffer(SLAB); let slabUsed = 0; @@ -385,6 +393,11 @@ export function stringLen(s: string): number { return encoder.encode(s).length; } +/** `char::from_u32`: `n`, unless it is a surrogate or past the last char. */ +export function charFromU32(n: u32): char | undefined { + return n > 0x10ffff || (n >= 0xd800 && n <= 0xdfff) ? undefined : (n as char); +} + // Formatting, as `core::fmt` does it: the same output byte for byte. /** `core::fmt::Error`. */ @@ -702,11 +715,11 @@ function closePretty(f: Formatter, close: string): FmtResult { /** Characters `Debug` of a string writes as `\u{..}`, by std's rule. */ const unprintable = /[\p{Cc}\p{Co}\p{White_Space}\p{Grapheme_Extend}\p{Default_Ignorable_Code_Point}\p{Cf}\P{Assigned}]/u; -/** One char of a string's `Debug`. */ -function escapeDebug(c: string): string { +/** One char of `Debug` of a string, which escapes `"`, or of a char, which escapes `'`. */ +function escapeDebug(c: string, quote: '"' | "'"): string { switch (c) { - case '"': - return '\\"'; + case quote: + return `\\${quote}`; case "\\": return "\\\\"; case "\n": @@ -753,10 +766,20 @@ export function fmtBool(value: boolean, f: Formatter): FmtResult { /** `Debug` of a string. */ export function fmtStr(s: string, f: Formatter): FmtResult { let out = '"'; - for (const c of s) out += escapeDebug(c); + for (const c of s) out += escapeDebug(c, '"'); return f.out.writeStr(out + '"'); } +/** `Display` of a `char`. */ +export function fmtCharDisplay(c: char, f: Formatter): FmtResult { + return fmtPad(f, String.fromCodePoint(c)); +} + +/** `Debug` of a `char`, which no width pads. */ +export function fmtCharDebug(c: char, f: Formatter): FmtResult { + return f.out.writeStr(`'${escapeDebug(String.fromCodePoint(c), "'")}'`); +} + /** `Debug` of `()`. */ export function fmtUnit(_: undefined, f: Formatter): FmtResult { return fmtPad(f, "()"); diff --git a/ts/runtime/rt/int.ts b/ts/runtime/rt/int.ts index a3930ec15..e3575a109 100644 --- a/ts/runtime/rt/int.ts +++ b/ts/runtime/rt/int.ts @@ -44,6 +44,8 @@ export type i16 = Num<"i16">; export type i32 = Num<"i32">; /** 32 bits, as on wasm32. */ export type isize = Num<"isize">; +/** Rust's `char`: a Unicode scalar value, which is at most 0x10ffff and no surrogate. */ +export type char = Num<"char">; /** * A `u64`: a number while it is a safe integer, at most 2^53 - 1, and its limbs past * that. Each value has one form, so two numbers compare with `===`, and a number never diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 0cae4bbae..a2d534b1d 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -380,7 +380,7 @@ fn empty<'tcx>(b: &mut Body<'_, '_, 'tcx>, new: Expr, coll: Ty<'tcx>, span: Span fn hashing<'tcx>(b: &mut Body<'_, '_, 'tcx>, coll: Ty<'tcx>, key: Ty<'tcx>, span: Span) -> Option> { let key = peel(b, key); let primitive = match key.kind() { - ty::Bool | ty::Str => true, + ty::Bool | ty::Char | ty::Str => true, ty::Int(_) | ty::Uint(_) => !Int::of(key)?.big(), ty::Adt(..) if b.t.std_of(key) == Some(Std::String) => true, ty::Adt(adt, _) if adt.did().is_local() && fieldless(*adt) => derived_eq(b, key), @@ -772,7 +772,7 @@ fn std_key<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { std_key(b, t) || b.t.deferred(t) || matches!(t.kind(), ty::Adt(adt, _) if adt.did().is_local()) }; match ty.kind() { - ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Str => true, + ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Str => true, ty::Tuple(tys) => !tys.is_empty() && tys.iter().all(held), ty::Adt(..) if let Some(inner) = option_of(b, ty).or_else(|| arc_of(b, ty)) => held(inner), ty::Adt(..) => matches!(b.t.std_of(ty), Some(Std::String | Std::Ordering)), @@ -796,7 +796,7 @@ fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: S let tcx = b.t.tcx; let ty = peel(b, ty); match ty.kind() { - ty::Bool | ty::Int(_) | ty::Uint(_) => Expr::Rt("cmp".into()), + ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => Expr::Rt("cmp".into()), ty::Str => Expr::Rt("cmpStr".into()), ty::Adt(..) if b.t.std_of(ty) == Some(Std::String) => Expr::Rt("cmpStr".into()), ty::Adt(..) if b.t.std_of(ty) == Some(Std::Ordering) => Expr::Rt("cmp".into()), @@ -833,7 +833,7 @@ fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { { int.func("eq") } - ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Str => Expr::Rt("same".into()), + ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Str => Expr::Rt("same".into()), ty::Adt(..) if matches!(b.t.std_of(ty), Some(Std::String | Std::Ordering)) => Expr::Rt("same".into()), ty::Tuple(tys) if !tys.is_empty() => { let fns = tys.iter().map(|t| eq_fn(b, t, span)).collect(); @@ -867,7 +867,7 @@ fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, spa let tcx = b.t.tcx; let ty = peel(b, ty); match ty.kind() { - ty::Bool | ty::Int(_) | ty::Uint(_) => Expr::Rt("hashInt".into()), + ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => Expr::Rt("hashInt".into()), ty::Str => Expr::Rt("hashStr".into()), ty::Adt(..) if b.t.std_of(ty) == Some(Std::String) => Expr::Rt("hashStr".into()), ty::Adt(..) if b.t.std_of(ty) == Some(Std::Ordering) => Expr::Rt("hashInt".into()), @@ -889,7 +889,7 @@ fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, spa } /// `Clone::clone` of `ty`, as a function, or `undefined` where it is the value itself. -fn clone_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { +pub fn clone_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { let tcx = b.t.tcx; if library::clone_copies(b.t, ty) && let Some(copy) = b.t.copy_fn(ty, span) diff --git a/ts/src/lower/consts.rs b/ts/src/lower/consts.rs index 1e562445f..83e8b3c7c 100644 --- a/ts/src/lower/consts.rs +++ b/ts/src/lower/consts.rs @@ -41,6 +41,10 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { }; int.lit(value) } + ty::Char => match leaf(valtree) { + Some(scalar) => Expr::lit(scalar.to_u32().to_string()), + None => self.err(span, "a char constant without a value"), + }, ty::Ref(_, inner, _) => match inner.kind() { ty::Str => { let bytes: Vec = children(valtree) diff --git a/ts/src/lower/fmt.rs b/ts/src/lower/fmt.rs index 065fadbed..6442fd86c 100644 --- a/ts/src/lower/fmt.rs +++ b/ts/src/lower/fmt.rs @@ -222,6 +222,8 @@ pub fn std_impl<'tcx>( Int::of(ty)?.method(method, vec![value, f]) } ty::Bool if text => rt("bool", vec![value, f]), + ty::Char if tr == Trait::Display => rt("charDisplay", vec![value, f]), + ty::Char if tr == Trait::Debug => rt("charDebug", vec![value, f]), ty::Str if tr == Trait::Display => Expr::rt("fmtPad", vec![f, value]), ty::Str if tr == Trait::Debug => rt("str", vec![value, f]), ty::Tuple(tys) if tys.is_empty() && tr == Trait::Debug => rt("unit", vec![value, f]), diff --git a/ts/src/lower/iter.rs b/ts/src/lower/iter.rs index d81a5e56e..c180f8d50 100644 --- a/ts/src/lower/iter.rs +++ b/ts/src/lower/iter.rs @@ -421,9 +421,9 @@ pub(super) fn implements<'tcx>(t: &Translator<'_, 'tcx>, ty: Ty<'tcx>, name: &st infcx.type_implements_trait(tr, [ty], env).must_apply_modulo_regions() } -/// Whether `ty` compares in JS as Rust's `Ord` does: an integer or a `bool`. +/// Whether `ty` compares in JS as Rust's `Ord` does: an integer, a `bool`, or a `char`. fn primitive(ty: Ty<'_>) -> bool { - matches!(ty.kind(), ty::Bool | ty::Int(_) | ty::Uint(_)) + matches!(ty.kind(), ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_)) } /// `iter.collect::()` of `item`s. diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 6dc1a0f14..ec30c2e41 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -12,7 +12,7 @@ use rustc_span::Span; use super::body::Body; use super::fmt; use super::num::{self, Int, Operand}; -use crate::ts::{Expr, Stmt, StmtKind}; +use crate::ts::{Expr, Stmt}; /// A standard library type with its own representation. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -297,7 +297,6 @@ fn keeps_operands(owner: &str, name: &str) -> bool { ) | ("Vec", "push") | ("Box", "new") - | ("boxed", "box_new") | ("mem", "replace" | "take" | "swap") | ("hint", "must_use") | ("From", "from") @@ -337,6 +336,7 @@ pub fn key(tcx: TyCtxt<'_>, def_id: DefId) -> Option<(String, String)> { ty::Array(..) => "array".into(), ty::Str => "str".into(), ty::Bool => "bool".into(), + ty::Char => "char".into(), ty::Int(_) | ty::Uint(_) => self_ty.to_string(), _ => return None, }; @@ -418,16 +418,16 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec if to == from { return Some(value); } - match (Int::of(to), Int::of(from)) { - (Some(_), Some(_)) => { - let operand = Operand { - expr: value, - value: None, - }; - num::cast(b, operand, from, to, span) - } - _ => return None, + // Each `From` between integers and `char` keeps the value, as `as` then does. + let scalar = |t: Ty<'tcx>| Int::of(t).is_some() || t.is_char(); + if !scalar(to) || !scalar(from) { + return None; } + let operand = Operand { + expr: value, + value: None, + }; + num::cast(b, operand, from, to, span) } ("Into", "into") => { let (from, to) = (targ(gargs, 0), targ(gargs, 1)); @@ -435,6 +435,8 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec let value = values.pop()?; b.convert(value, from, to, span, out) } + // A scalar value, but not a surrogate. + ("char", "from_u32") => Expr::rt("charFromU32", args), ("TryFrom", "try_from") => { let (to, from) = (targ(gargs, 0), targ(gargs, 1)); let (Some(int), Some(_)) = (Int::of(to), Int::of(from)) else { @@ -606,39 +608,37 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec false => return None, } } - ("slice", "into_vec") => { - // `vec![..]`: `<[T]>::into_vec(box_new([..]))`. + // A boxed slice's elements, and `vec![a, b]`'s array once `mir::vec` took the box + // away. A `Copy` aggregate's operand may be shared with where it came from, which the + // vector must not change. + ("slice", "into_vec") | ("boxed", "box_assume_init_into_vec_unsafe") => { let elem = targ(gargs, 0); let value = args.pop()?; - match is_u8(elem) { - true => Expr::rt("byteVecFrom", vec![value]), - false => value, + if is_u8(elem) { + return Some(Expr::rt("byteVecFrom", vec![value])); + } + match (b.t.copy_fn(elem, span), value) { + (None, value) => value, + (Some(_), Expr::Array(items)) => { + Expr::Array(items.into_iter().map(|item| owned(b, item, elem, span)).collect()) + } + (Some(copy), value) => value.member("map").call(vec![copy]), } } - ("boxed", "box_new") | ("Box", "new") => args.pop()?, + ("Box", "new") => args.pop()?, + // `vec![x; n]`: `n - 1` clones of `x`, then `x` itself. ("vec", "from_elem") => { let elem = targ(gargs, 0); - let values = args; + let mut values = args; match is_u8(elem) { true => Expr::rt("byteVecOf", values), - false if b.t.is_copy(elem) => { - let [value, n] = <[Expr; 2]>::try_from(values).ok()?; - let value = match value.is_path() { - true => value, - false => { - let name = b.fresh("item"); - out.push(StmtKind::decl(false, name.clone(), None, Some(value)).at(None)); - Expr::ident(name) - } - }; - let item = b.t.copied(value, elem, span); - let item_ty = b.t.ty(elem, span); - Expr::ident("Array").member("from").call(vec![ - Expr::Object(vec![(crate::ts::Key::Name("length".into()), n)]), - Expr::Arrow(Vec::new(), item_ty, vec![StmtKind::Return(Some(item.typed())).at(None)]), - ]) + false => { + // The last element is `x` itself: a copy of a `Copy` aggregate, without its `Clone`. + let value = owned(b, values.remove(0), elem, span); + values.insert(0, value); + values.push(super::collections::clone_fn(b, elem, span)); + Expr::rt("vecFromElem", values) } - false => return None, } } @@ -842,6 +842,22 @@ pub fn targ<'tcx>(gargs: GenericArgsRef<'tcx>, n: usize) -> Ty<'tcx> { gargs.types().nth(n).expect("a type argument") } +/// `value`, a `ty`, as a value of its own: copied if it is a `Copy` aggregate that is not +/// made right here. +fn owned<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Expr, ty: Ty<'tcx>, span: Span) -> Expr { + fn made(e: &Expr) -> bool { + match e { + Expr::Array(_) | Expr::Object(_) | Expr::New(..) => true, + Expr::As(e, _) | Expr::Located(_, e) => made(e), + _ => false, + } + } + match made(&value) { + true => value, + false => b.t.copied(value, ty, span), + } +} + /// `rt.(args)`. fn rt2(args: Vec, of: &str, name: &str) -> Expr { Expr::rt_of(of, name).call(args) @@ -907,6 +923,7 @@ pub fn default_value<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option Expr::lit("false"), ty::Int(_) | ty::Uint(_) => Int::of(ty)?.lit(0), + ty::Char => Expr::lit("0"), ty::Ref(_, inner, _) => match inner.kind() { ty::Slice(elem) if matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) => { Expr::New(Box::new(Expr::ident("Uint8Array")), vec![Expr::lit("0")]) diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 2bb83feae..80606b4fe 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -18,6 +18,7 @@ mod place; mod rvalue; mod step; mod unwind; +mod vec; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::IndexVec; @@ -72,7 +73,10 @@ fn instance_mir<'tcx>(t: &mut Translator<'_, 'tcx>, instance: Instance<'tcx>, sp return None; } let body = tcx.optimized_mir(def_id).clone(); - Some(instance.instantiate_mir_and_normalize_erasing_regions(tcx, t.typing_env_pub(), EarlyBinder::bind(tcx, body))) + let mut body = + instance.instantiate_mir_and_normalize_erasing_regions(tcx, t.typing_env_pub(), EarlyBinder::bind(tcx, body)); + vec::literals(tcx, &mut body); + Some(body) } /// What `_1` is. @@ -720,7 +724,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { && !self.mutated[local] { let ty = mir.local_decls[local].ty; - return ty.is_bool() || crate::lower::num::Int::of(ty).is_some_and(|i| !i.big()); + return ty.is_bool() || ty.is_char() || crate::lower::num::Int::of(ty).is_some_and(|i| !i.big()); } match (mir.local_decls[local].ty.kind(), rvalue) { // A borrow: borrow checking keeps the place as it is but through the borrow, @@ -2104,6 +2108,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { 0 => value.clone().not(), _ => value.clone(), }, + ty::Char => value.clone().binary("===", Expr::lit(v.to_string())), _ => match super::num::Int::of(ty) { Some(int) => { let lit = int.lit(int.fold(v as i128)); diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index 7abc34335..e2f4c869b 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -495,6 +495,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { }, ConstValue::Scalar(Scalar::Int(int)) => match ty.kind() { ty::Bool => Expr::lit((int.to_bits_unchecked() != 0).to_string()), + ty::Char => Expr::lit(int.to_u32().to_string()), _ => match Int::of(ty) { Some(i) => { let size = rustc_abi::Size::from_bits(i.bits); diff --git a/ts/src/lower/mir/vec.rs b/ts/src/lower/mir/vec.rs new file mode 100644 index 000000000..7e5d91520 --- /dev/null +++ b/ts/src/lower/mir/vec.rs @@ -0,0 +1,167 @@ +//! `vec![a, b]`, which the pinned nightly expands to +//! `box_assume_init_into_vec_unsafe(write_box_via_move(Box::new_uninit(), [a, b]))`: MIR +//! makes an uninitialized box, writes the array through the box's pointer, and turns the +//! box into a `Vec`. A box is its contents in JS, and there is nothing to make before +//! them, so the write becomes the box's local's one assignment, of the array itself. + +use rustc_middle::mir::{ + self, BasicBlock, Local, Operand, Place, ProjectionElem, Rvalue, StatementKind, TerminatorKind, +}; +use rustc_middle::ty::{Ty, TyCtxt}; + +use crate::lower::library::{self, Std}; + +/// Rewrite each `vec![a, b]` in `body` so its box's locals hold the array. One whose MIR +/// has another shape is left as it is, and refused where it is lowered. +pub fn literals<'tcx>(tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) { + let Some(into_vec) = tcx.get_diagnostic_item(rustc_span::Symbol::intern("box_assume_init_into_vec_unsafe")) else { + return; + }; + let boxes: Vec = body + .basic_blocks + .iter() + .filter_map(|data| match &data.terminator().kind { + TerminatorKind::Call { func, args, .. } if func.const_fn_def().is_some_and(|(f, _)| f == into_vec) => { + match &args[..] { + [arg] => arg.node.place()?.as_local(), + _ => None, + } + } + _ => None, + }) + .collect(); + for boxed in boxes { + if let Some(literal) = Literal::find(tcx, body, boxed) { + literal.rewrite(body); + } + } +} + +/// Where one `vec![a, b]`'s MIR makes its box, takes its pointer, and writes the array. +struct Literal<'tcx> { + /// The locals that hold the box: the one made first, then each it moves to. + boxes: Vec, + /// The block whose call makes the box, and where it goes on to. + made: (BasicBlock, BasicBlock), + /// The statement that takes the box's pointer. + pointer: (BasicBlock, usize), + /// The statement that writes the array through it, and the array's type. + write: (BasicBlock, usize), + array: Ty<'tcx>, +} + +impl<'tcx> Literal<'tcx> { + /// The literal whose box `last` holds as `box_assume_init_into_vec_unsafe` takes it. + fn find(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>, last: Local) -> Option { + let new_uninit = |func: &Operand<'tcx>| { + func.const_fn_def().is_some_and(|(f, _)| { + tcx.item_name(f).as_str() == "new_uninit" && library::inherent_std(tcx, f) == Some(Std::Box) + }) + }; + // Each statement of the body, where it is. + let statements = || { + body.basic_blocks.iter_enumerated().flat_map(|(bb, data)| { + data.statements + .iter() + .enumerate() + .filter_map(move |(i, stmt)| match &stmt.kind { + StatementKind::Assign(assign) => Some((bb, i, &assign.0, &assign.1)), + _ => None, + }) + }) + }; + // Back from `last` through the moves between its locals, to the one made first. + let mut boxes = vec![last]; + loop { + let to = *boxes.last()?; + let mut from = None; + for (_, _, place, rvalue) in statements() { + if place.as_local() == Some(to) + && let Rvalue::Use(Operand::Move(source), _) = rvalue + { + from = only(from, source.as_local()?)?; + } + } + match from { + Some(from) if !boxes.contains(&from) => boxes.push(from), + Some(_) => return None, + None => break, + } + } + boxes.reverse(); + let first = boxes[0]; + let mut made = None; + for (bb, data) in body.basic_blocks.iter_enumerated() { + if let TerminatorKind::Call { + func, + destination, + target: Some(target), + .. + } = &data.terminator().kind + && destination.as_local() == Some(first) + && new_uninit(func) + { + made = only(made, (bb, *target))?; + } + } + let mut pointer = None; + for (bb, i, place, rvalue) in statements() { + if let Rvalue::Cast(mir::CastKind::BoxDerefTransmute, Operand::Copy(from) | Operand::Move(from), _) = rvalue + && from.local == first + { + pointer = only(pointer, (place.as_local()?, bb, i))?; + } + } + let (ptr, pointer_bb, pointer_i) = pointer?; + let mut write = None; + for (bb, i, place, _) in statements() { + if place.local == ptr + && let [ + ProjectionElem::Deref, + ProjectionElem::Field(..), + ProjectionElem::Field(_, array), + ] = place.projection.as_slice() + { + write = only(write, (bb, i, *array))?; + } + } + let (write_bb, write_i, array) = write?; + Some(Self { + boxes, + made: made?, + pointer: (pointer_bb, pointer_i), + write: (write_bb, write_i), + array, + }) + } + + fn rewrite(self, body: &mut mir::Body<'tcx>) { + for &local in &self.boxes { + body.local_decls[local].ty = self.array; + } + let blocks = body.basic_blocks.as_mut(); + let (made, target) = self.made; + blocks[made].terminator_mut().kind = TerminatorKind::goto(target); + blocks[self.pointer.0].statements[self.pointer.1].make_nop(true); + if let StatementKind::Assign(assign) = &mut blocks[self.write.0].statements[self.write.1].kind { + assign.0 = Place::from(self.boxes[0]); + } + // Dropping the box only frees it, which JS leaves to its collector. + for data in blocks.iter_mut() { + let term = data.terminator_mut(); + if let TerminatorKind::Drop { place, target, .. } = &term.kind + && place.as_local().is_some_and(|local| self.boxes.contains(&local)) + { + term.kind = TerminatorKind::goto(*target); + } + } + } +} + +/// `found`, unless `seen` already holds one: then the pattern is not `vec!`'s. +fn only(seen: Option, found: T) -> Option> { + match seen { + Some(_) => None, + None => Some(Some(found)), + } +} diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 3f27f5f95..eec276eb4 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -849,6 +849,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { match ty.kind() { ty::Bool => Type::Builtin("boolean"), ty::Int(_) | ty::Uint(_) => num::Int::of(ty).unwrap().ty(), + ty::Char => Type::Rt("char", Vec::new()), ty::Str => Type::Builtin("string"), ty::Never => Type::Builtin("never"), ty::Tuple(tys) if tys.is_empty() => Type::Builtin("undefined"), diff --git a/ts/src/lower/num.rs b/ts/src/lower/num.rs index a573df464..0881cf9d7 100644 --- a/ts/src/lower/num.rs +++ b/ts/src/lower/num.rs @@ -346,9 +346,20 @@ pub fn unary<'tcx>(b: &mut Body<'_, '_, 'tcx>, op: UnOp, value: Expr, ty: Ty<'tc /// `value as to`. pub fn cast<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Operand, from: Ty<'tcx>, to: Ty<'tcx>, span: Span) -> Expr { + // Only a `u8` casts to a `char`, whose scalar value it is. + if let (ty::Char, ty::Uint(ty::UintTy::U8)) = (to.kind(), from.kind()) { + return Expr::As(Box::new(value.expr), Type::Rt("char", Vec::new())); + } let Some(target) = Int::of(to) else { return b.err(span, format!("a cast to `{to}`")); }; + // A `char` is its scalar value, at most 0x10FFFF: it fits a type of more than 21 bits. + if let ty::Char = from.kind() { + return match target.bits > 21 { + true => Expr::As(Box::new(value.expr), target.ty()), + false => target.wrap(value.expr), + }; + } if let ty::Bool = from.kind() { return Expr::Cond(Box::new(value.expr), Box::new(target.lit(1)), Box::new(target.lit(0))); } diff --git a/ts/src/print.rs b/ts/src/print.rs index af1c3d6d6..1d05f2eac 100644 --- a/ts/src/print.rs +++ b/ts/src/print.rs @@ -903,7 +903,13 @@ impl Printer<'_> { } Expr::Binary(l, op, r) => { let p = binary_prec(op); - self.operand(l, op, p); + // The type after `as` would read on into `&`, `|`, or `<` as its own. + let left = match &**l { + Expr::As(..) => 21, + Expr::Located(_, e) if matches!(&**e, Expr::As(..)) => 21, + _ => p, + }; + self.operand(l, op, left); self.write(&format!(" {op} ")); // `&&` and `||` are associative, so a chain reads without groups. let right = match is_logical(op) && matches!(&**r, Expr::Binary(_, inner, _) if inner == op) {