rust-lang / rust-lang/rust

`pin!()` macro no longer constant-promotes `&mut` references to empty arrays

Open
#142,345 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-pin C-bug P-low regression-from-stable-to-stable T-compiler T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

I tried this code:

use std::pin::{pin, Pin};

fn require_static(_: Pin<&'static mut [i32; 0]>) {}

pub fn weird() {
    require_static(pin!([]));
}

I expected to see this happen: The code compiles

Instead, this happened (when compiled with beta rust):

error[E0716]: temporary value dropped while borrowed
 --> src/lib.rs:6:20
  |
6 |     require_static(pin!([]));
  |     ---------------^^^^^^^^-- temporary value is freed at the end of this statement
  |     |              |
  |     |              creates a temporary value which is freed while still in use
  |     argument requires that borrow lasts for `'static`
  |
  = note: this error originates in the macro `pin` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0716`.
error: could not compile `playground` (lib) due to 1 previous error

See also #140126, which is about the fact that &mut references to empty arrays are, for some reason, sometimes allowed in const contexts.

This was found while messing around. I don't know if any code relies on this.

Version it worked on

It most recently worked on: stable Rust 1.87.0

Version with regression

The error is reproducible on the playground with 1.88.0-beta.5 (2025-06-01 645b44edd3717f02838d)

The regression presumably happened due to #139114. cc @m-ou-se

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged A-pin F-super_let

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example in src/lib.rs with the beta compiler and inspect the pin! macro behavior for the empty array reference. Compare it with stable Rust 1.87.0 and review the suspected regression from #139114, alongside the related const-context behavior in #140126. Done means the example compiles again with the expected 'static mutable reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.