Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro fixup inserting {} characters as punct, causing proc macros to panic #19206

Open
ChayimFriedman2 opened this issue Feb 22, 2025 · 3 comments
Labels
A-macro macro expansion A-proc-macro proc macro

Comments

@ChayimFriedman2
Copy link
Contributor

@ChayimFriedman2

Hi - I am still seeing this exact bug, with rustc 1.84.1 (e71f9a9a9 2025-01-27), with both the latest analyzer versions available for VS Code: 0.3.2308 and 0.4.2312.

In my case the test case is

#[tokio::main]
async fn main() {
    loop {}
    // type 'while ' here
}

and the error displayed is

proc-macro panicked: unsupported proc macro punctuation character '{'.

EDIT: cargo build does not result in the proc macro panic, which is why I'm assuming the fault lies with analyzer and not with the macro itself (this is tokio_macros 2.5.0) – let me know if there's something I can do to prove one way or the other

EDIT 2: with nightly analyzer (2025-02-19)

Error SyntaxError from LineCol { line: 18, col: 18 } to LineCol { line: 18, col: 18 }: Syntax Error: expected a block
Error Ra("macro-error", Error) from LineCol { line: 15, col: 0 } to LineCol { line: 19, col: 1 }: proc-macro panicked: unsupported proc macro punctuation character '{'
processing crate: foobar, module: /Users/me/foobar/src/lib.rs

diagnostic scan complete

Error: diagnostic error detected

Stack backtrace:
   0: std::backtrace::Backtrace::create
   1: <anyhow::Error>::msg::<&str>
   2: std::sys::backtrace::__rust_begin_short_backtrace::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>
   3: <<std::thread::Builder>::spawn_unchecked_<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
   4: std::sys::pal::unix::thread::Thread::new::thread_start
   5: __pthread_deallocate

Originally posted by @tcbennun in #18840

@ChayimFriedman2 ChayimFriedman2 added A-macro macro expansion A-proc-macro proc macro labels Feb 22, 2025
@ChayimFriedman2
Copy link
Contributor Author

@tcbennun I created a new issue for this.

It appears this always was the case - do you remember if it used to work?

@tcbennun
Copy link

@tcbennun I created a new issue for this.

It appears this always was the case - do you remember if it used to work?

I don't remember seeing this issue before 2025, and I use proc macro attributes very frequently.

Is there a possibility this particular macro (in recent versions) is revealing the issue?

@Veykril
Copy link
Member

Veykril commented Feb 23, 2025

I think this is due to proc-macro2 now panicking on invalid punctuations which it didn't use to, dtolnay/proc-macro2#475. And so proc-macros trip over that if they roundtrip puncts handed to them by rust-analyzer (just guessing here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion A-proc-macro proc macro
Projects
None yet
Development

No branches or pull requests

3 participants