Skip to content

proc_macro_quote: Undefined Behavior: trying to retag from .. for Unique permission at alloc.., but that tag does not exist in the borrow stack for this location #155148

@matthiaskrgr

Description

@matthiaskrgr

I got bored and ran miri on parts of my corpus and saw that

#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::quote;

fn main() {
    let s = "\u{1} a 'b \" c".to_string();
    quote!($s);
}

would panic when just being executed

thread 'main' (213631) panicked at /rustc/02c7f9bec0fd583160f8bcccb830216023b07bee/library/proc_macro/src/bridge/client.rs:186:32:
procedural macro API is used outside of a procedural macro

but under miri, it would throw ub which was flagged as there was no unsafe involved.
Feel free to close if this is bogus since we would normally hit the expect() anyway

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
     Running `/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/unreachable`
error: Undefined Behavior: trying to retag from <4522> for Unique permission at alloc1894[0xff1], but that tag does not exist in the borrow stack for this location
   --> /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:194:9
    |
194 |         &mut *ptr::slice_from_raw_parts_mut(data, len)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this error occurs as part of retag at alloc1894[0xff1..0x1000]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <4522> was created by a SharedReadWrite retag at offsets [0x0..0x1000]
   --> src/main.rs:9:5
    |
  9 |     quote!($s);
    |     ^^^^^^^^^^
help: <4522> was later invalidated at offsets [0x0..0x1000] by a Unique retag
   --> src/main.rs:9:5
    |
  9 |     quote!($s);
    |     ^^^^^^^^^^
    = note: stack backtrace:
            0: std::slice::from_raw_parts_mut::<'_, std::mem::MaybeUninit<u8>>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:194:9: 194:55
            1: proc_macro::bridge::arena::Arena::alloc_raw_without_grow
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/arena.rs:82:27: 82:68
            2: proc_macro::bridge::arena::Arena::alloc_raw
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/arena.rs:99:9: 99:43
            3: proc_macro::bridge::arena::Arena::alloc_str
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/arena.rs:104:21: 104:49
            4: proc_macro::bridge::symbol::Interner::intern
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/symbol.rs:156:28: 156:56
            5: proc_macro::bridge::symbol::Symbol::new::{closure#0}
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/symbol.rs:27:38: 27:54
            6: std::thread::LocalKey::<std::cell::RefCell<proc_macro::bridge::symbol::Interner>>::with_borrow_mut::<{closure@proc_macro::bridge::symbol::Symbol::new::{closure#0}}, proc_macro::bridge::symbol::Symbol>::{closure#0}
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:706:26: 706:51
            7: std::thread::LocalKey::<std::cell::RefCell<proc_macro::bridge::symbol::Interner>>::try_with::<{closure@std::thread::LocalKey<std::cell::RefCell<proc_macro::bridge::symbol::Interner>>::with_borrow_mut<{closure@proc_macro::bridge::symbol::Symbol::new::{closure#0}}, proc_macro::bridge::symbol::Symbol>::{closure#0}}, proc_macro::bridge::symbol::Symbol>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:462:12: 462:27
            8: std::thread::LocalKey::<std::cell::RefCell<proc_macro::bridge::symbol::Interner>>::with::<{closure@std::thread::LocalKey<std::cell::RefCell<proc_macro::bridge::symbol::Interner>>::with_borrow_mut<{closure@proc_macro::bridge::symbol::Symbol::new::{closure#0}}, proc_macro::bridge::symbol::Symbol>::{closure#0}}, proc_macro::bridge::symbol::Symbol>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:426:15: 426:31
            9: std::thread::LocalKey::<std::cell::RefCell<proc_macro::bridge::symbol::Interner>>::with_borrow_mut::<{closure@proc_macro::bridge::symbol::Symbol::new::{closure#0}}, proc_macro::bridge::symbol::Symbol>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:706:9: 706:52
            10: proc_macro::bridge::symbol::Symbol::new
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/symbol.rs:27:9: 27:55
            11: proc_macro::Literal::new
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/lib.rs:1190:21: 1190:55
            12: proc_macro::Literal::string
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/lib.rs:1325:9: 1325:56
            13: <std::string::String as proc_macro::ToTokens>::to_tokens
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/to_tokens.rs:294:9: 294:30
            14: main
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/lib.rs:463:1: 463:16
            15: <fn() as std::ops::FnOnce<()>>::call_once - shim(fn())
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5: 250:71
            16: std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:166:18: 166:21
            17: std::rt::lang_start::<()>::{closure#0}
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:206:18: 206:75
            18: std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:287:13: 287:31
            19: std::panicking::catch_unwind::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:581:40: 581:43
            20: std::panicking::catch_unwind::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:544:19: 544:88
            21: std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14: 359:40
            22: std::rt::lang_start_internal::{closure#0}
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:175:24: 175:49
            23: std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:581:40: 581:43
            24: std::panicking::catch_unwind::<isize, {closure@std::rt::lang_start_internal::{closure#0}}>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:544:19: 544:88
            25: std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14: 359:40
            26: std::rt::lang_start_internal
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:171:5: 193:7
            27: std::rt::lang_start::<()>
                at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:205:5: 210:6

error: aborting due to 1 previous error

Meta

rustc --version --verbose:

rustc 1.96.0-nightly (02c7f9bec 2026-04-10)
binary: rustc
commit-hash: 02c7f9bec0fd583160f8bcccb830216023b07bee
commit-date: 2026-04-10
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-proc_macro_quote`#![feature(proc_macro_quote)]`T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions