From fe0d6e174741de4a4fb146b69ba5a1f550e3d89c Mon Sep 17 00:00:00 2001 From: Tanishq Rajesh Jain <127596924+Tanjaint21@users.noreply.github.com> Date: Tue, 12 Mar 2024 01:49:49 +0530 Subject: [PATCH 1/5] Replace `unreachable!` with `None` --- src/expr.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 147f4b31a3b..6a21d88ac9d 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, }; From c454081385513ea1db45941eed53d772a296399b Mon Sep 17 00:00:00 2001 From: Tanishq Rajesh Jain <127596924+Tanjaint21@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:34:46 +0530 Subject: [PATCH 2/5] add test #6105 --- tests/target/issue-6105.rs | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/target/issue-6105.rs diff --git a/tests/target/issue-6105.rs b/tests/target/issue-6105.rs new file mode 100644 index 00000000000..b74c236d5d9 --- /dev/null +++ b/tests/target/issue-6105.rs @@ -0,0 +1 @@ +const _: () = builtin # offset_of(x, x); \ No newline at end of file From 5fe375eb45fe4fbd24b9a48bc3dabcee23e3005d Mon Sep 17 00:00:00 2001 From: Tanishq Rajesh Jain <127596924+Tanjaint21@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:36:57 +0530 Subject: [PATCH 3/5] add test #5885 --- tests/target/issue-5885.rs | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/target/issue-5885.rs diff --git a/tests/target/issue-5885.rs b/tests/target/issue-5885.rs new file mode 100644 index 00000000000..f7580cce510 --- /dev/null +++ b/tests/target/issue-5885.rs @@ -0,0 +1,3 @@ +fn main() { + println!("{}", builtin # offset_of(A, 0. 1.1.1)); +} \ No newline at end of file From ec8b50f76cbd1842c14b73f1570d5d8856e63af5 Mon Sep 17 00:00:00 2001 From: Tanishq Rajesh Jain <127596924+Tanjaint21@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:51:25 +0530 Subject: [PATCH 4/5] fix failing CI --- tests/target/issue-5885.rs | 2 +- tests/target/issue-6105.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/target/issue-5885.rs b/tests/target/issue-5885.rs index f7580cce510..85a659cbb47 100644 --- a/tests/target/issue-5885.rs +++ b/tests/target/issue-5885.rs @@ -1,3 +1,3 @@ fn main() { println!("{}", builtin # offset_of(A, 0. 1.1.1)); -} \ No newline at end of file +} diff --git a/tests/target/issue-6105.rs b/tests/target/issue-6105.rs index b74c236d5d9..1eb0ce89f78 100644 --- a/tests/target/issue-6105.rs +++ b/tests/target/issue-6105.rs @@ -1 +1 @@ -const _: () = builtin # offset_of(x, x); \ No newline at end of file +const _: () = builtin # offset_of(x, x); From 514b6d6a5146c34c8efe97339f0e7b7a8262015b Mon Sep 17 00:00:00 2001 From: Tanishq Rajesh Jain <127596924+Tanjaint21@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:49:51 +0530 Subject: [PATCH 5/5] add files to test --- tests/rustfmt/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs index 11fb4786e82..39c93c97fa6 100644 --- a/tests/rustfmt/main.rs +++ b/tests/rustfmt/main.rs @@ -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);