]> git.lizzy.rs Git - rust.git/commit
abolish ICE when pretty-printing async block
authorZack M. Davis <code@zackmdavis.net>
Wed, 3 Oct 2018 04:43:05 +0000 (21:43 -0700)
committerZack M. Davis <code@zackmdavis.net>
Wed, 3 Oct 2018 06:02:51 +0000 (23:02 -0700)
commit1081bbbfc5d170f22b5810b40c456a17da59cf7f
tree1173edef0f401a7670d77fdc72baf1d32ac7ca1b
parent4cf11765dc98536c6eedf33f2df7f72f6e161263
abolish ICE when pretty-printing async block

Joshua Netterfield reported an ICE when the unused-parentheses lint
triggered around an async block (#54752). In order to compose an
autofixable suggestion, the lint invokes the pretty-printer on the
unnecessarily-parenthesized expression. (One wonders why the lint
doesn't just use `SourceMap::span_to_snippet` instead, to preserve the
formatting of the original source?—but for that, you'd have to ask the
author of 5c9f806d.)

But then the pretty-printer panics when trying to call `<pprust::State
as PrintState>::end` when `State.boxes` is empty. Empirically, the
problem would seem to be solved if we start some "boxes" beforehand in
the `ast::ExprKind::Async` arm of the big match in
`print_expr_outer_attr_style`, exactly like we do in the
immediately-preceding match arm for `ast::ExprKind::Block`—it would
seem pretty ("pretty") reasonable for the pretty-printing of async
blocks to work a lot like the pretty-printing of ordinary non-async
blocks, right??

Of course, it would be shamefully cargo-culty to commit code on the
basis of this kind of mere reasoning-by-analogy (in contrast to
understanding the design of the pretty-printer in such detail that the
correctness of the patch is comprehended with all the lucid certainty
of mathematical proof, rather than being merely surmised by
intuition). But maybe we care more about fixing the bug with high
probability today, than with certainty in some indefinite hypothetical
future?  Maybe the effort is worth a fifth of a shirt??

Humbly resolves #54752.
src/libsyntax/print/pprust.rs
src/test/pretty/issue-54752-async-block.rs [new file with mode: 0644]