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

ICE in rustc_lint::unused::UnusedParens #54752

Closed
jocelyn-stericker opened this issue Oct 2, 2018 · 1 comment · Fixed by #54777
Closed

ICE in rustc_lint::unused::UnusedParens #54752

jocelyn-stericker opened this issue Oct 2, 2018 · 1 comment · Fixed by #54777
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-pretty Area: Pretty printing (incl. `-Z unpretty`). I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@jocelyn-stericker
Copy link

jocelyn-stericker commented Oct 2, 2018

I tried compiling this code:

#![feature(await_macro, async_await, futures_api)]

#[macro_use]
extern crate tokio;

fn main() {
    tokio::run_async((async {}));
}

Note the extra set of parentheses.

My Cargo.toml had:

[package]
name = "rs_server"
version = "0.1.0"
authors = ["Joshua Netterfield <joshua@nettek.ca>"]
edition = "2018"

[dependencies]
futures = "0.1.24"
tokio = {version = "0.1.11",  features = ["async-await-preview"]}

I expected the compiler to not crash.

Instead, it crashed with the following output:

env RUST_BACKTRACE=1 cargo +nightly build 

... snip ...

   Compiling rs_server v0.1.0 (/Users/joshua/dev/hacklily/server/rs-server)
     Running `rustc --edition=2018 --crate-name rs_server src/main.rs --color never --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=570ddfa143c25928 -C extra-filename=-570ddfa143c25928 --out-dir /Users/joshua/dev/hacklily/server/rs-server/target/debug/deps -C incremental=/Users/joshua/dev/hacklily/server/rs-server/target/debug/incremental -L dependency=/Users/joshua/dev/hacklily/server/rs-server/target/debug/deps --extern futures=/Users/joshua/dev/hacklily/server/rs-server/target/debug/deps/libfutures-896873aebf27fd84.rlib --extern tokio=/Users/joshua/dev/hacklily/server/rs-server/target/debug/deps/libtokio-4702d2f4954beb28.rlib --extern tokio_process=/Users/joshua/dev/hacklily/server/rs-server/target/debug/deps/libtokio_process-5537fdad580af0a3.rlib`

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:355:21
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::continue_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic
  10: syntax::print::pprust::State::print_expr_outer_attr_style
  11: syntax::print::pprust::State::print_expr_outer_attr_style
  12: syntax::print::pprust::to_string
  13: syntax::print::pprust::expr_to_string
  14: rustc_lint::unused::UnusedParens::check_unused_parens_core
  15: <rustc_lint::unused::UnusedParens as rustc::lint::EarlyLintPass>::check_expr
  16: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  17: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  18: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_fn
  19: syntax::visit::walk_item
  20: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_item
  21: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_mod
  22: rustc::lint::context::check_ast_crate
  23: rustc::util::common::time
  24: rustc_driver::driver::phase_2_configure_and_expand
  25: rustc_driver::driver::compile_input
  26: rustc_driver::run_compiler_with_pool
  27: rustc_driver::driver::spawn_thread_pool
  28: rustc_driver::run_compiler
  29: syntax::with_globals
  30: __rust_maybe_catch_panic
  31: rustc_driver::run
  32: rustc_driver::main
  33: std::rt::lang_start::{{closure}}
  34: std::panicking::try::do_call
  35: __rust_maybe_catch_panic
  36: std::rt::lang_start_internal
  37: main
query stack during panic:
end of query stack

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.31.0-nightly (de3d640f5 2018-10-01) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `rs_server`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name rs_server src/main.rs --color never --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=570ddfa143c25928 -C extra-filename=-570ddfa143c25928 --out-dir /Users/joshua/dev/hacklily/server/rs-server/target/debug/deps -C incremental=/Users/joshua/dev/hacklily/server/rs-server/target/debug/incremental -L dependency=/Users/joshua/dev/hacklily/server/rs-server/target/debug/deps --extern futures=/Users/joshua/dev/hacklily/server/rs-server/target/debug/deps/libfutures-896873aebf27fd84.rlib --extern tokio=/Users/joshua/dev/hacklily/server/rs-server/target/debug/deps/libtokio-4702d2f4954beb28.rlib --extern tokio_process=/Users/joshua/dev/hacklily/server/rs-server/target/debug/deps/libtokio_process-5537fdad580af0a3.rlib` (exit code: 101)

Meta

rustc +nightly --version --verbose :

rustc 1.31.0-nightly (de3d640f5 2018-10-01)
binary: rustc
commit-hash: de3d640f59c4fa4a09faf2a8d6b0a812aaa6d6cb
commit-date: 2018-10-01
host: x86_64-apple-darwin
release: 1.31.0-nightly
LLVM version: 8.0
@zackmdavis zackmdavis added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Oct 2, 2018
@estebank estebank added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Oct 2, 2018
@zackmdavis zackmdavis added the A-pretty Area: Pretty printing (incl. `-Z unpretty`). label Oct 3, 2018
@zackmdavis
Copy link
Member

The example can be minimized to exclude tokio:

#![feature(async_await)]

fn main() {
    let _a = (async {});
}

I should have a PR in a few minutes (despite some discomfort about apparent solutions incompletely understood).

zackmdavis added a commit to zackmdavis/rust that referenced this issue Oct 3, 2018
Joshua Netterfield reported an ICE when the unused-parentheses lint
triggered around an async block (rust-lang#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 5c9f806.)

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 rust-lang#54752.
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 3, 2018
…ertj

abolish ICE when pretty-printing async block

@jnetterf reported an ICE when the unused-parentheses lint triggered around an async block (rust-lang#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 to answer that, you'd have to ask the author of 5c9f806.)

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](https://hacktoberfest.digitalocean.com/stats/zackmdavis)??

Humbly resolves rust-lang#54752.

r? @cramertj
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 4, 2018
…ertj

abolish ICE when pretty-printing async block

@jnetterf reported an ICE when the unused-parentheses lint triggered around an async block (rust-lang#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 to answer that, you'd have to ask the author of 5c9f806.)

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](https://hacktoberfest.digitalocean.com/stats/zackmdavis)??

Humbly resolves rust-lang#54752.

r? @cramertj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-pretty Area: Pretty printing (incl. `-Z unpretty`). I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants