-
Notifications
You must be signed in to change notification settings - Fork 1.7k
"internal error: entered unreachable code" when expanding function-like proc macros #6868
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
Comments
Do you mean that it might still happen with a proc macro that returns its input unchanged? That might be a path to a minimized test case.
The expansion still fails, but the errors are not reported. |
It does still happen if I replace the macro implementations with just |
Ah, I was wrong, actually. If I replace the macro implementations with a passthrough, close vscode, delete |
The target directory shouldn't matter for rust-analyzer, a restart should make it give that error again. Can you try to simplify the macros? |
I think I'm onto something, but I'm getting the diagnostic "proc macro not expanded" and don't know what that means or how to fix it. |
"proc macro not expanded" means that the proc macro could not be found in the library produced by Cargo. If you set |
|
Never mind, I just forgot to set the options that let rust-analyzer evaluate proc macros :p I have a minimal reproduction now: repro.zip |
The error no longer occurs for any of my macros with the new version that was published about an hour ago. |
Okay, maybe we can close it, but I found it really easy to make it crash: #6880. |
Well, let's close this. I still haven't figured why it's crashing on my computer, but if it works for you, that's great. |
matklad.rust-analyzer
v0.2.408I have a workspace with two crates defining various proc macros and one crate using them. I don't use any proc macros from crates outside this workspace. I only use derive macros and function-like macros, and the derive macros don't seem to be affected.
About half of the function-like proc macro invocations result in the error
proc macro returned error: Cannot perform expansion for say: error String("internal error: entered unreachable code")
(with the name of the relevant macro in place of "say"):When I close vscode, delete the "target" directory, and reopen vscode, the same invocations produce errors every time. Whether the error occurs seems to have some strange relationship with the tokens passed into the macro. For instance, this is okay:
But this errors:
The difference in this case seems to be that the source of the string in the latter is exactly one byte long.
":"
,"C"
, and" "
all error, for instance, but"::"
,""
,"ü"
, and"\n"
don't. But that's just in this case. This, for instance, also errors despite having no one-byte string literals:Which macro is being called and where and in what file the invocation is haven't made a difference in my experiments. When editing, the feedback on whether or not the error is triggered is instantaneous, even without saving.
The error only seems to occur, at least visibly, with the latest version of the extension, v0.2.408. If I downgrade to v0.2.400, I stop getting the red squiggly lines.
The project isn't public, and I haven't managed to create a minimal reproduction, but it's a personal project, so I could send a copy privately to a trusted rust-analyzer contributor if you need it.
The text was updated successfully, but these errors were encountered: