-
Notifications
You must be signed in to change notification settings - Fork 888
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
rustfmt
ICE with expanded code
#6105
Comments
Pretty sure this is a duplicate of #5885. I think the quickest fix for now would be to return |
Indeed, looks like it, thanks! If ignoring (or similar) is possible, that is great. In general, what would be best is knowing that |
To the best of my knowledge, as long as the output from One caveat would be a case like this where there was an assumption that certain AST nodes would never appear directly in the AST, and instead would be expanded later in the compilation process. There might also be cases where rustfmt doesn't handle experimental, nightly-only syntax. Another thing to keep in mind is that the |
Thanks for the analysis! Yeah, I think it is reasonable that the output of If you want, we could reuse this issue to make it more about the general idea of ensuring it can process (to some degree) |
Overall I think makes sense to add one off code snippets like the one you included in the issue description as test cases for rustfmt, but I don't know if we'd set up exhaustive It's hard to guarantee that rustfmt can handle all the I agree that it would be better if rustfmt could process the In this case I think the fix for this one is something like this: diff --git a/src/expr.rs b/src/expr.rs
index 147f4b31..6a21d88a 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -404,8 +404,11 @@ pub(crate) fn format_expr(
ast::ExprKind::FormatArgs(..)
| ast::ExprKind::IncludedBytes(..)
| ast::ExprKind::OffsetOf(..) => {
- // These do not occur in the AST because macros aren't expanded.
- unreachable!()
+ // These don't normally occur in the AST because macros aren't expanded. However,
+ // rustfmt tries to parse macro arguments when formatting macros, so it's not totally
+ // impossible for rustfmt to come across one of these nodes when formatting a file.
+ // Also, rustfmt might get passed the output from `-Zunpretty=expanded`.
+ None
}
ast::ExprKind::Err => None,
}; |
Thanks! That makes sense -- we will report the ICEs then. I added a note about it on our linked issue. Of course, bugs can happen :) It was more about knowing whether expanded output was intended to be handled or not. |
@rustbot claim |
I just hit this issue with |
@y86-dev I can understand the confusion. Fixes applied directly to rustfmt won't be reflected in nightly until we sync rustfmt up with rust-lang/rust |
For reference: I can see it fixed in the current nightly (1.81.0), but not the current beta (1.80.0). |
1.80 beta was cut before the subtree sync with the fix. i don't recall offhand where 1.80 is on the release train but if it's not too late then we could see if the relevant teams would support a backport to beta to pull it in |
Ah, sorry, I wrote the message for reference since I was taking a look to see in which version it got fixed. But, of course, getting it into 1.80.0 would be nice, since some people want to use the feature and it has been a while. There are a bit more than 3 weeks until its release. |
Code
Minimized from expanded code (i.e.
-Zunpretty=expanded
) that werustfmt
in the Linux kernel to make it easier to read:Which makes sense, given:
https://github.com/rust-lang/rust/blob/7606c13961ddc1174b70638e934df0439b7dc515/src/tools/rustfmt/src/expr.rs#L401-L406
However, it would be nice to ignore (or format) these so that we can format expanded code.
Meta
It breaks in the latest stable (1.76.0) and nightly:
Error output
Backtrace
Cc: @metaspace (who found it when trying to expand his
rnull
driver)From: https://rust-for-linux.zulipchat.com/#narrow/stream/291565-Help/topic/Using.20the.20.2Ersi.20target/near/423973701.
The text was updated successfully, but these errors were encountered: