Fix: ICE when formatting builtins
Replace `unreachable!` with `None`. Now rustfmt won't panic when it comes across a `builtin # offset_of` or any other builtin
This commit is contained in:
parent
dd301b0c04
commit
202fa22cee
@ -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,
|
||||
};
|
||||
|
@ -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);
|
||||
|
3
tests/target/issue-5885.rs
Normal file
3
tests/target/issue-5885.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("{}", builtin # offset_of(A, 0. 1.1.1));
|
||||
}
|
1
tests/target/issue-6105.rs
Normal file
1
tests/target/issue-6105.rs
Normal file
@ -0,0 +1 @@
|
||||
const _: () = builtin # offset_of(x, x);
|
Loading…
x
Reference in New Issue
Block a user