From 46247ef49f0c01b5451e2809edbdd4a2f669a7fb Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 06:55:49 -0700 Subject: [PATCH 1/5] chore(quest): claim quest/m2/ts-mir-census.md Quest-Claim: f47cd0ce4260a868 From 862b397e2f597f780b0716e7537e8e448bc0dc62 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 07:44:18 -0700 Subject: [PATCH 2/5] fix(ts): translate what MIR refused and THIR did not Represent every `ControlFlow`: what `?` branches on stays the value it was applied to, and any other is an `rt.Result`, `Ok` to continue. Refuse a type without a JS value where a value of it is made or received, not at each variable that holds one, and point each type refusal at its local. Check every local, folded temporaries included, for a type whose JS value is ambiguous, such as `Option<()>`. Free a box that was moved out of, write through a `MutexGuard`'s `deref_mut` to the place it borrows, drop a boxed or optional array, and read a box through its pointer without copying what it holds. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- quest/m2/README.md | 1 - quest/m2/ts-mir-census.md | 30 ----- ts/README.md | 12 +- ts/fixtures/lang/expected/harness.ts | 8 +- ts/fixtures/lang/expected/shapes.ts | 159 +++++++++++++++++++++- ts/fixtures/lang/src/harness.rs | 5 +- ts/fixtures/lang/src/shapes.rs | 84 ++++++++++++ ts/fixtures/reject/census.md | 76 ++++++----- ts/fixtures/reject/expected.txt | 22 ++-- ts/fixtures/task/expected/model.Guard.ts | 17 +++ ts/fixtures/task/expected/model.ts | 160 ++++++++++++++--------- ts/fixtures/task/src/model.rs | 20 ++- ts/src/lower/drop.rs | 24 +++- ts/src/lower/library.rs | 42 +++++- ts/src/lower/mir/call.rs | 96 ++++++++------ ts/src/lower/mir/coroutine.rs | 3 +- ts/src/lower/mir/mod.rs | 61 ++++++--- ts/src/lower/mir/place.rs | 4 +- ts/src/lower/mir/rvalue.rs | 15 ++- ts/src/lower/mir/step.rs | 5 +- ts/src/lower/mod.rs | 128 ++++++++++++++---- 21 files changed, 717 insertions(+), 255 deletions(-) delete mode 100644 quest/m2/ts-mir-census.md diff --git a/quest/m2/README.md b/quest/m2/README.md index ca580d60c..a2d3b0856 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -22,7 +22,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md); ## Required - [Cheaper byte slices](/quest/m2/ts-byte-views.md) - splitting a `&[u8]` stops making a `Uint8Array` view per split -- [MIR's own census refusals](/quest/m2/ts-mir-census.md) - the census refuses no function THIR translated, and points type refusals at their locals - [Smaller output from MIR](/quest/m2/ts-mir-size.md) - the bench's bundles shrink back to THIR's sizes, coroutine classes first - [Wide-integer runtime off bigint](/quest/m2/ts-wide-bigint.md) - checked sums, 128-bit quotients, and comparisons with numbers stop going through `bigint`, kept only if measured faster - [Drop in the TypeScript translator](/quest/m2/ts-drop.md) - every value that drops in moq-net and kio drops where Rust drops it diff --git a/quest/m2/ts-mir-census.md b/quest/m2/ts-mir-census.md deleted file mode 100644 index be4b2abba..000000000 --- a/quest/m2/ts-mir-census.md +++ /dev/null @@ -1,30 +0,0 @@ -# [S] MIR's own census refusals - -## Goal - -[rust2-ts](/ts/README.md)'s census of moq-net and kio refuses no function the THIR -lowering translated, and each refusal of a type points at the local or expression that -holds it rather than at its function. - -## Plan - -At the move to MIR, 16 function instances of moq-net and kio that THIR translated -clean, before collections landed, are refused: - -- `unsupported type ... from another crate` for temporaries THIR never declared - (`Patterns`, `Duration`, kio's `Mut`, `Shared`, and `Consumer`, an atomic, - `MaybeUninit`), reported at the function's span. Each should carry its local's span, - from `local_decls`. -- Drops THIR's scopes never saw: `Option>`, `AdapterSend`, `Box<[..]>`, - `Box`'s `Drop`, and an `Option` replaced through a `&mut`. - -MIR also refuses constructs THIR wrote differently: - -- `ControlFlow` values other than the one `?` makes (27 sites): pick a representation, - such as `rt.Result`'s shape or a tagged object, by what `try_fold` and moq's own uses - need. -- A switch on, or a field of, a type from another crate without a mapping - (`kio::Unused`, `Bound`, `MaybeUninit`, `ManuallyDrop`). -- A switch on `char` (6), once `char` has a representation. - -Public API: the translator's output for the functions it newly translates. diff --git a/ts/README.md b/ts/README.md index 4516f2aa5..b60fd8af4 100644 --- a/ts/README.md +++ b/ts/README.md @@ -10,7 +10,10 @@ It runs `cargo check` on the package with itself as `RUSTC_WRAPPER`, for `wasm32-unknown-unknown`. Every crate compiles as rustc would; the configured library is also translated, after type and borrow checking, starting from its roots and following what they reach. A construct outside the subset is a compile error with its span, and -then nothing is written. +then nothing is written. A type without a JS value is refused where a value of it is made +or received, such as a parameter, a field, or a call, rather than again at each variable +holding one; any variable or temporary that holds a type whose JS value is ambiguous, such +as `Option<()>`, is refused at its own span. ```toml # ts.toml, beside the package's Cargo.toml unless --manifest-path says otherwise. @@ -60,6 +63,7 @@ runtime: what std does that JS does not, with iterators in `rt/iter.ts`, collect | `enum` | a union of objects tagged by variant | | `Option` | `T \| undefined`; refused if `T` can already be `undefined`, as `()` and `Option` can | | `Result` | `rt.Result`: `{ ok: true, value }` or `{ ok: false, error }` | +| `ControlFlow` | `rt.Result`, `Ok` to continue; what `?` branches on is the value it was applied to | | tuple, `[T; N]`, `&[T]`, `Vec` | an array, `Uint8Array` for bytes, `rt.ByteVec` for `Vec` | | `&T`, `&mut T`, `Box` | the value: a `&mut` must point at an object JS can change in place | | an iterator | `rt.Iter`, whose adaptors are runtime functions: `rt.iterMap(rt.iterSlice(v), f)` | @@ -283,9 +287,9 @@ own `impl Iterator` with `next_back`, `len`, or another provided method of its o format specs (a precision, `+`, `{:b}`, `{:x?}`, and widths from arguments), writing to a `String` with `write!`, a copy of a closure that changes what it captured, `mem::swap`, `replace`, or `take` of a reference's whole pointee, assigning an `Arc`, a waker, a -`MutexGuard`, a pinned reference, or a future through a reference, a `ControlFlow` other -than the one `?` makes, a switch on or a field of another crate's type without a mapping, -and std functions without a mapping in `src/lower/library.rs`. +`MutexGuard`, a pinned reference, or a future through a reference, a switch on or a +field of another crate's type without a mapping, and std functions without a mapping in +`src/lower/library.rs`. ## Tests diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 14f96c4f4..6d19d5310 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -6,7 +6,7 @@ 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"; import { adaptors, consumers, ranges, options, own, values } from "./iters.ts"; -import { copies, order, discriminants, loops, patterns, closures, library } from "./shapes.ts"; +import { copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts"; /** Run one case. */ export function run(input: Uint8Array): rt.ByteVec { @@ -24,7 +24,7 @@ export function run(input: Uint8Array): rt.ByteVec { _10 = [input[0], input[1]] as [rt.u8, rt.u8]; op = _10[0]; kind = _10[1]; - _14 = rt.u8Rem(op, 38); + _14 = rt.u8Rem(op, 39); if (_14 === 0) { u8Op(kind, input.subarray(2, input.length - 0), out); } else if (_14 === 1) { @@ -117,8 +117,10 @@ export function run(input: Uint8Array): rt.ByteVec { sets(kind, input.subarray(2, input.length - 0), out); } else if (_14 === 36) { btreeMaps(kind, input.subarray(2, input.length - 0), out); - } else { + } else if (_14 === 37) { deques(input.subarray(2, input.length - 0), out); + } else { + flows(input.subarray(2, input.length - 0), out); } return out; } diff --git a/ts/fixtures/lang/expected/shapes.ts b/ts/fixtures/lang/expected/shapes.ts index 1ec7b3610..f3e7177bd 100644 --- a/ts/fixtures/lang/expected/shapes.ts +++ b/ts/fixtures/lang/expected/shapes.ts @@ -121,6 +121,9 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void { let _66!: Point.Point; let _71!: rt.u8; let _73!: rt.u8; + let boxed!: Moved.Moved; + let _81!: rt.u16; + let _83!: rt.u16; let n!: rt.u32; let both!: [rt.u32, rt.u32]; let word!: Uint8Array; @@ -128,7 +131,7 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void { let cell!: Uint8Array; let source!: Uint8Array; let returned!: Uint8Array; - let _128!: rt.u8; + let _145!: rt.u8; let marked!: boolean; let opt!: Meters.Meters | undefined; let taken!: Meters.Meters | undefined; @@ -136,6 +139,8 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void { let first!: Point.Point; let fail!: rt.Result; let err!: Point.Point; + let _195!: Moved.Moved; + let _198!: Moved.Moved; p = Point.new(rt.optionUnwrapOr(rt.sliceFirst(data), 0) as rt.i32, 7); q = rt.copy(p); _9 = rt.i32Add(q.x, 100); @@ -175,7 +180,6 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void { const swapped = a; a = b; b = swapped; - undefined; _66 = Point.new(5, 6); const old2 = a; a = rt.copy(_66); @@ -183,6 +187,15 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void { _71 = a.x & 0xff; _73 = b.x & 0xff; rt.byteVecExtendFromSlice(out, Uint8Array.of(_71, _73, old.x & 0xff)); + boxed = { _0: data.length & 0xff, _1: 0 }; + _81 = rt.u16Add(boxed._1, 1); + _198 = boxed; + _198._1 = _81; + _83 = rt.u16Add(boxed._1, 2); + _195 = boxed; + _195._1 = _83; + rt.byteVecExtendFromSlice(out, Uint8Array.of(boxed._0)); + rt.byteVecExtendFromSlice(out, rt.u16ToBeBytes(boxed._1)); n = data.length as rt.u32; both = [n, n] as [rt.u32, rt.u32]; n = 9; @@ -196,8 +209,8 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void { source = Uint8Array.of(data.length & 0xff); returned = same(rt.copy(source)); source[0] = 9; - _128 = returned[0]; - rt.byteVecExtendFromSlice(out, Uint8Array.of(_128, source[0])); + _145 = returned[0]; + rt.byteVecExtendFromSlice(out, Uint8Array.of(_145, source[0])); rt.byteVecPush(out, copyThenWrite([data.length & 0xff, 0] as [rt.u8, rt.u8])); marked = mark(out, 1) === 0; mark(out, 2); @@ -1505,4 +1518,142 @@ export function library(data: Uint8Array, out: rt.ByteVec): void { } } +/** Steps a total by `x`: breaks with what it can't take, or continues with the new total. */ +export function step(total: rt.u16, x: rt.u8): rt.Result { + let _3!: rt.u16 | undefined; + _3 = rt.u16CheckedAdd(total, rt.u16Mul(x as rt.u16, 64)); + if (!(x === 0)) { + if (_3 === undefined) { + return rt.Err(255); + } else if (!(_3 > 8192)) { + return rt.Ok(_3); + } else { + return rt.Err(x); + } + } else { + return rt.Err(undefined); + } +} + +/** A step that may be pending, as a polled read is. */ +export function polled(x: rt.u8): rt.Poll, rt.u8>> { + let _2!: rt.u8; + _2 = rt.u8Rem(x, 4); + if (_2 === 0) { + return rt.Pending; + } else if (_2 === 1) { + return rt.Err(x); + } else if (_2 === 2) { + return rt.Ok(rt.Err(undefined)); + } else { + return rt.Ok(rt.Ok(undefined)); + } +} + +/** + * `ControlFlow`s made by hand rather than by `?`, and a value replaced through a + * `MutexGuard`. + */ +export function flows(data: Uint8Array, out: rt.ByteVec): void { + let total!: rt.u16; + let iterS!: Uint8Array; + let iterI!: number; + let _7!: rt.u8 | rt.Done; + let x!: rt.u8; + let flow!: rt.Result; + let _28!: rt.Poll, rt.u8>>; + let a!: rt.u8; + let result!: rt.Result; + let option!: rt.u8 | undefined; + let slot!: rt.Mutex; + let iterS2!: Uint8Array; + let iterI2!: number; + let _82!: rt.u8 | rt.Done; + let x2!: rt.u8; + let held!: rt.Mutex; + let _89!: boolean; + let _90!: rt.u8 | undefined; + let _105!: rt.Mutex; + total = 0; + iterS = data; + iterI = 0; + while (true) { + _7 = iterI < iterS.length ? iterS[iterI++] : rt.DONE; + if (_7 === rt.DONE) { + rt.byteVecExtendFromSlice(out, rt.u16ToBeBytes(total)); + a = rt.optionUnwrapOr(rt.sliceFirst(data), 0); + if (rt.u8Rem(a, 3) === 0) { + result = rt.Err(a); + } else { + result = rt.Ok(rt.u16Add(a as rt.u16, 256)); + } + rt.byteVecPush(out, result.ok ? 1 : 0); + if (result.ok) { + rt.byteVecExtendFromSlice(out, rt.u16ToBeBytes(result.value)); + } else { + rt.byteVecPush(out, (result as { ok: false; error: rt.u8 }).error); + } + if (rt.u8Rem(a, 5) === 0) { + option = undefined; + } else { + option = rt.u8Div(a, 5); + } + rt.byteVecPush(out, option === undefined ? 1 : 0); + if (option !== undefined) { + rt.byteVecPush(out, option); + } else { + rt.byteVecPush(out, 253); + } + slot = new rt.Mutex(undefined); + iterS2 = data; + iterI2 = 0; + while (true) { + _82 = iterI2 < iterS2.length ? iterS2[iterI2++] : rt.DONE; + if (_82 === rt.DONE) { + _105 = slot; + rt.byteVecPush(out, rt.optionUnwrapOr(_105.value, 252)); + return; + } else { + x2 = _82; + held = slot; + _90 = held.value; + b7: { + if (_90 !== undefined) { + if (_90 >= x2) { + _89 = true; + break b7; + } + } + _89 = false; + } + if (!_89) { + held.value = x2; + } + } + } + } else { + x = _7; + flow = step(total, x); + rt.byteVecExtendFromSlice(out, Uint8Array.of(!flow.ok ? 1 : 0, flow.ok ? 1 : 0)); + if (flow.ok) { + total = flow.value; + } else if (flow.error === undefined) { + rt.byteVecPush(out, 254); + } else { + rt.byteVecPush(out, flow.error); + } + _28 = polled(x); + if (_28 !== rt.Pending) { + if (_28.ok) { + rt.byteVecPush(out, rt.u8Add(2, !_28.value.ok ? 1 : 0)); + } else { + rt.byteVecPush(out, _28.error); + } + } else { + rt.byteVecPush(out, 0); + } + } + } +} + //# sourceMappingURL=shapes.ts.map diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index c08b3ec40..3fda7250d 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -19,7 +19,7 @@ pub fn run(input: &[u8]) -> Vec { return out; }; let (op, kind) = (*op, *kind); - match op % 38 { + match op % 39 { 0 => ints::u8_op(kind, data, &mut out), 1 => ints::u16_op(kind, data, &mut out), 2 => ints::u32_op(kind, data, &mut out), @@ -67,7 +67,8 @@ pub fn run(input: &[u8]) -> Vec { 34 => collections::hash_maps(kind, data, &mut out), 35 => collections::sets(kind, data, &mut out), 36 => collections::btree_maps(kind, data, &mut out), - _ => collections::deques(data, &mut out), + 37 => collections::deques(data, &mut out), + _ => shapes::flows(data, &mut out), } out } diff --git a/ts/fixtures/lang/src/shapes.rs b/ts/fixtures/lang/src/shapes.rs index aac088ae8..2a8723935 100644 --- a/ts/fixtures/lang/src/shapes.rs +++ b/ts/fixtures/lang/src/shapes.rs @@ -1,5 +1,10 @@ //! Control flow, patterns, aggregates, closures, and traits. +use std::convert::Infallible; +use std::ops::ControlFlow; +use std::sync::Mutex; +use std::task::Poll; + use crate::fmt::Pair; /// A `Copy` struct, which Rust copies where JS would share. @@ -174,6 +179,14 @@ pub fn copies(data: &[u8], out: &mut Vec) { let old = std::mem::replace(&mut a, Point::new(5, 6)); out.extend_from_slice(&[a.x as u8, b.x as u8, old.x as u8]); + // A box is its contents: a write through it, or through a borrow of it, changes them. + let mut boxed = Box::new(Moved(data.len() as u8, 0)); + boxed.1 += 1; + let held = &mut boxed; + held.1 += 2; + out.extend_from_slice(&[boxed.0]); + out.extend_from_slice(&boxed.1.to_be_bytes()); + // A tuple keeps the values it was made of, though the variable they came from changes. let mut n = data.len() as u32; let both = (n, n); @@ -1020,3 +1033,74 @@ pub fn library(data: &[u8], out: &mut Vec) { Err(_) => out.push(0), } } + +/// Steps a total by `x`: breaks with what it can't take, or continues with the new total. +fn step(total: u16, x: u8) -> ControlFlow, u16> { + match total.checked_add(u16::from(x) * 0x40) { + _ if x == 0 => ControlFlow::Break(None), + Some(n) if n > 0x2000 => ControlFlow::Break(Some(x)), + Some(n) => ControlFlow::Continue(n), + None => ControlFlow::Break(Some(0xff)), + } +} + +/// A step that may be pending, as a polled read is. +fn polled(x: u8) -> Poll, u8>> { + match x % 4 { + 0 => Poll::Pending, + 1 => Poll::Ready(Err(x)), + 2 => Poll::Ready(Ok(ControlFlow::Break(()))), + _ => Poll::Ready(Ok(ControlFlow::Continue(()))), + } +} + +/// `ControlFlow`s made by hand rather than by `?`, and a value replaced through a +/// `MutexGuard`. +pub fn flows(data: &[u8], out: &mut Vec) { + let mut total = 0u16; + for &x in data { + let flow = step(total, x); + out.extend_from_slice(&[flow.is_break() as u8, flow.is_continue() as u8]); + match flow { + ControlFlow::Continue(n) => total = n, + ControlFlow::Break(Some(b)) => out.push(b), + ControlFlow::Break(None) => out.push(0xfe), + } + match polled(x) { + Poll::Pending => out.push(0), + Poll::Ready(Err(e)) => out.push(e), + Poll::Ready(Ok(flow)) => out.push(2 + flow.is_break() as u8), + } + } + out.extend_from_slice(&total.to_be_bytes()); + + // The two shapes `?` branches on, made by hand. + let a = data.first().copied().unwrap_or(0); + let result: ControlFlow, u16> = match a % 3 { + 0 => ControlFlow::Break(Err(a)), + _ => ControlFlow::Continue(u16::from(a) + 0x100), + }; + out.push(result.is_continue() as u8); + match result { + ControlFlow::Continue(n) => out.extend_from_slice(&n.to_be_bytes()), + ControlFlow::Break(Err(e)) => out.push(e), + } + let option: ControlFlow, u8> = match a % 5 { + 0 => ControlFlow::Break(None), + _ => ControlFlow::Continue(a / 5), + }; + out.push(option.is_break() as u8); + match option { + ControlFlow::Continue(n) => out.push(n), + ControlFlow::Break(None) => out.push(0xfd), + } + + let slot = Mutex::new(None); + for &x in data { + let mut held = slot.lock().unwrap(); + if !matches!(*held, Some(h) if h >= x) { + *held = Some(x); + } + } + out.push(slot.lock().unwrap().unwrap_or(0xfc)); +} diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index d6b6403da..57b536e21 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,6 +1,6 @@ # Census of `reject-fixture` -- Refusals: 69 +- Refusals: 73 - Function instances: 61 - Generic functions no instance reached, lowered over their type parameters: 3 @@ -8,14 +8,14 @@ | Count | Construct | First | | ---: | --- | --- | +| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:31:15 | | 6 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:20:2 | -| 5 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:19:1 | +| 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 | -| 4 | unsupported type `_` | fixtures/reject/src/lib.rs:6:1 | -| 3 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:31:1 | +| 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:133:2 | -| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:159:1 | +| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:159:20 | | 2 | a field of `_` | fixtures/reject/src/lib.rs:326:7 | | 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:218:1 | | 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:204:23 | @@ -57,20 +57,20 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | -| 5 | `f64` | fixtures/reject/src/lib.rs:6:1 | -| 4 | `Option` | fixtures/reject/src/lib.rs:31:1 | +| 7 | `Option` | fixtures/reject/src/lib.rs:31:15 | +| 6 | `f64` | fixtures/reject/src/lib.rs:6:14 | | 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:59:2 | -| 4 | `u32` | fixtures/reject/src/lib.rs:19:1 | +| 4 | `u32` | fixtures/reject/src/lib.rs:19:13 | | 4 | `u8` | fixtures/reject/src/lib.rs:90:10 | | 3 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:331:6 | | 2 | `HashMap` | fixtures/reject/src/lib.rs:331:6 | | 2 | `Iterator` | fixtures/reject/src/lib.rs:198:2 | | 2 | `Meters` | fixtures/reject/src/lib.rs:133:2 | -| 2 | `Poll` | fixtures/reject/src/lib.rs:159:1 | -| 2 | `char` | fixtures/reject/src/lib.rs:10:1 | +| 2 | `Poll` | fixtures/reject/src/lib.rs:159:20 | +| 2 | `char` | fixtures/reject/src/lib.rs:10:18 | | 2 | `std::option::Option` | fixtures/reject/src/lib.rs:290:4 | | 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:175:2 | -| 2 | `std::string::String` | fixtures/reject/src/lib.rs:120:1 | +| 2 | `std::string::String` | fixtures/reject/src/lib.rs:120:16 | | 2 | `std::sync::Arc` | fixtures/reject/src/lib.rs:151:1 | | 1 | `Boxed` | fixtures/reject/src/lib.rs:75:1 | | 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:218:1 | @@ -82,7 +82,7 @@ The type or module each refused type or path belongs to. | 1 | `Noisy` | fixtures/reject/src/lib.rs:285:20 | | 1 | `Slot` | fixtures/reject/src/lib.rs:73:1 | | 1 | `[u8; 1]` | fixtures/reject/src/lib.rs:309:22 | -| 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:14:1 | +| 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:14:16 | | 1 | `std::collections::HashSet` | fixtures/reject/src/lib.rs:354:6 | | 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:231:51 | | 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:204:23 | @@ -101,13 +101,13 @@ The type or module each refused type or path belongs to. | Count | Construct | Type or path | First | | ---: | --- | --- | --- | -| 3 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:31:1 | -| 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:159:1 | -| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u32`, `u32` | fixtures/reject/src/lib.rs:19:1 | +| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:31: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:159: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 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:175:2 | | 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:133:2 | -| 2 | unsupported type `_` | `f64` | fixtures/reject/src/lib.rs:6:1 | | 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:336:6 | | 1 | `_` is generic and implements `Drop`, which is not supported yet | `Boxed` | fixtures/reject/src/lib.rs:75:1 | | 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:371:6 | @@ -115,7 +115,7 @@ The type or module each refused type or path belongs to. | 1 | `_` of `_`, which may drop what it holds, which is not supported yet | `HashMap::clear`, `std::collections::HashMap` | fixtures/reject/src/lib.rs:331:6 | | 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:379:9 | | 1 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut Slot`, `Slot` | fixtures/reject/src/lib.rs:73:1 | -| 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:120:1 | +| 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:120:16 | | 1 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:90:10 | | 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:144: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:231:51 | @@ -148,11 +148,22 @@ The type or module each refused type or path belongs to. | 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:239: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:1 | -| 1 | unsupported type `_` | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:14:1 | +| 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 | ## Spans +
`_` 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:164:19: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:336:2: `Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` + +
+
an assignment through a reference to `_` (6) - fixtures/reject/src/lib.rs:20:2: an assignment through a reference to `u32` @@ -166,11 +177,11 @@ The type or module each refused type or path belongs to.
`_`: a JS value of `_` is a copy, so a reference can't change it (5) -- fixtures/reject/src/lib.rs:19:1: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:24:1: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it +- 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:73:1: `&mut Slot`: a JS value of `Slot` is a copy, so a reference can't change it - fixtures/reject/src/lib.rs:90:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:120:1: `&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:120:16: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it
@@ -184,20 +195,13 @@ The type or module each refused type or path belongs to.
-
unsupported type `_` (4) +
unsupported type `_` (5) -- fixtures/reject/src/lib.rs:6:1: unsupported type `f64` -- fixtures/reject/src/lib.rs:10:1: unsupported type `char` -- fixtures/reject/src/lib.rs:14:1: unsupported type `dyn std::ops::Fn(u8) -> u8` -- fixtures/reject/src/lib.rs:142:1: unsupported type `f64` - -
- -
`_` is not supported: its `None` and `Some` would both be `undefined` (3) - -- fixtures/reject/src/lib.rs:31:1: `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:164:1: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- 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:142:51: unsupported type `f64`
@@ -219,7 +223,7 @@ The type or module each refused type or path belongs to.
`_` is not supported: it would be pending two ways with one value (2) -- fixtures/reject/src/lib.rs:159:1: `Poll>>` is not supported: it would be pending two ways with one value +- fixtures/reject/src/lib.rs:159:20: `Poll>>` is not supported: it would be pending two ways with one value - fixtures/reject/src/lib.rs:169:54: `Poll>` is not supported: it would be pending two ways with one value
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index cec4e6cd1..8577d3a02 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -1,17 +1,20 @@ a root must not be generic at fixtures/reject/src/lib.rs:142:1 no item `missing` in the crate a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:140:1 -unsupported type `f64` at fixtures/reject/src/lib.rs:6: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 `char` at fixtures/reject/src/lib.rs:10:1 +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:1 -`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:19:1 +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:24:1 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:31:1 +`&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 @@ -31,15 +34,15 @@ hex `Debug`, as in `{:x?}`, is not supported at fixtures/reject/src/lib.rs:113:3 a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:114:15 a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:114:3 `Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:115: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:120:1 +`&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:120:16 unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:122:10 a constant of type `&u8` at fixtures/reject/src/lib.rs:128:2 replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:133:2 replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:137:2 dropping `std::sync::Arc<&Noisy>`, which is not supported yet at fixtures/reject/src/lib.rs:151:1 an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:155:2 -`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:159:1 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:164:1 +`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:159:20 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:164:19 `Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:169:54 an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:175:2 an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:180:2 @@ -58,6 +61,7 @@ a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs: a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:326:7 a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:326:48 `HashMap::clear` of `std::collections::HashMap`, which may drop what it holds, which is not supported yet at fixtures/reject/src/lib.rs:331:6 +`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:336:2 `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:336:6 hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:341:52 comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:341:52 diff --git a/ts/fixtures/task/expected/model.Guard.ts b/ts/fixtures/task/expected/model.Guard.ts index 3204e1ab4..f5bad1d82 100644 --- a/ts/fixtures/task/expected/model.Guard.ts +++ b/ts/fixtures/task/expected/model.Guard.ts @@ -53,6 +53,23 @@ export function finish(self: Guard, event: string): rt.u32 { } } +/** [`Self::finish`], moved out of its box: freeing the box must not drop it again. */ +export function unbox(self: Guard, event: string): rt.u32 { + let _0!: rt.u32; + let unwind: number = 0; + try { + unwind = 5; + _0 = finish(self, event); + unwind = 0; + return _0; + } catch (e) { + if (unwind === 0) { + throw e; + } + throw e; + } +} + export function drop$Drop(self: Guard): void { let _4!: string; let args2!: rt.Fmt[]; diff --git a/ts/fixtures/task/expected/model.ts b/ts/fixtures/task/expected/model.ts index 38ce177be..9b038e4b8 100644 --- a/ts/fixtures/task/expected/model.ts +++ b/ts/fixtures/task/expected/model.ts @@ -1296,8 +1296,9 @@ export function pick(log: Log.Log, i: rt.usize): rt.usize { * guards destructured in part: the one left in the array drops with it, after the other; * a pinned box of one, which drops it; `ref` bindings, which borrow a variable and keep a * temporary to the end of the block; a `_` binding of an element, which evaluates its - * index and moves nothing; a boxed guard read twice, which a read leaves boxed; and a - * guard a method takes by value, which drops inside it. + * index and moves nothing; a boxed guard read twice, which a read leaves boxed; a guard + * a method takes by value, which drops inside it, once from a box; and a boxed array of + * guards that may be absent, which drops them in order. */ export function turns(log: Log.Log, count: rt.u32): void { let pair!: Guard.Guard[]; @@ -1314,30 +1315,35 @@ export function turns(log: Log.Log, count: rt.u32): void { let args4!: rt.Fmt[]; let _70!: rt.Fmt; let args6!: rt.Fmt[]; + let args8!: rt.Fmt[]; + let stacked!: Guard.Guard[] | undefined; + let _112!: Guard.Guard; + let _116!: Guard.Guard; + let args10!: rt.Fmt[]; let spares!: Guard.Guard[]; - let _91!: Guard.Guard; - let _95!: Guard.Guard; - let _99!: rt.usize; + let _133!: Guard.Guard; + let _137!: Guard.Guard; + let _141!: rt.usize; let left!: rt.u32; let turn!: Guard.Guard; - let _119!: rt.u32; + let _161!: rt.u32; let unwind: number = 0; try { _4 = Guard.new(rt.u32Add(count, 10), Log.clone$Clone(log)); - unwind = 94; + unwind = 124; _8 = Guard.new(rt.u32Add(count, 20), Log.clone$Clone(log)); - unwind = 93; + unwind = 123; pair = [_4, _8]; kept = pair[0]; Guard.note(kept, "kept"); pinned = Guard.new(rt.u32Add(count, 40), Log.clone$Clone(log)); - unwind = 92; + unwind = 122; Guard.note(pinned, "pinned"); held = Guard.new(rt.u32Add(count, 50), Log.clone$Clone(log)); - unwind = 91; + unwind = 121; Guard.note(held, "borrowed"); _34 = Guard.new(rt.u32Add(count, 60), Log.clone$Clone(log)); - unwind = 90; + unwind = 120; Guard.note(_34, "extended"); _42 = Guard.new(rt.u32Add(count, 90), Log.clone$Clone(log)); scoped = _42.id; @@ -1346,7 +1352,7 @@ export function turns(log: Log.Log, count: rt.u32): void { args2 = [(f: rt.Formatter) => rt.u32Display(arg, f)]; Log.note(log, rt.fmtFormat(["after ", args2[0]])); boxed = Guard.new(rt.u32Add(count, 100), Log.clone$Clone(log)); - unwind = 89; + unwind = 119; const arg2 = boxed.id; _70 = (f: rt.Formatter) => rt.u32Display(arg2, f); const arg3 = boxed.id; @@ -1355,16 +1361,32 @@ export function turns(log: Log.Log, count: rt.u32): void { const arg4 = ([Guard.finish(Guard.new(rt.u32Add(count, 110), Log.clone$Clone(log)), "finishing")] as [rt.u32])[0]; args6 = [(f: rt.Formatter) => rt.u32Display(arg4, f)]; Log.note(log, rt.fmtFormat(["finished ", args6[0]])); - _91 = Guard.new(rt.u32Add(count, 70), Log.clone$Clone(log)); - unwind = 88; - _95 = Guard.new(rt.u32Add(count, 80), Log.clone$Clone(log)); - unwind = 87; - spares = [_91, _95]; - _99 = pick(log, rt.usizeRem(count as rt.usize, 2)); - if (!(_99 < 2)) { - rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _99); + const arg5 = ([Guard.unbox(Guard.new(rt.u32Add(count, 120), Log.clone$Clone(log)), "unboxing")] as [rt.u32])[0]; + args8 = [(f: rt.Formatter) => rt.u32Display(arg5, f)]; + Log.note(log, rt.fmtFormat(["unboxed ", args8[0]])); + if (rt.u32Rem(count, 2) === 0) { + _112 = Guard.new(rt.u32Add(count, 130), Log.clone$Clone(log)); + unwind = 118; + _116 = Guard.new(rt.u32Add(count, 140), Log.clone$Clone(log)); + unwind = 119; + stacked = [_112, _116]; + } else { + stacked = undefined; + } + unwind = 117; + const arg6 = ([stacked !== undefined] as [boolean])[0]; + args10 = [(f: rt.Formatter) => rt.fmtBool(arg6, f)]; + Log.note(log, rt.fmtFormat(["stacked ", args10[0]])); + _133 = Guard.new(rt.u32Add(count, 70), Log.clone$Clone(log)); + unwind = 116; + _137 = Guard.new(rt.u32Add(count, 80), Log.clone$Clone(log)); + unwind = 115; + spares = [_133, _137]; + _141 = pick(log, rt.usizeRem(count as rt.usize, 2)); + if (!(_141 < 2)) { + rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _141); } - b0: { + b1: { if (count === 0) { Log.note(log, rt.fmtFormat(["no turns"])); } else if (!(count < 4)) { @@ -1374,68 +1396,78 @@ export function turns(log: Log.Log, count: rt.u32): void { while (true) { turn = Guard.new(left, Log.clone$Clone(log)); if (!(left === 1)) { - unwind = 86; + unwind = 114; Guard.note(turn, "turn"); - _119 = rt.u32Sub(left, 1); - unwind = 87; - left = _119; + _161 = rt.u32Sub(left, 1); + unwind = 115; + left = _161; rt.drop(turn); } else { rt.drop(turn); - break b0; + break b1; } } } } - unwind = 89; + unwind = 117; rt.dropAll(spares); - unwind = 90; + unwind = 119; + rt.dropAll(stacked); + unwind = 120; rt.drop(boxed); - unwind = 91; + unwind = 121; rt.drop(_34); - unwind = 92; + unwind = 122; rt.drop(held); - unwind = 93; + unwind = 123; rt.drop(pinned); - unwind = 96; + unwind = 126; rt.drop(kept); unwind = 0; rt.dropAll(pair.slice(1, 2)); } catch (e) { - b2: { - b3: { - b4: { - b5: { - b6: { - b7: { - b8: { - if (unwind === 0) { - throw e; - } - if (unwind === 86) { - rt.drop(turn); - } else if (unwind !== 87) { - if (unwind === 88) { - rt.drop(_91); - break b8; - } else if (unwind === 89) { - break b8; - } else if (unwind === 90) { - break b7; - } else if (unwind === 91) { - break b6; - } else if (unwind === 92) { - break b5; - } else if (unwind === 93) { - break b4; - } else if (unwind === 94) { - rt.drop(_4); - break b2; - } else { - break b3; + b3: { + b4: { + b5: { + b6: { + b7: { + b8: { + b9: { + b10: { + if (unwind === 0) { + throw e; + } + if (unwind === 114) { + rt.drop(turn); + } else if (unwind !== 115) { + if (unwind === 116) { + rt.drop(_133); + break b10; + } else if (unwind === 117) { + break b10; + } else if (unwind === 118) { + rt.drop(_112); + break b9; + } else if (unwind === 119) { + break b9; + } else if (unwind === 120) { + break b8; + } else if (unwind === 121) { + break b7; + } else if (unwind === 122) { + break b6; + } else if (unwind === 123) { + break b5; + } else if (unwind === 124) { + rt.drop(_4); + break b3; + } else { + break b4; + } } + rt.dropAll(spares); } - rt.dropAll(spares); + rt.dropAll(stacked); } rt.drop(boxed); } diff --git a/ts/fixtures/task/src/model.rs b/ts/fixtures/task/src/model.rs index 2be0352b8..d2e05aa1b 100644 --- a/ts/fixtures/task/src/model.rs +++ b/ts/fixtures/task/src/model.rs @@ -78,6 +78,11 @@ impl Guard { self.note(event); self.id } + + /// [`Self::finish`], moved out of its box: freeing the box must not drop it again. + fn unbox(self: Box, event: &str) -> u32 { + (*self).finish(event) + } } impl Drop for Guard { @@ -270,8 +275,9 @@ fn pick(log: &Log, i: usize) -> usize { /// guards destructured in part: the one left in the array drops with it, after the other; /// a pinned box of one, which drops it; `ref` bindings, which borrow a variable and keep a /// temporary to the end of the block; a `_` binding of an element, which evaluates its -/// index and moves nothing; a boxed guard read twice, which a read leaves boxed; and a -/// guard a method takes by value, which drops inside it. +/// index and moves nothing; a boxed guard read twice, which a read leaves boxed; a guard +/// a method takes by value, which drops inside it, once from a box; and a boxed array of +/// guards that may be absent, which drops them in order. #[expect(clippy::toplevel_ref_arg, reason = "the `ref` bindings are under test")] fn turns(log: &Log, count: u32) { let pair = [Guard::new(count + 10, log.clone()), Guard::new(count + 20, log.clone())]; @@ -294,6 +300,16 @@ fn turns(log: &Log, count: u32) { log.note(format!("boxed {once} {}", boxed.id)); let finished = Guard::new(count + 110, log.clone()).finish("finishing"); log.note(format!("finished {finished}")); + let unboxed = Box::new(Guard::new(count + 120, log.clone())).unbox("unboxing"); + log.note(format!("unboxed {unboxed}")); + let stacked = match count % 2 { + 0 => Some(Box::new([ + Guard::new(count + 130, log.clone()), + Guard::new(count + 140, log.clone()), + ])), + _ => None, + }; + log.note(format!("stacked {}", stacked.is_some())); let spares = [Guard::new(count + 70, log.clone()), Guard::new(count + 80, log.clone())]; let _ = spares[pick(log, count as usize % 2)]; match count { diff --git a/ts/src/lower/drop.rs b/ts/src/lower/drop.rs index bceda7068..864a4c19d 100644 --- a/ts/src/lower/drop.rs +++ b/ts/src/lower/drop.rs @@ -131,11 +131,14 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { if !self.drops(ty) { return None; } + // An array or `Vec`, or one in an `Option` or a box, which is it or `undefined`. + if let Some(elem) = self.elements(ty) + && self.disposable(elem) + { + return Some(Expr::rt("dropAll", vec![value])); + } let supported = match ty.kind() { ty::Adt(adt, args) => match Std::of(self.tcx, adt.did()) { - Some(Std::Vec) if self.disposable(args.type_at(0)) => { - return Some(Expr::rt("dropAll", vec![value])); - } Some(Std::Arc | Std::Mutex | Std::Option | Std::Box | Std::Pin) => self.disposable(args.type_at(0)), Some(Std::Waker) => true, Some(_) => false, @@ -146,7 +149,6 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { } None => false, }, - ty::Array(elem, _) if self.disposable(*elem) => return Some(Expr::rt("dropAll", vec![value])), ty::Coroutine(..) | ty::Param(_) => true, _ => false, }; @@ -169,6 +171,20 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { Some(Expr::rt("drop", vec![value])) } + /// The elements of an array or `Vec` that `ty` is, or holds in an `Option` or a box, + /// whose JS value is the array or `undefined`. + fn elements(&self, ty: Ty<'tcx>) -> Option> { + match ty.kind() { + ty::Array(elem, _) => Some(*elem), + ty::Adt(adt, args) => match Std::of(self.tcx, adt.did())? { + Std::Vec => Some(args.type_at(0)), + Std::Option | Std::Box | Std::Pin => self.elements(args.type_at(0)), + _ => None, + }, + _ => None, + } + } + /// Give a class whose own fields or `Drop` impl drop its drop glue up front, so JS /// that holds one can drop it. One that drops only through a type parameter gets /// it once an instance that drops does. diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 1d26195be..1239230e6 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -64,7 +64,7 @@ pub enum Std { RangeInclusive, /// `rt.Peekable`, an iterator with `peek`. Peekable, - /// What `?` branches on, as MIR spells it: the value it was applied to. + /// What `?` branches on, as MIR spells it, and what else makes one: see [`Flow`]. ControlFlow, /// `..end`, `start..`, and `..`, as MIR makes them to slice by: `{ end }`, `{ start }`, /// and `undefined`. @@ -184,6 +184,44 @@ impl Std { } } +/// How a `ControlFlow` is represented. What `?` branches on is the value it was +/// applied to, which breaks with what can only be its `Err` or `None`. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Flow { + /// Breaking with a `Result`: the `rt.Result` `?` was applied to. + Result, + /// Breaking with an `Option`: the `C | undefined` `?` was applied to. + Option, + /// Any other: an `rt.Result`, `Ok` to continue and `Err` to break. + Other, +} + +impl Flow { + /// The representation of a `ControlFlow` with `args`, its break's type first. + pub fn of<'tcx>(tcx: TyCtxt<'tcx>, args: GenericArgsRef<'tcx>) -> Self { + let ty::Adt(adt, residual) = args.type_at(0).kind() else { + return Self::Other; + }; + let uninhabited = + |t: Ty<'tcx>| t.is_never() || matches!(t.kind(), ty::Adt(e, _) if e.is_enum() && e.variants().is_empty()); + match Std::of(tcx, adt.did()) { + Some(Std::Result) if uninhabited(residual.type_at(0)) => Self::Result, + Some(Std::Option) if uninhabited(residual.type_at(0)) => Self::Option, + _ => Self::Other, + } + } + + /// The test that `value`, a `ControlFlow` represented so, continues, or breaks. + pub fn test(self, value: Expr, continues: bool) -> Expr { + match (self, continues) { + (Self::Result | Self::Other, true) => value.member("ok"), + (Self::Result | Self::Other, false) => value.member("ok").not(), + (Self::Option, true) => value.binary("!==", Expr::undefined()), + (Self::Option, false) => value.binary("===", Expr::undefined()), + } + } +} + /// The path of a std item within its crate, as `["slice", "iter", "Iter"]`; empty for /// any other crate's. pub fn std_path(tcx: TyCtxt<'_>, did: DefId) -> Vec { @@ -515,6 +553,8 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec } ("Result", "unwrap_or") => rt2(args, "result", "unwrapOr"), + ("ControlFlow", "is_continue" | "is_break") => Flow::of(tcx, gargs).test(args.pop()?, name == "is_continue"), + // Ranges, which are their own iterators. // An integer range wraps within its type's bounds where std's `nth` does. ("RangeInclusive", "new") if range => { diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index 4643883a1..f43685ef6 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -10,7 +10,7 @@ use rustc_span::{Span, Spanned}; use super::{Fx, Slot}; use crate::lower::fmt::{self, Piece}; -use crate::lower::library::{self, Std}; +use crate::lower::library::{self, Flow, Std}; use crate::lower::num::Int; use crate::ts::{Expr, Stmt, StmtKind}; @@ -223,6 +223,20 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { if library::std_path(tcx, def_id).is_empty() { return None; } + // A box's own `Drop` frees its memory, once drop elaboration dropped or moved out + // what it holds: nothing JS sees. + let drop_trait = tcx + .trait_of_assoc(def_id) + .or_else(|| tcx.trait_impl_of_assoc(def_id).map(|imp| tcx.impl_trait_id(imp))); + if drop_trait.is_some_and(|tr| tcx.is_lang_item(tr, rustc_attr_ir::LangItem::Drop)) + && self + .b + .t + .self_ty(Instance::new_raw(def_id, gargs)) + .is_some_and(|ty| self.b.t.std_of(ty) == Some(Std::Box)) + { + return Some(Some((Expr::undefined(), false))); + } let (owner, name) = library::key(tcx, def_id)?; let targ = |n: usize| gargs.types().nth(n); let done = |e: Expr, effect: bool| Some(Some((e, effect))); @@ -262,6 +276,23 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } // Indexing, whose result a `&mut` reads in place. ("Index" | "IndexMut", "index" | "index_mut") => self.index(&name, gargs, args, dest, span, out), + // A `&mut` to a value JS copies, such as through a `MutexGuard`, reads and writes + // the place it borrows, as an index does. + ("DerefMut", "deref_mut") + if let ty::Ref(_, pointee, _) = dest.ty(&self.mir.local_decls, tcx).ty.kind() + && self.b.t.object_kind(*pointee).is_none() + && let Some(local) = dest.as_local() + && self.defs[local] == 1 + && matches!(self.slots[local], Slot::Var(_)) => + { + let place = self.call_def(def_id, gargs, args, span, out); + if !place.is_path() { + return done(place, true); + } + self.materialize(&place, out); + self.slots[local] = Slot::Alias(Some(place)); + Some(None) + } ("slice", "copy_within") => { let s = self.operand(&args[0].node, span, out); let s = self.path(s, "slice", out); @@ -651,25 +682,16 @@ fn int_named(name: &str) -> Option { Some(Int { bits, signed, pointer }) } -/// The residual a `ControlFlow` breaks with: what `?` was applied to. -fn residual<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option { - let ty::Adt(_, args) = ty.kind() else { - return None; - }; - match args.type_at(0).kind() { - ty::Adt(adt, _) => Std::of(tcx, adt.did()), - _ => None, +/// How a `ControlFlow` type is represented. +fn flow<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Flow { + match ty.kind() { + ty::Adt(_, args) => Flow::of(tcx, args), + _ => unreachable!("checked by the caller"), } } /// The test that `scrut`, a `ControlFlow`, is `Continue` (variant 0) or `Break`. -pub fn control_flow_test<'tcx>( - fx: &mut Fx<'_, '_, '_, 'tcx>, - scrut: &Expr, - ty: Ty<'tcx>, - variant: VariantIdx, - span: Span, -) -> Expr { +pub fn control_flow_test<'tcx>(fx: &mut Fx<'_, '_, '_, 'tcx>, scrut: &Expr, ty: Ty<'tcx>, variant: VariantIdx) -> Expr { let continues = variant.index() == 0; if matches!(scrut, Expr::Ident(n) if fx.next_names.contains(n)) { return match continues { @@ -677,35 +699,24 @@ pub fn control_flow_test<'tcx>( false => scrut.clone().binary("===", Expr::Rt("DONE".into())), }; } - match residual(fx.tcx, ty) { - Some(Std::Result) => match continues { - true => scrut.clone().member("ok"), - false => scrut.clone().member("ok").not(), - }, - Some(Std::Option) => match continues { - true => scrut.clone().binary("!==", Expr::undefined()), - false => scrut.clone().binary("===", Expr::undefined()), - }, - _ => fx.err(span, format!("`{ty}` other than from `?`")), - } + flow(fx.tcx, ty).test(scrut.clone(), continues) } -/// A field of a `ControlFlow`: `Continue`'s value, or `Break`'s residual, which is the -/// value `?` was applied to. +/// A field of a `ControlFlow`: `Continue`'s value, or `Break`'s, which for `?` is the +/// value it was applied to. pub fn control_flow_field<'tcx>( fx: &mut Fx<'_, '_, '_, 'tcx>, base: Expr, ty: Ty<'tcx>, variant: Option, - span: Span, ) -> Expr { let continues = variant.is_none_or(|v| v.index() == 0); - match (residual(fx.tcx, ty), continues) { - (Some(Std::Result), true) => base.member("value"), - (Some(Std::Result), false) => base, - (Some(Std::Option), true) => base, - (Some(Std::Option), false) => Expr::undefined(), - _ => fx.err(span, format!("`{ty}` other than from `?`")), + match (flow(fx.tcx, ty), continues) { + (Flow::Result | Flow::Other, true) => base.member("value"), + (Flow::Result, false) => base, + (Flow::Other, false) => base.member("error"), + (Flow::Option, true) => base, + (Flow::Option, false) => Expr::undefined(), } } @@ -715,14 +726,13 @@ pub fn control_flow<'tcx>( ty: Ty<'tcx>, variant: VariantIdx, mut values: Vec, - span: Span, ) -> Expr { let value = values.pop().unwrap_or_else(Expr::undefined); - match (residual(fx.tcx, ty), variant.index()) { - (Some(Std::Result), 0) => Expr::rt("Ok", vec![value]), - (Some(Std::Result), _) => value, - (Some(Std::Option), 0) => value, - (Some(Std::Option), _) => Expr::undefined(), - _ => fx.err(span, format!("`{ty}` other than from `?`")), + match (flow(fx.tcx, ty), variant.index()) { + (Flow::Result | Flow::Other, 0) => Expr::rt("Ok", vec![value]), + (Flow::Result, _) => value, + (Flow::Other, _) => Expr::rt("Err", vec![value]), + (Flow::Option, 0) => value, + (Flow::Option, _) => Expr::undefined(), } } diff --git a/ts/src/lower/mir/coroutine.rs b/ts/src/lower/mir/coroutine.rs index f1b1acbb7..e0219bc80 100644 --- a/ts/src/lower/mir/coroutine.rs +++ b/ts/src/lower/mir/coroutine.rs @@ -113,7 +113,8 @@ pub fn info<'tcx>(t: &mut Translator<'_, 'tcx>, def_id: DefId, args: GenericArgs let id = t.program.field(sym, name); saved.push(id); let ty = t.subst(args, field.ty); - let ty = t.ty(ty, span); + // A local held across an `.await`, refused as any variable is. + let ty = t.held_ty(ty, field.source_info.span); fields.push(ts::Field { id, ty, diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 184fb279c..4f355a119 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -46,9 +46,12 @@ pub fn function<'a, 'tcx>(t: &mut Translator<'a, 'tcx>, instance: Instance<'tcx> let mut fx = Fx::new(&mut b, &mir, Env::Plain, span); let params = fx.params(); let body = fx.lower(); + let ret_span = fx.local_span(mir::RETURN_PLACE); let ret = match (next, ret_ty.kind()) { - (true, ty::Adt(_, args)) => Type::Union(vec![fx.b.t.ty(args.type_at(0), span), Type::Rt("Done", Vec::new())]), - _ => fx.b.t.ret_ty(ret_ty, span), + (true, ty::Adt(_, args)) => { + Type::Union(vec![fx.b.t.ty(args.type_at(0), ret_span), Type::Rt("Done", Vec::new())]) + } + _ => fx.b.t.ret_ty(ret_ty, ret_span), }; Some(ts::Function { sym: 0, @@ -394,6 +397,16 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { Slot::Var(String::new()) }; self.slots[local] = slot; + // A temporary folded into what reads it is declared nowhere, so a type that can't + // tell its values apart is refused here. The signature types the parameters and + // the result. + if !self.is_arg(local) && local != mir::RETURN_PLACE { + let held = match self.next_results.contains(&local) { + true => next_item(self.tcx, ty), + false => ty, + }; + self.b.t.check_erased(held, self.local_span(local)); + } } // Names: what debug info calls a local, else its number. let mut named: FxHashMap = FxHashMap::default(); @@ -647,7 +660,10 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { { return Some(match elem.kind() { ty::Uint(ty::UintTy::U8) => Expr::ident("Uint8Array").member("of").call(Vec::new()), - _ => Expr::As(Box::new(Expr::Array(Vec::new())), self.b.t.ty(ty, self.span)), + _ => Expr::As( + Box::new(Expr::Array(Vec::new())), + self.b.t.ty(ty, self.local_span(local)), + ), }); } let ty::Adt(adt, _) = ty.kind() else { @@ -656,7 +672,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { if !adt.is_struct() || !adt.did().is_local() || adt.all_fields().next().is_some() { return None; } - let info = self.b.t.adt(*adt, self.span); + let info = self.b.t.adt(*adt, self.local_span(local)); Some(self.b.t.construct(info.sym, &ts::Ctor::Unit, &[], Vec::new())) } @@ -999,7 +1015,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { Slot::Var(name) => name.clone(), _ => self.b.fresh("_"), }; - let ty = self.b.t.ty(ty, self.span); + let ty = self.b.t.ty(ty, self.local_span(local)); params.push(Param { name, ty: Some(ty) }); } params @@ -1178,15 +1194,8 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { /// A local's declared type: the value's, for a checked pair. fn decl_ty(&mut self, local: Local) -> Type { let ty = self.mir.local_decls[local].ty; - if self.next_results.contains(&local) - && let ty::Adt(adt, args) = ty.kind() - { - // `Option`, or `?`'s `ControlFlow<_, Item>`. - let item = match crate::lower::library::Std::of(self.tcx, adt.did()) { - Some(crate::lower::library::Std::ControlFlow) => args.type_at(1), - _ => args.type_at(0), - }; - let item = self.b.t.ty(item, self.span); + if self.next_results.contains(&local) { + let item = self.b.t.held_ty(next_item(self.tcx, ty), self.local_span(local)); if self.range_nexts.contains(&local) { return item; } @@ -1194,9 +1203,20 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } let ty = match (self.checked.contains(&local), ty.kind()) { (true, ty::Tuple(tys)) => tys[0], + // A box's pointer is the box's contents in JS. + (_, ty::RawPtr(pointee, _)) if self.box_pointer(local) => *pointee, _ => ty, }; - self.b.t.ty(ty, self.span) + self.b.t.held_ty(ty, self.local_span(local)) + } + + /// Where a local is declared, which a refusal of its type points at: for drop glue, + /// whose locals are std's, where the value drops. + pub(super) fn local_span(&self, local: Local) -> Span { + match self.env { + Env::Shim => self.span, + _ => self.mir.local_decls[local].source_info.span, + } } /// Where a terminator can go, without its unwinding. @@ -2752,6 +2772,17 @@ fn inert(e: &Expr) -> bool { } } +/// The item a next result holds, as `ty`: `Option`, or `?`'s `ControlFlow<_, Item>`. +fn next_item<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + let ty::Adt(adt, args) = ty.kind() else { + unreachable!("checked by find_next_results") + }; + match crate::lower::library::Std::of(tcx, adt.did()) { + Some(crate::lower::library::Std::ControlFlow) => args.type_at(1), + _ => args.type_at(0), + } +} + /// Whether `ty` is a `Range` of numbers that fit a JS number, which steps in place. pub(super) fn small_range<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { matches!(ty.kind(), ty::Adt(adt, args) diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index d56ae15cc..52c13e00f 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -226,7 +226,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { base.member(adt.non_enum_variant().fields[field].name.as_str()) } Some(Std::Context | Std::NonNull | Std::Entry) => base, - Some(Std::ControlFlow) => super::call::control_flow_field(self, base, ty, variant, span), + Some(Std::ControlFlow) => super::call::control_flow_field(self, base, ty, variant), _ if transparent(self.b.t, ty) => base, None if adt.did().is_local() => { let info = self.b.t.adt(*adt, span); @@ -409,7 +409,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { AdtRepr::Struct { .. } => self.err(span, format!("a switch on `{ty}`")), } } - Some(Std::ControlFlow) => super::call::control_flow_test(self, scrut, ty, index, span), + Some(Std::ControlFlow) => super::call::control_flow_test(self, scrut, ty, index), Some(Std::Entry) => crate::lower::collections::entry_test(*adt, index, scrut.clone()), Some(Std::Ordering) => scrut .clone() diff --git a/ts/src/lower/mir/rvalue.rs b/ts/src/lower/mir/rvalue.rs index cacb25f66..f7bd91f16 100644 --- a/ts/src/lower/mir/rvalue.rs +++ b/ts/src/lower/mir/rvalue.rs @@ -192,8 +192,12 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } _ => self.err(span, format!("unsupported pointer coercion {coercion:?}")), }, - // A box's pointer is its contents in JS. - CastKind::BoxDerefTransmute => self.operand(op, span, out), + // A box's pointer is its contents in JS, which a read shares: the pointer's + // type is `Copy`, but what it points to is not copied. + CastKind::BoxDerefTransmute => match op { + Operand::Copy(place) | Operand::Move(place) => self.place_expr(*place, span, out), + Operand::Constant(_) | Operand::RuntimeChecks(_) => self.operand(op, span, out), + }, // An async body's context passes through `ResumeTy` and `NonNull`. CastKind::Transmute if context_like(self, from) && context_like(self, to) => self.operand(op, span, out), _ => self.err(span, format!("a `{kind:?}` cast from `{from}` to `{to}`")), @@ -318,7 +322,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { (Std::RangeFrom, _) => Expr::Object(vec![(Key::Name("start".into()), values.pop().unwrap())]), (Std::RangeFull, _) => Expr::undefined(), (Std::Ordering, _) => crate::lower::collections::ordering_variant(variant), - (Std::ControlFlow, _) => super::call::control_flow(self, ty, variant, values, span), + (Std::ControlFlow, _) => super::call::control_flow(self, ty, variant, values), (Std::Range, _) => { let ty::Adt(_, gargs) = ty.kind() else { unreachable!("a range is a struct") @@ -437,7 +441,10 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { return Expr::undefined(); }; let sig = tcx.instantiate_bound_regions_with_erased(args.as_closure().sig()); - let ret = self.b.t.ret_ty(sig.output(), span); + let ret = self + .b + .t + .ret_ty(sig.output(), mir.local_decls[mir::RETURN_PLACE].source_info.span); let mut inner = Fx::new(&mut *self.b, &mir, Env::Closure(captures), span); let params = inner.params(); let body = inner.lower(); diff --git a/ts/src/lower/mir/step.rs b/ts/src/lower/mir/step.rs index 773174e46..10eb9ef43 100644 --- a/ts/src/lower/mir/step.rs +++ b/ts/src/lower/mir/step.rs @@ -298,16 +298,17 @@ impl<'tcx> Fx<'_, '_, '_, 'tcx> { /// The types of a stepped local's variables: its array and index, or its bounds. pub(super) fn stepped_tys(&mut self, local: Local) -> [Type; 2] { let ty = self.mir.local_decls[local].ty; + let span = self.local_span(local); match array_iter(self.tcx, ty) { Some(item) => [ - self.b.t.ty(Ty::new_slice(self.tcx, item), self.span), + self.b.t.held_ty(Ty::new_slice(self.tcx, item), span), Type::Builtin("number"), ], None => { let ty::Adt(_, args) = ty.kind() else { unreachable!("a range is a struct") }; - let bound = self.b.t.ty(args.type_at(0), self.span); + let bound = self.b.t.held_ty(args.type_at(0), span); [bound.clone(), bound] } } diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 9fe8dd16c..fa473928c 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -147,6 +147,8 @@ pub struct Translator<'a, 'tcx> { pub drop_shims: rustc_data_structures::fx::FxHashMap, SymId>, /// The class of each coroutine instance. pub coroutines: rustc_data_structures::fx::FxHashMap, mir::coroutine::Info<'tcx>>, + /// Whether [`Self::ty`] is typing a variable: see [`Self::held_ty`]. + held: bool, } /// A local struct or enum, and how it is represented. @@ -209,6 +211,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { glued: Default::default(), coroutines: Default::default(), drop_shims: Default::default(), + held: false, }) } @@ -646,6 +649,14 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { if let Some(info) = self.adts.get(&adt.did()) { return info.clone(); } + // Its fields' types are refused where they are written, whatever reached it. + let held = std::mem::replace(&mut self.held, false); + let info = self.define(adt, span); + self.held = held; + info + } + + fn define(&mut self, adt: AdtDef<'tcx>, span: Span) -> Adt { let tcx = self.tcx; let did = adt.did(); let repr = match () { @@ -876,12 +887,74 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { } _ if self.deferred(ty) => Type::Builtin("unknown"), _ => { - self.err(span, format!("unsupported type `{ty}`")); + self.unrepresented(span, format!("unsupported type `{ty}`")); Type::Builtin("unknown") } } } + /// The TypeScript type of a variable that holds a `ty`. It refuses no type without a JS + /// value, which is refused where a value of it is made or received: a parameter, a + /// field, a call, or a constant. + pub fn held_ty(&mut self, ty: Ty<'tcx>, span: Span) -> Type { + let held = std::mem::replace(&mut self.held, true); + let ts = self.ty(ty, span); + self.held = held; + ts + } + + /// Refuse a type without a JS value, unless typing a variable. + fn unrepresented(&mut self, span: Span, msg: String) { + if !self.held { + self.err(span, msg); + } + } + + /// Refuse each type in `ty` whose JS value can't tell two of its values apart, as an + /// `Option` of what can already be `undefined`. + pub fn check_erased(&mut self, ty: Ty<'tcx>, span: Span) { + let mut msgs: Vec = Vec::new(); + for part in ty.walk().filter_map(|arg| arg.as_type()) { + if let Some(msg) = self.erasure_conflict(part) + && !msgs.contains(&msg) + { + msgs.push(msg); + } + } + for msg in msgs { + self.err(span, msg); + } + } + + /// Why a `ty`'s JS value, not looking inside its arguments, can't tell two of its + /// values apart, if it can't. + fn erasure_conflict(&self, ty: Ty<'tcx>) -> Option { + let ty::Adt(adt, args) = ty.kind() else { + return None; + }; + match library::Std::of(self.tcx, adt.did())? { + library::Std::Option => { + let inner = args.type_at(0); + self.erases_to(inner).undefined.then(|| { + format!("`Option<{inner}>` is not supported: its `None` and `Some` would both be `undefined`") + }) + } + library::Std::Poll => { + let inner = args.type_at(0); + self.erases_to(inner) + .pending + .then(|| format!("`Poll<{inner}>` is not supported: it would be pending two ways with one value")) + } + library::Std::ControlFlow if library::Flow::of(self.tcx, args) == library::Flow::Option => { + let inner = args.type_at(1); + self.erases_to(inner) + .undefined + .then(|| format!("`{ty}` is not supported: its break and its continue would both be `undefined`")) + } + _ => None, + } + } + fn fn_ty(&mut self, inputs: &[Ty<'tcx>], output: Ty<'tcx>, span: Span) -> Type { let params = inputs.iter().map(|t| self.ty(*t, span)).collect(); let ret = match output.is_unit() { @@ -905,13 +978,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { return match std { library::Std::Option => { let inner = args.type_at(0); - if self.erases_to(inner).undefined { - self.err( - span, - format!( - "`Option<{inner}>` is not supported: its `None` and `Some` would both be `undefined`" - ), - ); + if let Some(msg) = self.erasure_conflict(Ty::new_adt(tcx, adt, args)) { + self.err(span, msg); } Type::Union(vec![self.ty(inner, span), Type::Builtin("undefined")]) } @@ -949,14 +1017,10 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { library::Std::Waker => Type::Rt("Waker", vec![]), library::Std::Context => Type::Rt("Context", vec![]), library::Std::Poll => { - let inner = args.type_at(0); - if self.erases_to(inner).pending { - self.err( - span, - format!("`Poll<{inner}>` is not supported: it would be pending two ways with one value"), - ); + if let Some(msg) = self.erasure_conflict(Ty::new_adt(tcx, adt, args)) { + self.err(span, msg); } - Type::Rt("Poll", vec![self.ty(inner, span)]) + Type::Rt("Poll", vec![self.ty(args.type_at(0), span)]) } library::Std::Pin => self.ty(args.type_at(0), span), library::Std::Range => Type::Rt("Range", vec![self.ty(args.type_at(0), span)]), @@ -991,20 +1055,22 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { } library::Std::Ordering => Type::Rt("Ordering", vec![]), library::Std::Hasher => Type::Rt("Hasher", vec![]), - // The value `?` was applied to, which MIR branches on as this. - library::Std::ControlFlow => match (self.std_of(args.type_at(0)), args.type_at(0).kind()) { - (Some(library::Std::Result), ty::Adt(_, residual)) => Type::Rt( - "Result", - vec![self.ty(args.type_at(1), span), self.ty(residual.type_at(1), span)], - ), - (Some(library::Std::Option), _) => { - Type::Union(vec![self.ty(args.type_at(1), span), Type::Builtin("undefined")]) + library::Std::ControlFlow => { + if let Some(msg) = self.erasure_conflict(Ty::new_adt(tcx, adt, args)) { + self.err(span, msg); } - _ => { - self.err(span, format!("`{}` other than from `?`", Ty::new_adt(tcx, adt, args))); - Type::Builtin("unknown") + let (residual, value) = (args.type_at(0), args.type_at(1)); + match library::Flow::of(tcx, args) { + library::Flow::Result => { + let ty::Adt(_, residual) = residual.kind() else { + unreachable!("a `Result` residual") + }; + Type::Rt("Result", vec![self.ty(value, span), self.ty(residual.type_at(1), span)]) + } + library::Flow::Option => Type::Union(vec![self.ty(value, span), Type::Builtin("undefined")]), + library::Flow::Other => Type::Rt("Result", vec![self.ty(value, span), self.ty(residual, span)]), } - }, + } }; } // Every other iterator std has is an `rt.Iter` of its items. @@ -1014,7 +1080,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { return Type::Rt("Iter", vec![self.ty(item, span)]); } if !adt.did().is_local() { - self.err( + self.unrepresented( span, format!("unsupported type `{}` from another crate", tcx.def_path_str(adt.did())), ); @@ -1055,6 +1121,12 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { pending: true, ..self.erases_to(args.type_at(0)) }, + Some(library::Std::ControlFlow) if library::Flow::of(self.tcx, args) == library::Flow::Option => { + Erased { + undefined: true, + ..self.erases_to(args.type_at(1)) + } + } _ => Erased::default(), }, _ => Erased::default(), From ce956cdbc7931a78104c21e9f03ec24fa09d23c0 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 07:56:35 -0700 Subject: [PATCH 3/5] fix(ts): drop and copy what a ControlFlow holds A `ControlFlow` drops what it holds and copies a mutable `Copy` payload, as an `Option` or `Result` does. Its drop glue, like any enum's, takes a `&mut` on this nightly, which is the value in JS: an enum that drops through rustc's glue translates, so the reject fixture's `slot` goes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- ts/fixtures/lang/expected/shapes.ts | 71 +++++++---- ts/fixtures/lang/src/shapes.rs | 12 ++ ts/fixtures/reject/census.md | 25 ++-- ts/fixtures/reject/expected.txt | 109 ++++++++-------- ts/fixtures/reject/src/lib.rs | 10 -- ts/fixtures/reject/ts.toml | 1 - ts/fixtures/task/expected/lib.ts | 18 +++ ts/fixtures/task/expected/model.ts | 184 +++++++++++++++++----------- ts/fixtures/task/src/model.rs | 15 ++- ts/src/lower/body.rs | 4 +- ts/src/lower/drop.rs | 1 + ts/src/lower/mir/mod.rs | 2 +- 12 files changed, 272 insertions(+), 180 deletions(-) create mode 100644 ts/fixtures/task/expected/lib.ts diff --git a/ts/fixtures/lang/expected/shapes.ts b/ts/fixtures/lang/expected/shapes.ts index f3e7177bd..64f5e341e 100644 --- a/ts/fixtures/lang/expected/shapes.ts +++ b/ts/fixtures/lang/expected/shapes.ts @@ -1565,15 +1565,21 @@ export function flows(data: Uint8Array, out: rt.ByteVec): void { let a!: rt.u8; let result!: rt.Result; let option!: rt.u8 | undefined; + let original!: rt.Result; + let copied!: rt.Result; + let _83!: rt.u8; + let iter2!: rt.Iter>; + let _93!: rt.Result | rt.Done; + let flow3!: rt.Result; let slot!: rt.Mutex; let iterS2!: Uint8Array; let iterI2!: number; - let _82!: rt.u8 | rt.Done; + let _106!: rt.u8 | rt.Done; let x2!: rt.u8; let held!: rt.Mutex; - let _89!: boolean; - let _90!: rt.u8 | undefined; - let _105!: rt.Mutex; + let _113!: boolean; + let _114!: rt.u8 | undefined; + let _129!: rt.Mutex; total = 0; iterS = data; iterI = 0; @@ -1604,30 +1610,47 @@ export function flows(data: Uint8Array, out: rt.ByteVec): void { } else { rt.byteVecPush(out, 253); } - slot = new rt.Mutex(undefined); - iterS2 = data; - iterI2 = 0; + original = rt.Ok(Uint8Array.of(a, 1)); + copied = rt.copy(original); + if (copied.ok) { + _83 = rt.u8WrappingAdd(copied.value[0], 1); + copied.value[0] = _83; + } + iter2 = rt.iterSlice([original, rt.copy(copied)]); while (true) { - _82 = iterI2 < iterS2.length ? iterS2[iterI2++] : rt.DONE; - if (_82 === rt.DONE) { - _105 = slot; - rt.byteVecPush(out, rt.optionUnwrapOr(_105.value, 252)); - return; - } else { - x2 = _82; - held = slot; - _90 = held.value; - b7: { - if (_90 !== undefined) { - if (_90 >= x2) { - _89 = true; - break b7; + _93 = iter2.next(); + if (_93 === rt.DONE) { + slot = new rt.Mutex(undefined); + iterS2 = data; + iterI2 = 0; + while (true) { + _106 = iterI2 < iterS2.length ? iterS2[iterI2++] : rt.DONE; + if (_106 === rt.DONE) { + _129 = slot; + rt.byteVecPush(out, rt.optionUnwrapOr(_129.value, 252)); + return; + } else { + x2 = _106; + held = slot; + _114 = held.value; + b9: { + if (_114 !== undefined) { + if (_114 >= x2) { + _113 = true; + break b9; + } + } + _113 = false; + } + if (!_113) { + held.value = x2; } } - _89 = false; } - if (!_89) { - held.value = x2; + } else { + flow3 = _93; + if (flow3.ok) { + rt.byteVecExtendFromSlice(out, flow3.value); } } } diff --git a/ts/fixtures/lang/src/shapes.rs b/ts/fixtures/lang/src/shapes.rs index 2a8723935..d3054c0b5 100644 --- a/ts/fixtures/lang/src/shapes.rs +++ b/ts/fixtures/lang/src/shapes.rs @@ -1095,6 +1095,18 @@ pub fn flows(data: &[u8], out: &mut Vec) { ControlFlow::Break(None) => out.push(0xfd), } + // A copy holds its own copy of what it holds. + let original: ControlFlow<(), [u8; 2]> = ControlFlow::Continue([a, 1]); + let mut copied = original; + if let ControlFlow::Continue(ref mut v) = copied { + v[0] = v[0].wrapping_add(1); + } + for flow in [original, copied] { + if let ControlFlow::Continue(v) = flow { + out.extend_from_slice(&v); + } + } + let slot = Mutex::new(None); for &x in data { let mut held = slot.lock().unwrap(); diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 57b536e21..4661e6615 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,6 +1,6 @@ # Census of `reject-fixture` -- Refusals: 73 +- Refusals: 72 - Function instances: 61 - Generic functions no instance reached, lowered over their type parameters: 3 @@ -10,9 +10,9 @@ | ---: | --- | --- | | 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:31:15 | | 6 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:20:2 | -| 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 | +| 4 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:19:13 | | 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:133:2 | | 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:159:20 | @@ -80,7 +80,6 @@ The type or module each refused type or path belongs to. | 1 | `IntToFloat` | fixtures/reject/src/lib.rs:144:2 | | 1 | `Loud` | fixtures/reject/src/lib.rs:354:6 | | 1 | `Noisy` | fixtures/reject/src/lib.rs:285:20 | -| 1 | `Slot` | fixtures/reject/src/lib.rs:73:1 | | 1 | `[u8; 1]` | fixtures/reject/src/lib.rs:309:22 | | 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:14:16 | | 1 | `std::collections::HashSet` | fixtures/reject/src/lib.rs:354:6 | @@ -114,7 +113,6 @@ The type or module each refused type or path belongs to. | 1 | `_` of `_`, which may drop a `_`, which is not supported yet | `HashSet::remove`, `std::collections::HashSet`, `Loud` | fixtures/reject/src/lib.rs:354:6 | | 1 | `_` of `_`, which may drop what it holds, which is not supported yet | `HashMap::clear`, `std::collections::HashMap` | fixtures/reject/src/lib.rs:331:6 | | 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:379:9 | -| 1 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut Slot`, `Slot` | fixtures/reject/src/lib.rs:73:1 | | 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:120:16 | | 1 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:90:10 | | 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:144:2 | @@ -175,16 +173,6 @@ The type or module each refused type or path belongs to.
-
`_`: 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:73:1: `&mut Slot`: a JS value of `Slot` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:90:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:120:16: `&mut std::string::String`: a JS value of `std::string::String` 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` @@ -205,6 +193,15 @@ The type or module each refused type or path belongs to.
+
`_`: a JS value of `_` is a copy, so a reference can't change it (4) + +- 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:90:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:120:16: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it + +
+
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 diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 8577d3a02..875bd6c42 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -1,6 +1,6 @@ -a root must not be generic at fixtures/reject/src/lib.rs:142:1 +a root must not be generic at fixtures/reject/src/lib.rs:132:1 no item `missing` in the crate -a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:140:1 +a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:130: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 @@ -19,56 +19,55 @@ unsupported call to `std::slice::::sort` at fixtures/reject/src/lib.r 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 -`&mut Slot`: a JS value of `Slot` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:73:1 -`Boxed` is generic and implements `Drop`, which is not supported yet at fixtures/reject/src/lib.rs:83:10 -`&mut u8`: a JS value of `u8` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:90:10 -an assignment through a reference to `u8` at fixtures/reject/src/lib.rs:91:3 -a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:99:10: 99:18}` at fixtures/reject/src/lib.rs:100:2 -a precision, as in `{:.2}`, is not supported at fixtures/reject/src/lib.rs:107:3 -the `+` flag of a format spec is not supported at fixtures/reject/src/lib.rs:108:3 -the `-` flag of a format spec is not supported at fixtures/reject/src/lib.rs:109:3 -`Binary` formatting, as in `{:b}`, is not supported at fixtures/reject/src/lib.rs:110:12 -`Octal` formatting, as in `{:o}`, is not supported at fixtures/reject/src/lib.rs:111:12 -`LowerExp` formatting, as in `{:e}`, is not supported at fixtures/reject/src/lib.rs:112:12 -hex `Debug`, as in `{:x?}`, is not supported at fixtures/reject/src/lib.rs:113:3 -a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:114:15 -a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:114:3 -`Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:115: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:120:16 -unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:122:10 -a constant of type `&u8` at fixtures/reject/src/lib.rs:128:2 -replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:133:2 -replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:137:2 -dropping `std::sync::Arc<&Noisy>`, which is not supported yet at fixtures/reject/src/lib.rs:151:1 -an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:155:2 -`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:159:20 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:164:19 -`Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:169:54 -an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:175:2 -an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:180:2 -unsupported call to ` as std::iter::Iterator>::cycle` at fixtures/reject/src/lib.rs:185:11 -constructing `std::iter::Map` from another crate at fixtures/reject/src/lib.rs:204:23 -constructing `std::iter::Rev` from another crate at fixtures/reject/src/lib.rs:225:14 -a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:231:15: 231:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` at fixtures/reject/src/lib.rs:231:51 -unsupported call to `std::ops::Range::::contains::` at fixtures/reject/src/lib.rs:239:8 -an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:280:4 -an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:285:20 -passing `std::option::Option`, which drops, to `Option::unwrap_or`, which is not supported yet at fixtures/reject/src/lib.rs:290:4 -a mutable borrow of a subslice of `u32`, which JS would copy, having no views at fixtures/reject/src/lib.rs:295:13 -an assignment through a reference to `std::pin::Pin<&mut Noisy>` at fixtures/reject/src/lib.rs:303:2 -replacing the value behind a reference to `[u8; 1]` at fixtures/reject/src/lib.rs:309:22 -a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:320:14 -a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:326:7 -a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:326:48 -`HashMap::clear` of `std::collections::HashMap`, which may drop what it holds, which is not supported yet at fixtures/reject/src/lib.rs:331:6 -`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:336:2 -`std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:336:6 -hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:341:52 -comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:341:52 -`HashSet::remove` of `std::collections::HashSet`, which may drop a `Loud`, which is not supported yet at fixtures/reject/src/lib.rs:354:6 -`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:371:6 -overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:198:2 -an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:218:1 -overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:252:2 -an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:272:1 -`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:379:9 +`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 +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 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 34246a631..d0d8b80f5 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -62,16 +62,6 @@ pub fn each(v: Vec) -> u8 { sum } -pub enum Slot { - Empty, - Full(Noisy), -} - -/// An enum's drop glue would switch on its variant. -pub fn slot(s: Slot) -> bool { - matches!(s, Slot::Empty) -} - pub struct Boxed(pub T); impl Drop for Boxed { diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index 7c898faff..6a5f4cd73 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -11,7 +11,6 @@ roots = [ "Noisy", "owning_closure", "each", - "slot", "boxed", "async_borrow", "async_closure", diff --git a/ts/fixtures/task/expected/lib.ts b/ts/fixtures/task/expected/lib.ts new file mode 100644 index 000000000..4c452cc8a --- /dev/null +++ b/ts/fixtures/task/expected/lib.ts @@ -0,0 +1,18 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import type * as Guard from "./model.Guard.ts"; + +export function drop$ControlFlow_Guard_u32(_1: rt.Result): void { + if (!_1.ok) { + rt.drop(_1.error); + } +} + +export function drop$Result_u32_Guard(_1: rt.Result): void { + if (!_1.ok) { + rt.drop(_1.error); + } +} + +//# sourceMappingURL=lib.ts.map diff --git a/ts/fixtures/task/expected/model.ts b/ts/fixtures/task/expected/model.ts index 9b038e4b8..349e8c152 100644 --- a/ts/fixtures/task/expected/model.ts +++ b/ts/fixtures/task/expected/model.ts @@ -1,6 +1,7 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; +import { drop$ControlFlow_Guard_u32, drop$Result_u32_Guard } from "./lib.ts"; import * as Consumer from "./kio.Consumer.ts"; import * as Log from "./log.Log.ts"; import * as Countdown from "./model.Countdown.ts"; @@ -1298,7 +1299,8 @@ export function pick(log: Log.Log, i: rt.usize): rt.usize { * temporary to the end of the block; a `_` binding of an element, which evaluates its * index and moves nothing; a boxed guard read twice, which a read leaves boxed; a guard * a method takes by value, which drops inside it, once from a box; and a boxed array of - * guards that may be absent, which drops them in order. + * guards that may be absent, which drops them in order, and a `Result` and a + * `ControlFlow` that may hold a guard, which rustc's glue drops. */ export function turns(log: Log.Log, count: rt.u32): void { let pair!: Guard.Guard[]; @@ -1320,30 +1322,34 @@ export function turns(log: Log.Log, count: rt.u32): void { let _112!: Guard.Guard; let _116!: Guard.Guard; let args10!: rt.Fmt[]; + let failed!: rt.Result; + let args12!: rt.Fmt[]; + let flow!: rt.Result; + let args14!: rt.Fmt[]; let spares!: Guard.Guard[]; - let _133!: Guard.Guard; - let _137!: Guard.Guard; - let _141!: rt.usize; + let _171!: Guard.Guard; + let _175!: Guard.Guard; + let _179!: rt.usize; let left!: rt.u32; let turn!: Guard.Guard; - let _161!: rt.u32; + let _199!: rt.u32; let unwind: number = 0; try { _4 = Guard.new(rt.u32Add(count, 10), Log.clone$Clone(log)); - unwind = 124; + unwind = 154; _8 = Guard.new(rt.u32Add(count, 20), Log.clone$Clone(log)); - unwind = 123; + unwind = 153; pair = [_4, _8]; kept = pair[0]; Guard.note(kept, "kept"); pinned = Guard.new(rt.u32Add(count, 40), Log.clone$Clone(log)); - unwind = 122; + unwind = 152; Guard.note(pinned, "pinned"); held = Guard.new(rt.u32Add(count, 50), Log.clone$Clone(log)); - unwind = 121; + unwind = 151; Guard.note(held, "borrowed"); _34 = Guard.new(rt.u32Add(count, 60), Log.clone$Clone(log)); - unwind = 120; + unwind = 150; Guard.note(_34, "extended"); _42 = Guard.new(rt.u32Add(count, 90), Log.clone$Clone(log)); scoped = _42.id; @@ -1352,7 +1358,7 @@ export function turns(log: Log.Log, count: rt.u32): void { args2 = [(f: rt.Formatter) => rt.u32Display(arg, f)]; Log.note(log, rt.fmtFormat(["after ", args2[0]])); boxed = Guard.new(rt.u32Add(count, 100), Log.clone$Clone(log)); - unwind = 119; + unwind = 149; const arg2 = boxed.id; _70 = (f: rt.Formatter) => rt.u32Display(arg2, f); const arg3 = boxed.id; @@ -1366,27 +1372,45 @@ export function turns(log: Log.Log, count: rt.u32): void { Log.note(log, rt.fmtFormat(["unboxed ", args8[0]])); if (rt.u32Rem(count, 2) === 0) { _112 = Guard.new(rt.u32Add(count, 130), Log.clone$Clone(log)); - unwind = 118; + unwind = 148; _116 = Guard.new(rt.u32Add(count, 140), Log.clone$Clone(log)); - unwind = 119; + unwind = 149; stacked = [_112, _116]; } else { stacked = undefined; } - unwind = 117; + unwind = 147; const arg6 = ([stacked !== undefined] as [boolean])[0]; args10 = [(f: rt.Formatter) => rt.fmtBool(arg6, f)]; Log.note(log, rt.fmtFormat(["stacked ", args10[0]])); - _133 = Guard.new(rt.u32Add(count, 70), Log.clone$Clone(log)); - unwind = 116; - _137 = Guard.new(rt.u32Add(count, 80), Log.clone$Clone(log)); - unwind = 115; - spares = [_133, _137]; - _141 = pick(log, rt.usizeRem(count as rt.usize, 2)); - if (!(_141 < 2)) { - rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _141); + if (rt.u32Rem(count, 2) === 0) { + failed = rt.Err(Guard.new(rt.u32Add(count, 150), Log.clone$Clone(log))); + } else { + failed = rt.Ok(count); } - b1: { + unwind = 146; + const arg7 = ([!failed.ok] as [boolean])[0]; + args12 = [(f: rt.Formatter) => rt.fmtBool(arg7, f)]; + Log.note(log, rt.fmtFormat(["failed ", args12[0]])); + if (rt.u32Rem(count, 3) === 0) { + flow = rt.Err(Guard.new(rt.u32Add(count, 160), Log.clone$Clone(log))); + } else { + flow = rt.Ok(count); + } + unwind = 145; + const arg8 = ([!flow.ok] as [boolean])[0]; + args14 = [(f: rt.Formatter) => rt.fmtBool(arg8, f)]; + Log.note(log, rt.fmtFormat(["flow ", args14[0]])); + _171 = Guard.new(rt.u32Add(count, 70), Log.clone$Clone(log)); + unwind = 144; + _175 = Guard.new(rt.u32Add(count, 80), Log.clone$Clone(log)); + unwind = 143; + spares = [_171, _175]; + _179 = pick(log, rt.usizeRem(count as rt.usize, 2)); + if (!(_179 < 2)) { + rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _179); + } + b3: { if (count === 0) { Log.note(log, rt.fmtFormat(["no turns"])); } else if (!(count < 4)) { @@ -1396,76 +1420,90 @@ export function turns(log: Log.Log, count: rt.u32): void { while (true) { turn = Guard.new(left, Log.clone$Clone(log)); if (!(left === 1)) { - unwind = 114; + unwind = 142; Guard.note(turn, "turn"); - _161 = rt.u32Sub(left, 1); - unwind = 115; - left = _161; + _199 = rt.u32Sub(left, 1); + unwind = 143; + left = _199; rt.drop(turn); } else { rt.drop(turn); - break b1; + break b3; } } } } - unwind = 117; + unwind = 145; rt.dropAll(spares); - unwind = 119; + unwind = 146; + drop$ControlFlow_Guard_u32(flow); + unwind = 147; + drop$Result_u32_Guard(failed); + unwind = 149; rt.dropAll(stacked); - unwind = 120; + unwind = 150; rt.drop(boxed); - unwind = 121; + unwind = 151; rt.drop(_34); - unwind = 122; + unwind = 152; rt.drop(held); - unwind = 123; + unwind = 153; rt.drop(pinned); - unwind = 126; + unwind = 156; rt.drop(kept); unwind = 0; rt.dropAll(pair.slice(1, 2)); } catch (e) { - b3: { - b4: { - b5: { - b6: { - b7: { - b8: { - b9: { - b10: { - if (unwind === 0) { - throw e; - } - if (unwind === 114) { - rt.drop(turn); - } else if (unwind !== 115) { - if (unwind === 116) { - rt.drop(_133); - break b10; - } else if (unwind === 117) { - break b10; - } else if (unwind === 118) { - rt.drop(_112); - break b9; - } else if (unwind === 119) { - break b9; - } else if (unwind === 120) { - break b8; - } else if (unwind === 121) { - break b7; - } else if (unwind === 122) { - break b6; - } else if (unwind === 123) { - break b5; - } else if (unwind === 124) { - rt.drop(_4); - break b3; - } else { - break b4; + b5: { + b6: { + b7: { + b8: { + b9: { + b10: { + b11: { + b12: { + b13: { + b14: { + if (unwind === 0) { + throw e; + } + if (unwind === 142) { + rt.drop(turn); + } else if (unwind !== 143) { + if (unwind === 144) { + rt.drop(_171); + break b14; + } else if (unwind === 145) { + break b14; + } else if (unwind === 146) { + break b13; + } else if (unwind === 147) { + break b12; + } else if (unwind === 148) { + rt.drop(_112); + break b11; + } else if (unwind === 149) { + break b11; + } else if (unwind === 150) { + break b10; + } else if (unwind === 151) { + break b9; + } else if (unwind === 152) { + break b8; + } else if (unwind === 153) { + break b7; + } else if (unwind === 154) { + rt.drop(_4); + break b5; + } else { + break b6; + } + } + rt.dropAll(spares); } + drop$ControlFlow_Guard_u32(flow); } - rt.dropAll(spares); + drop$Result_u32_Guard(failed); } rt.dropAll(stacked); } diff --git a/ts/fixtures/task/src/model.rs b/ts/fixtures/task/src/model.rs index d2e05aa1b..f6f565984 100644 --- a/ts/fixtures/task/src/model.rs +++ b/ts/fixtures/task/src/model.rs @@ -1,6 +1,8 @@ //! What the harness spawns and drives: a consumer loop holding guards across its awaits, //! the same loop under a stack of async functions, and the channels they read. +use std::ops::ControlFlow; + use crate::kio::{Consumer, Producer}; use crate::log::Log; @@ -277,7 +279,8 @@ fn pick(log: &Log, i: usize) -> usize { /// temporary to the end of the block; a `_` binding of an element, which evaluates its /// index and moves nothing; a boxed guard read twice, which a read leaves boxed; a guard /// a method takes by value, which drops inside it, once from a box; and a boxed array of -/// guards that may be absent, which drops them in order. +/// guards that may be absent, which drops them in order, and a `Result` and a +/// `ControlFlow` that may hold a guard, which rustc's glue drops. #[expect(clippy::toplevel_ref_arg, reason = "the `ref` bindings are under test")] fn turns(log: &Log, count: u32) { let pair = [Guard::new(count + 10, log.clone()), Guard::new(count + 20, log.clone())]; @@ -310,6 +313,16 @@ fn turns(log: &Log, count: u32) { _ => None, }; log.note(format!("stacked {}", stacked.is_some())); + let failed = match count % 2 { + 0 => Err::(Guard::new(count + 150, log.clone())), + _ => Ok(count), + }; + log.note(format!("failed {}", failed.is_err())); + let flow = match count % 3 { + 0 => ControlFlow::Break(Guard::new(count + 160, log.clone())), + _ => ControlFlow::Continue(count), + }; + log.note(format!("flow {}", flow.is_break())); let spares = [Guard::new(count + 70, log.clone()), Guard::new(count + 80, log.clone())]; let _ = spares[pick(log, count as usize % 2)]; match count { diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index 46f5e8799..261423216 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -87,7 +87,9 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { ty::Array(..) => true, ty::Adt(adt, args) => match library::Std::of(self.t.tcx, adt.did()) { // The runtime's methods hand out the payload itself. - Some(library::Std::Option | library::Std::Result) => args.types().any(|t| self.mutable_aggregate(t)), + Some(library::Std::Option | library::Std::Result | library::Std::ControlFlow) => { + args.types().any(|t| self.mutable_aggregate(t)) + } Some(_) => false, None => adt.is_struct() && !adt.non_enum_variant().fields.is_empty(), }, diff --git a/ts/src/lower/drop.rs b/ts/src/lower/drop.rs index 864a4c19d..abd4e064e 100644 --- a/ts/src/lower/drop.rs +++ b/ts/src/lower/drop.rs @@ -33,6 +33,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { Some( Std::Option | Std::Result + | Std::ControlFlow | Std::Box | Std::Vec | Std::Mutex diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 4f355a119..569a640e3 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -1008,7 +1008,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { }; for local in self.mir.args_iter().skip(skip) { let ty = match (&self.env, self.mir.local_decls[local].ty.kind()) { - (Env::Shim, ty::RawPtr(pointee, _)) => *pointee, + (Env::Shim, ty::RawPtr(pointee, _) | ty::Ref(_, pointee, _)) => *pointee, (_, _) => self.mir.local_decls[local].ty, }; let name = match &self.slots[local] { From 69a0c923cb0de79f53c547857909412ed6abd33d Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 08:07:27 -0700 Subject: [PATCH 4/5] test(ts): update the reject census without slot Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- ts/fixtures/reject/census.md | 306 +++++++++++++++++------------------ 1 file changed, 153 insertions(+), 153 deletions(-) diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 4661e6615..48e92912f 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,7 +1,7 @@ # Census of `reject-fixture` - Refusals: 72 -- Function instances: 61 +- Function instances: 60 - Generic functions no instance reached, lowered over their type parameters: 3 ## By construct @@ -14,42 +14,42 @@ | 5 | unsupported type `_` | fixtures/reject/src/lib.rs:6:14 | | 4 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:19:13 | | 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:133:2 | -| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:159:20 | -| 2 | a field of `_` | fixtures/reject/src/lib.rs:326:7 | -| 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:218:1 | -| 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:204:23 | -| 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:198:2 | -| 1 | `Binary` formatting, as in `{:b}`, is not supported | fixtures/reject/src/lib.rs:110:3 | -| 1 | `LowerExp` formatting, as in `{:e}`, is not supported | fixtures/reject/src/lib.rs:112:3 | -| 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:111:3 | -| 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:115:3 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:336:6 | -| 1 | `_` is generic and implements `Drop`, which is not supported yet | fixtures/reject/src/lib.rs:75:1 | -| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:371:6 | -| 1 | `_` of `_`, which may drop a `_`, which is not supported yet | fixtures/reject/src/lib.rs:354:6 | -| 1 | `_` of `_`, which may drop what it holds, which is not supported yet | fixtures/reject/src/lib.rs:331:6 | -| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:379:9 | -| 1 | a `_` cast from `_` to `_` | fixtures/reject/src/lib.rs:144:2 | -| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:231:51 | +| 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 | +| 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 | `_`, 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:128:2 | -| 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:320:14 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:295:13 | -| 1 | a precision, as in `{:.2}`, is not supported | fixtures/reject/src/lib.rs:107:3 | -| 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:140:1 | +| 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 | | 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:114:3 | -| 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:100: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 | arithmetic on `_` | fixtures/reject/src/lib.rs:7:2 | -| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:341:52 | -| 1 | dropping `_`, which is not supported yet | fixtures/reject/src/lib.rs:151:1 | +| 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:341:52 | -| 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:113:3 | -| 1 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:290:4 | -| 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:108:3 | -| 1 | the `-` flag of a format spec is not supported | fixtures/reject/src/lib.rs:109:3 | +| 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 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:280:4 | +| 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 | ## By API @@ -61,40 +61,40 @@ The type or module each refused type or path belongs to. | 6 | `f64` | fixtures/reject/src/lib.rs:6:14 | | 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:59:2 | | 4 | `u32` | fixtures/reject/src/lib.rs:19:13 | -| 4 | `u8` | fixtures/reject/src/lib.rs:90:10 | -| 3 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:331:6 | -| 2 | `HashMap` | fixtures/reject/src/lib.rs:331:6 | -| 2 | `Iterator` | fixtures/reject/src/lib.rs:198:2 | -| 2 | `Meters` | fixtures/reject/src/lib.rs:133:2 | -| 2 | `Poll` | fixtures/reject/src/lib.rs:159:20 | +| 4 | `u8` | fixtures/reject/src/lib.rs:80:10 | +| 3 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:321:6 | +| 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::option::Option` | fixtures/reject/src/lib.rs:290:4 | -| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:175:2 | -| 2 | `std::string::String` | fixtures/reject/src/lib.rs:120:16 | -| 2 | `std::sync::Arc` | fixtures/reject/src/lib.rs:151:1 | -| 1 | `Boxed` | fixtures/reject/src/lib.rs:75:1 | -| 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:218:1 | -| 1 | `FusedIterator` | fixtures/reject/src/lib.rs:272:1 | -| 1 | `HashSet` | fixtures/reject/src/lib.rs:354:6 | -| 1 | `Hasher` | fixtures/reject/src/lib.rs:379:9 | -| 1 | `IntToFloat` | fixtures/reject/src/lib.rs:144:2 | -| 1 | `Loud` | fixtures/reject/src/lib.rs:354:6 | -| 1 | `Noisy` | fixtures/reject/src/lib.rs:285:20 | -| 1 | `[u8; 1]` | fixtures/reject/src/lib.rs:309:22 | +| 2 | `std::option::Option` | fixtures/reject/src/lib.rs:280:4 | +| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:165:2 | +| 2 | `std::string::String` | fixtures/reject/src/lib.rs:110:16 | +| 2 | `std::sync::Arc` | fixtures/reject/src/lib.rs:141:1 | +| 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 | `[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:354:6 | -| 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:231:51 | -| 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:204:23 | -| 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:225:14 | +| 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:326:48 | -| 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:326:7 | -| 1 | `std::ops::Range` | fixtures/reject/src/lib.rs:239:8 | -| 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:185:11 | +| 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:180:2 | -| 1 | `u64` | fixtures/reject/src/lib.rs:144:2 | -| 1 | `{async closure}` | fixtures/reject/src/lib.rs:100:2 | +| 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 | ## By type or path @@ -102,49 +102,49 @@ The type or module each refused type or path belongs to. | ---: | --- | --- | --- | | 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:31: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:159:20 | +| 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 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:175:2 | +| 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:165:2 | | 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:133:2 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:336:6 | -| 1 | `_` is generic and implements `Drop`, which is not supported yet | `Boxed` | fixtures/reject/src/lib.rs:75:1 | -| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:371:6 | -| 1 | `_` of `_`, which may drop a `_`, which is not supported yet | `HashSet::remove`, `std::collections::HashSet`, `Loud` | fixtures/reject/src/lib.rs:354:6 | -| 1 | `_` of `_`, which may drop what it holds, which is not supported yet | `HashMap::clear`, `std::collections::HashMap` | fixtures/reject/src/lib.rs:331:6 | -| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:379: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:120:16 | -| 1 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:90:10 | -| 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:144: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:231:51 | +| 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 | `_`, 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 JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:80:10 | +| 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:128:2 | -| 1 | a field of `_` | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:326:48 | -| 1 | a field of `_` | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:326:7 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:295:13 | +| 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 | | 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:100:2 | -| 1 | an assignment through a reference to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:155:2 | -| 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:180: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 assignment through a reference to `_` | `u8` | fixtures/reject/src/lib.rs:91:3 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:218:1 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:272:1 | -| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:285:20 | +| 1 | an assignment through a reference to `_` | `u8` | fixtures/reject/src/lib.rs:81:3 | +| 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 | 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:341:52 | -| 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:204:23 | -| 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:225:14 | -| 1 | dropping `_`, which is not supported yet | `std::sync::Arc` | fixtures/reject/src/lib.rs:151:1 | -| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:341:52 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:198:2 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:252:2 | -| 1 | passing `_`, which drops, to `_`, which is not supported yet | `std::option::Option`, `Option::unwrap_or` | fixtures/reject/src/lib.rs:290:4 | -| 1 | replacing the value behind a reference to `_` | `[u8; 1]` | fixtures/reject/src/lib.rs:309:22 | -| 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:185:11 | -| 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:122:10 | +| 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 | 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:239:8 | +| 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 | @@ -157,19 +157,19 @@ The type or module each refused type or path belongs to. - 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:164:19: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:336:2: `Option<&std::option::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`
an assignment through a reference to `_` (6) - fixtures/reject/src/lib.rs:20:2: an assignment through a reference to `u32` -- fixtures/reject/src/lib.rs:91:3: an assignment through a reference to `u8` -- fixtures/reject/src/lib.rs:155:2: an assignment through a reference to `std::sync::Arc` -- fixtures/reject/src/lib.rs:175:2: an assignment through a reference to `std::pin::Pin>` -- fixtures/reject/src/lib.rs:180:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` -- fixtures/reject/src/lib.rs:303:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>` +- 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>`
@@ -177,9 +177,9 @@ The type or module each refused type or path belongs to. - 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:122:10: unsupported call to `::write_fmt` -- fixtures/reject/src/lib.rs:185:11: unsupported call to ` as std::iter::Iterator>::cycle` -- fixtures/reject/src/lib.rs:239:8: unsupported call to `std::ops::Range::::contains::` +- 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::` @@ -189,7 +189,7 @@ The type or module each refused type or path belongs to. - 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:142:51: unsupported type `f64` +- fixtures/reject/src/lib.rs:132:51: unsupported type `f64` @@ -197,131 +197,131 @@ The type or module each refused type or path belongs to. - 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:90:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:120: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: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
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:280:4: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:285:20: an iterator that owns `Noisy`, 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
replacing the value behind a reference to `_` (3) -- fixtures/reject/src/lib.rs:133:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:137:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:309:22: replacing the value behind a reference to `[u8; 1]` +- 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]`
`_` is not supported: it would be pending two ways with one value (2) -- fixtures/reject/src/lib.rs:159:20: `Poll>>` is not supported: it would be pending two ways with one value -- fixtures/reject/src/lib.rs:169:54: `Poll>` is not supported: it would be pending two ways with one value +- 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
a field of `_` (2) -- fixtures/reject/src/lib.rs:326:7: a field of `std::ops::RangeTo` -- fixtures/reject/src/lib.rs:326:48: a field of `std::ops::RangeFrom` +- 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`
an iterator of the crate implementing `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:218:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet -- fixtures/reject/src/lib.rs:272:1: an iterator of the crate implementing `FusedIterator`, which is not supported yet +- 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
constructing `_` from another crate (2) -- fixtures/reject/src/lib.rs:204:23: constructing `std::iter::Map` from another crate -- fixtures/reject/src/lib.rs:225:14: constructing `std::iter::Rev` from another crate +- 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
overriding `_`, which std's adaptors call in place of `next` or beside it (2) -- fixtures/reject/src/lib.rs:198:2: overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it -- fixtures/reject/src/lib.rs:252:2: overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it +- 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
`Binary` formatting, as in `{:b}`, is not supported (1) -- fixtures/reject/src/lib.rs:110:3: `Binary` formatting, as in `{:b}`, is not supported +- fixtures/reject/src/lib.rs:100:3: `Binary` formatting, as in `{:b}`, is not supported
`LowerExp` formatting, as in `{:e}`, is not supported (1) -- fixtures/reject/src/lib.rs:112:3: `LowerExp` formatting, as in `{:e}`, is not supported +- fixtures/reject/src/lib.rs:102:3: `LowerExp` formatting, as in `{:e}`, is not supported
`Octal` formatting, as in `{:o}`, is not supported (1) -- fixtures/reject/src/lib.rs:111:3: `Octal` formatting, as in `{:o}`, is not supported +- fixtures/reject/src/lib.rs:101:3: `Octal` formatting, as in `{:o}`, is not supported
`Pointer` formatting, as in `{:p}`, is not supported (1) -- fixtures/reject/src/lib.rs:115:3: `Pointer` formatting, as in `{:p}`, is not supported +- fixtures/reject/src/lib.rs:105: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:336:6: `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported +- fixtures/reject/src/lib.rs:326: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:75:1: `Boxed` is generic and implements `Drop`, which is not supported yet +- fixtures/reject/src/lib.rs:65: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:371:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet +- fixtures/reject/src/lib.rs:361: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:354:6: `HashSet::remove` of `std::collections::HashSet`, which may drop a `Loud`, which is not supported yet +- fixtures/reject/src/lib.rs:344: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:331:6: `HashMap::clear` of `std::collections::HashMap`, which may drop what it holds, which is not supported yet +- fixtures/reject/src/lib.rs:321:6: `HashMap::clear` of `std::collections::HashMap`, which may drop what it holds, which is not supported yet
`_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:379:9: `Hasher::write`, which is not supported yet +- fixtures/reject/src/lib.rs:369:9: `Hasher::write`, which is not supported yet
a `_` cast from `_` to `_` (1) -- fixtures/reject/src/lib.rs:144:2: a `IntToFloat` cast from `u64` to `f64` +- fixtures/reject/src/lib.rs:134: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:231:51: a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:231:15: 231:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` +- 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`
@@ -333,31 +333,31 @@ The type or module each refused type or path belongs to.
a constant of type `_` (1) -- fixtures/reject/src/lib.rs:128:2: a constant of type `&u8` +- fixtures/reject/src/lib.rs:118:2: a constant of type `&u8`
a copy of a closure that changes what it captured (1) -- fixtures/reject/src/lib.rs:320:14: a copy of a closure that changes what it captured +- fixtures/reject/src/lib.rs:310: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:295:13: a mutable borrow of a subslice of `u32`, which JS would copy, having no views +- fixtures/reject/src/lib.rs:285: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:107:3: a precision, as in `{:.2}`, is not supported +- fixtures/reject/src/lib.rs:97:3: a precision, as in `{:.2}`, is not supported
a printable type must implement `Display` or `Debug` (1) -- fixtures/reject/src/lib.rs:140:1: a printable type must implement `Display` or `Debug` +- fixtures/reject/src/lib.rs:130:1: a printable type must implement `Display` or `Debug`
@@ -369,13 +369,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:114:3: a width or precision from an argument, as in `{:1$}`, is not supported +- fixtures/reject/src/lib.rs:104: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:100:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:99:10: 99:18}` +- fixtures/reject/src/lib.rs:90:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:89:10: 89:18}`
@@ -387,13 +387,13 @@ 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:341:52: comparing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:331: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:151:1: dropping `std::sync::Arc<&Noisy>`, which is not supported yet +- fixtures/reject/src/lib.rs:141:1: dropping `std::sync::Arc<&Noisy>`, which is not supported yet
@@ -405,30 +405,30 @@ The type or module each refused type or path belongs to.
hashing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:341:52: hashing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:331: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:113:3: hex `Debug`, as in `{:x?}`, is not supported +- fixtures/reject/src/lib.rs:103:3: hex `Debug`, as in `{:x?}`, is not supported
passing `_`, which drops, to `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:290:4: passing `std::option::Option`, which drops, to `Option::unwrap_or`, which is not supported yet +- fixtures/reject/src/lib.rs:280:4: passing `std::option::Option`, which drops, to `Option::unwrap_or`, which is not supported yet
the `+` flag of a format spec is not supported (1) -- fixtures/reject/src/lib.rs:108:3: the `+` flag of a format spec is not supported +- fixtures/reject/src/lib.rs:98: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:109:3: the `-` flag of a format spec is not supported +- fixtures/reject/src/lib.rs:99:3: the `-` flag of a format spec is not supported
From a1a2a4346d9e1efe6edf22b22187ce07aae5a8a6 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 08:22:38 -0700 Subject: [PATCH 5/5] fix(ts): leave a left-out macro's temporaries unchecked The erasure check of each local ran before the left-out macros were found, so a logging call's ambiguous temporary refused its function. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- ts/fixtures/codec/expected/lite/message.ts | 8 ++++++-- ts/fixtures/codec/src/lite/message.rs | 2 ++ ts/src/lower/mir/mod.rs | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ts/fixtures/codec/expected/lite/message.ts b/ts/fixtures/codec/expected/lite/message.ts index 3dd51d249..88013767f 100644 --- a/ts/fixtures/codec/expected/lite/message.ts +++ b/ts/fixtures/codec/expected/lite/message.ts @@ -33,12 +33,14 @@ export function decodeSize(r: Decoder.Decoder, max: rt.usize): rt.Result rt.Result): rt.Result { let _3!: rt.Result; + let size!: rt.usize; let body!: Decoder.Decoder; let _9!: rt.Result; let result!: rt.Result; _3 = decodeSize(r, 65535); if (_3.ok) { - _9 = Decoder.sub(r, _3.value); + size = _3.value; + _9 = Decoder.sub(r, size); if (_9.ok) { body = _9.value; result = rt.resultAndThen(rt.resultMapErr(decode(body), DecodeError.complete), (msg: Group.Group): rt.Result => { @@ -66,12 +68,14 @@ export function decodeWith$Group_decode_closure0(r: Decoder.Decoder, decode: (a0 */ export function decodeWith$Probe_decode_closure0(r: Decoder.Decoder, decode: (a0: Decoder.Decoder) => rt.Result): rt.Result { let _3!: rt.Result; + let size!: rt.usize; let body!: Decoder.Decoder; let _9!: rt.Result; let result!: rt.Result; _3 = decodeSize(r, 65535); if (_3.ok) { - _9 = Decoder.sub(r, _3.value); + size = _3.value; + _9 = Decoder.sub(r, size); if (_9.ok) { body = _9.value; result = rt.resultAndThen(rt.resultMapErr(decode(body), DecodeError.complete), (msg: Probe.Probe): rt.Result => { diff --git a/ts/fixtures/codec/src/lite/message.rs b/ts/fixtures/codec/src/lite/message.rs index afb637565..65d0a149f 100644 --- a/ts/fixtures/codec/src/lite/message.rs +++ b/ts/fixtures/codec/src/lite/message.rs @@ -65,6 +65,8 @@ pub(super) fn decode_with( ) -> Result { let size = decode_size(r, T::MAX_SIZE)?; let mut body = r.sub(size)?; + // Left out with its arguments, whose `Option<()>` has no JS value. + tracing::trace!(empty = (size == 0).then_some(()).is_some(), "body"); // The body is complete, so running short inside it is malformed, not a wait for more. let result = decode(&mut body) diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 569a640e3..d051277a2 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -278,6 +278,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { /// Count each local's reads and assignments, and decide how each lowers. fn analyze(&mut self) { let mir = self.mir; + self.find_ignored_sites(); self.find_noops(); let mut bounds = Vec::new(); for (bb, data) in mir.basic_blocks.iter_enumerated() { @@ -399,8 +400,8 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { self.slots[local] = slot; // A temporary folded into what reads it is declared nowhere, so a type that can't // tell its values apart is refused here. The signature types the parameters and - // the result. - if !self.is_arg(local) && local != mir::RETURN_PLACE { + // the result, and a left-out macro's code holds nothing. + if !self.is_arg(local) && local != mir::RETURN_PLACE && !self.in_ignored(self.local_span(local)) { let held = match self.next_results.contains(&local) { true => next_item(self.tcx, ty), false => ty, @@ -1130,13 +1131,10 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { out } - /// Send each block whose terminator an ignored macro made to the one block its code - /// leaves to. Such a macro evaluates to `()`, so its code has one way out. - fn skip_ignored_macros(&mut self) { - let mir = self.mir; - // Every left-out invocation's span, which its arguments' code is within too. + /// Every left-out macro invocation's span, which its arguments' code is within too. + fn find_ignored_sites(&mut self) { let mut sites = Vec::new(); - for data in mir.basic_blocks.iter() { + for data in self.mir.basic_blocks.iter() { let spans = data.statements.iter().map(|s| s.source_info.span); for span in spans.chain([data.terminator().source_info.span]) { if let Some(site) = self.b.t.ignored_site(span) @@ -1147,6 +1145,12 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } } self.ignored_sites = sites; + } + + /// Send each block whose terminator an ignored macro made to the one block its code + /// leaves to. Such a macro evaluates to `()`, so its code has one way out. + fn skip_ignored_macros(&mut self) { + let mir = self.mir; let flags: IndexVec = mir .basic_blocks .iter()