Skip to content

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

Open
@theemathas

Description

@theemathas

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-pinArea: PinC-bugCategory: This is a bug.F-super_letit's super, let's go!I-prioritizeIssue: Indicates that prioritization has been requested for this issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions