Skip to content

Conversation

@TKanX
Copy link
Contributor

@TKanX TKanX commented Dec 13, 2025

Fixes #1

Problem

Rust 1.94-nightly introduced a breaking change (rust-lang/rust#141402) that forbids raw pointer casts which extend trait object lifetimes:

error: lifetime may not live long enough
   --> src/lib.rs:609:42
    |
556 | fn for_each_raw_imp(n_jobs: usize, task: &(dyn Sync + Fn(usize))) {
    |                                          - let's call the lifetime of this reference `'1`
...
609 |                     let mut task = (&raw const task) as *const TaskInner;
    |                                                         ^^^^^^^^^^^^^^^^ type annotation requires that `'1` must outlive `'static`

Solution

Replace the direct pointer cast with std::mem::transmute:

let task_ref: &(dyn Sync + Fn(usize, &AtomicPtr<PanicLoad>)) = &task;
let mut task: *const TaskInner = std::mem::transmute(task_ref as *const _);

Safety

The transmute is sound because the barrier mechanism (wait_and_clear) guarantees all worker threads complete before the closure is dropped. The task lives on the stack until synchronization completes.

Performance

Zero-cost. transmute is a compile-time type reinterpretation—no runtime instructions generated. Verified via benchmark and assembly inspection.

Testing

  • All existing tests pass on both stable and nightly
  • Benchmarks show no performance regression

Rust 1.94-nightly (rust-lang/rust#141402) forbids raw pointer casts
that extend trait object lifetimes. This broke the TaskInner pointer
construction in for_each_raw_imp.

Replace the direct cast with explicit transmute. The barrier mechanism
guarantees task lifetime validity - all workers synchronize via
wait_and_clear before the closure drops.

Zero-cost: transmute is a compile-time type reinterpretation only.

Fixes #1
SauersML pushed a commit to SauersML/gnomon that referenced this pull request Dec 14, 2025
… fix

The Rust compiler now correctly rejects raw pointer casts that extend
trait object lifetimes (rust-lang/rust#141402). This breaks spindle 0.2.5.

Patching to use the fix from sarah-quinones/spindle#2 until a new
version is published to crates.io.
@BoxyUwU
Copy link

BoxyUwU commented Dec 15, 2025

Sorry for having missed this in the crater run and not having opened a fix PR myself. If you have any questions about why this change was made on the language side please let me know and I'll do my best to explain the justification.

@sarah-quinones
Copy link
Owner

no worries! i appreciate the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compiler error in nightly rustc (1.94)

3 participants