Skip to content

Miri reports UB for explicit tail call with by-value non-ZST struct parameter #144820

@narpfel

Description

@narpfel

I tried this code:

#![feature(explicit_tail_calls)]
#![expect(incomplete_features)]

struct Wrapper(#[expect(unused)] usize);

fn f(x: Wrapper) {
    become f(x);
}

fn main() {
    f(Wrapper(5));
}

I expected to see this happen: This should be an infinite loop.

Instead, this happened: When run in Miri, this reports UB on the first become f(x):

$ cargo miri run
error: Undefined Behavior: memory access failed: alloc198 has been freed, so this pointer is dangling
  --> src/main.rs:11:5
   |
11 |     f(Wrapper(5));
   |     ^^^^^^^^^^^^^ Undefined Behavior occurred here
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
help: alloc198 was allocated here:
  --> src/main.rs:7:14
   |
 7 |     become f(x);
   |              ^
help: alloc198 was deallocated here:
  --> src/main.rs:11:5
   |
11 |     f(Wrapper(5));
   |     ^^^^^^^^^^^^^
   = note: BACKTRACE (of the first span):
   = note: inside `main` at src/main.rs:11:5: 11:18

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

(playground link)

Meta

rustc --version --verbose:

rustc 1.90.0-nightly (4b55fe199 2025-08-01)
binary: rustc
commit-hash: 4b55fe199cfe9c710555a5af7f2a49491ad38254
commit-date: 2025-08-01
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8
Backtrace

<backtrace>

@rustbot label +F-explicit_tail_calls +requires-incomplete-features

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.F-explicit_tail_calls`#![feature(explicit_tail_calls)]`requires-incomplete-featuresThis issue requires the use of incomplete features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions