-
Notifications
You must be signed in to change notification settings - Fork 981
Closed as duplicate of#6739
Closed as duplicate of#6739
Copy link
Labels
needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.This issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
Description
Summary
rustfmt panics when formatting code containing quote!(Self(#interpolated_var)). This is a regression from Rust 1.92.0.
Reproduction
Repository: https://github.com/natepiano/rustfmt_bug_repro
# Cargo.toml
[package]
name = "rustfmt_bug_repro"
version = "0.1.0"
edition = "2024"
[dependencies]
quote = "1"// src/lib.rs
use quote::quote;
fn f() {
let y = 0;
quote!(Self(#y));
}
// Workaround that doesn't panic:
// fn f_workaround() {
// let y = 0;
// let self_ty = quote!(Self);
// quote!(#self_ty(#y));
// }Command: rustfmt src/lib.rs
Error Output
thread 'main' panicked at compiler/rustc_parse/src/parser/item.rs:400:32:
called `Result::unwrap()` on an `Err` value: Some(DiagInner { level: Error, messages: [(FluentIdentifier("parse_expected_identifier_found_keyword_str", None), NoStyle)], ... args: {"token": Str("Self")}, ... })
The panic occurs in rustfmt_nightly::parse::macros::parse_macro_arg when parsing the Self keyword followed by parentheses containing an interpolated variable.
Version Info
Fails on:
- rustc 1.93.0 (254b59607 2026-01-19)
- rustfmt 1.8.0-stable (254b59607d 2026-01-19)
Works on:
- rustc 1.92.0 (ded5c06cf 2025-12-08)
Impact
This affects real-world code including Bevy's bevy_reflect_derive crate which uses this pattern.
Workaround
Pre-construct Self as a separate token stream:
let self_ty = quote!(Self);
quote!(#self_ty(#y)); // instead of quote!(Self(#y))Metadata
Metadata
Assignees
Labels
needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.This issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.