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

Fix: ICE with expanded code #6105 #6112

Merged
merged 5 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
10 changes: 8 additions & 2 deletions tests/rustfmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,14 @@ fn rustfmt_emits_error_on_line_overflow_true() {
#[test]
#[allow(non_snake_case)]
fn dont_emit_ICE() {
let files = ["tests/target/issue_5728.rs", "tests/target/issue_5729.rs", "tests/target/issue_6069.rs"];

let files = [
"tests/target/issue_5728.rs",
"tests/target/issue_5729.rs",
"tests/target/issue-5885.rs",
"tests/target/issue_6069.rs",
"tests/target/issue-6105.rs",
];

for file in files {
let args = [file];
let (_stdout, stderr) = rustfmt(&args);
Expand Down
3 changes: 3 additions & 0 deletions tests/target/issue-5885.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("{}", builtin # offset_of(A, 0. 1.1.1));
}
1 change: 1 addition & 0 deletions tests/target/issue-6105.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const _: () = builtin # offset_of(x, x);
Loading