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

thread 'main' panicked at 'assertion failed: self.tcx.sess.err_count() > 0', librustc_typeck/check/mod.rs:3783:19 #50581

Closed
vegard opened this issue May 9, 2018 · 1 comment · Fixed by #51070
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@vegard
Copy link

vegard commented May 9, 2018

Input:

fn f() {
    |x: [u8; break]| loop { };
}

fn main() {
    macro_rules! vec {
        (*) => ()
    }
}

Output:

$ rustc -Z external-macro-backtrace -
...
thread 'main' panicked at 'assertion failed: self.tcx.sess.err_count() > 0', librustc_typeck/check/mod.rs:3783:19
...
   6: std::panicking::begin_panic
             at /home/vegard/rust/src/libstd/panicking.rs:397
   7: rustc_typeck::check::FnCtxt::check_expr_kind
             at librustc_typeck/check/mod.rs:3783
   8: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
             at librustc_typeck/check/mod.rs:3530
   9: rustc_typeck::check::typeck_tables_of::{{closure}}
             at librustc_typeck/check/mod.rs:2864
             at librustc_typeck/check/mod.rs:2858
             at librustc_typeck/check/mod.rs:2851
             at librustc_typeck/check/mod.rs:885
...
Complete output
$ rustc -Z external-macro-backtrace -
warning: unused macro definition
 --> <anon>:6:5
  |
6 | /     macro_rules! vec {
7 | |         (*) => ()
8 | |     }
  | |_____^
  |
  = note: #[warn(unused_macros)] on by default

thread 'main' panicked at 'assertion failed: self.tcx.sess.err_count() > 0', librustc_typeck/check/mod.rs:3783:19
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
             at librustc/util/common.rs:54
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:467
   6: std::panicking::begin_panic
             at /home/vegard/rust/src/libstd/panicking.rs:397
   7: rustc_typeck::check::FnCtxt::check_expr_kind
             at librustc_typeck/check/mod.rs:3783
   8: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
             at librustc_typeck/check/mod.rs:3530
   9: rustc_typeck::check::typeck_tables_of::{{closure}}
             at librustc_typeck/check/mod.rs:2864
             at librustc_typeck/check/mod.rs:2858
             at librustc_typeck/check/mod.rs:2851
             at librustc_typeck/check/mod.rs:885
  10: rustc_typeck::check::typeck_tables_of
             at librustc_typeck/check/mod.rs:617
             at /home/vegard/rust/src/librustc/infer/mod.rs:453
             at /home/vegard/rust/src/librustc/ty/context.rs:1578
             at /home/vegard/rust/src/librustc/ty/context.rs:1844
             at /home/vegard/rust/src/librustc/ty/context.rs:1787
             at /home/vegard/rust/src/librustc/ty/context.rs:1843
             at /home/vegard/rust/src/librustc/ty/context.rs:1577
             at /home/vegard/rust/src/librustc/ty/context.rs:1905
             at /home/vegard/rust/src/librustc/ty/context.rs:1889
             at /home/vegard/rust/src/librustc/ty/context.rs:1880
             at /home/vegard/rust/src/librustc/ty/context.rs:1889
             at /home/vegard/rust/src/librustc/ty/context.rs:1900
             at /home/vegard/rust/src/librustc/ty/context.rs:1570
             at /home/vegard/rust/src/librustc/infer/mod.rs:453
             at librustc_typeck/check/mod.rs:617
             at librustc_typeck/check/mod.rs:855
  11: rustc::dep_graph::graph::DepGraph::with_task_impl
             at librustc/ty/maps/plumbing.rs:723
             at librustc/dep_graph/graph.rs:343
  12: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
             at librustc/dep_graph/graph.rs:209
             at librustc/ty/maps/plumbing.rs:530
             at librustc/ty/maps/plumbing.rs:200
             at librustc/ty/context.rs:1844
             at librustc/ty/context.rs:1787
             at librustc/ty/context.rs:1843
             at librustc/ty/maps/plumbing.rs:199
             at librustc/ty/context.rs:1905
             at librustc/ty/context.rs:1889
             at librustc/ty/context.rs:1880
             at librustc/ty/context.rs:1889
             at librustc/ty/context.rs:1900
             at librustc/ty/maps/plumbing.rs:189
             at librustc/ty/maps/plumbing.rs:523
  13: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
             at librustc/ty/maps/plumbing.rs:372
             at librustc/ty/maps/plumbing.rs:599
             at librustc/ty/maps/plumbing.rs:606
  14: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
             at librustc/ty/maps/plumbing.rs:776
             at librustc/ty/maps/plumbing.rs:769
  15: rustc_mir::interpret::const_eval::const_eval_provider
             at librustc_mir/interpret/const_eval.rs:447
  16: rustc::dep_graph::graph::DepGraph::with_task_impl
             at librustc/ty/maps/plumbing.rs:723
             at librustc/dep_graph/graph.rs:343
  17: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
             at librustc/dep_graph/graph.rs:209
             at librustc/ty/maps/plumbing.rs:530
             at librustc/ty/maps/plumbing.rs:200
             at librustc/ty/context.rs:1844
             at librustc/ty/context.rs:1787
             at librustc/ty/context.rs:1843
             at librustc/ty/maps/plumbing.rs:199
             at librustc/ty/context.rs:1905
             at librustc/ty/context.rs:1889
             at librustc/ty/context.rs:1880
             at librustc/ty/context.rs:1889
             at librustc/ty/context.rs:1900
             at librustc/ty/maps/plumbing.rs:189
             at librustc/ty/maps/plumbing.rs:523
  18: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_query
             at librustc/ty/maps/plumbing.rs:372
             at librustc/ty/maps/plumbing.rs:599
  19: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const
             at librustc/ty/maps/plumbing.rs:606
             at librustc/ty/maps/plumbing.rs:776
             at librustc/ty/maps/plumbing.rs:769
             at librustc/traits/project.rs:436
  20: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
             at librustc/ty/structural_impls.rs:1176
             at librustc/ty/structural_impls.rs:857
             at librustc/traits/project.rs:346
  21: rustc_typeck::check::Inherited::normalize_associated_types_in
             at /home/vegard/rust/src/librustc/ty/structural_impls.rs:890
             at /home/vegard/rust/src/librustc/traits/project.rs:324
             at /home/vegard/rust/src/librustc/traits/project.rs:283
             at /home/vegard/rust/src/librustc/traits/project.rs:267
             at /home/vegard/rust/src/librustc/infer/mod.rs:1358
             at librustc_typeck/check/mod.rs:677
  22: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::normalize_ty
             at librustc_typeck/check/mod.rs:2075
             at librustc_typeck/check/mod.rs:1776
  23: <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::ast_ty_to_ty
             at librustc_typeck/astconv.rs:1095
  24: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::supplied_sig_of_closure
             at librustc_typeck/check/closure.rs:604
             at /home/vegard/rust/src/libcore/ops/function.rs:271
             at /home/vegard/rust/src/libcore/option.rs:404
             at /home/vegard/rust/src/libcore/iter/mod.rs:1347
             at /home/vegard/rust/src/libcore/iter/mod.rs:814
             at /home/vegard/rust/src/librustc_data_structures/array_vec.rs:197
             at /home/vegard/rust/src/librustc_data_structures/accumulate_vec.rs:113
             at /home/vegard/rust/src/libcore/iter/iterator.rs:1375
             at /home/vegard/rust/src/librustc/ty/context.rs:2729
             at /home/vegard/rust/src/librustc/ty/context.rs:2717
             at /home/vegard/rust/src/librustc/ty/context.rs:2569
             at librustc_typeck/check/closure.rs:610
  25: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::sig_of_closure_no_expectation
             at librustc_typeck/check/closure.rs:379
  26: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_closure
             at librustc_typeck/check/closure.rs:365
             at librustc_typeck/check/closure.rs:88
  27: rustc_typeck::check::FnCtxt::check_expr_kind
             at librustc_typeck/check/closure.rs:66
             at librustc_typeck/check/mod.rs:3910
  28: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
             at librustc_typeck/check/mod.rs:3530
  29: rustc_typeck::check::FnCtxt::check_block_with_expected::{{closure}}
             at librustc_typeck/check/mod.rs:2864
             at librustc_typeck/check/mod.rs:2868
             at librustc_typeck/check/mod.rs:4296
             at librustc_typeck/check/mod.rs:4361
  30: rustc_typeck::check::FnCtxt::check_block_with_expected
             at librustc_typeck/check/mod.rs:5070
             at librustc_typeck/check/mod.rs:4359
  31: rustc_typeck::check::FnCtxt::check_expr_kind
             at librustc_typeck/check/mod.rs:3913
  32: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
             at librustc_typeck/check/mod.rs:3530
  33: rustc_typeck::check::FnCtxt::check_return_expr
             at librustc_typeck/check/mod.rs:2864
             at librustc_typeck/check/mod.rs:2858
             at librustc_typeck/check/mod.rs:2996
  34: rustc_typeck::check::check_fn
             at librustc_typeck/check/mod.rs:1081
  35: rustc_typeck::check::typeck_tables_of::{{closure}}
             at librustc_typeck/check/mod.rs:871
  36: rustc_typeck::check::typeck_tables_of
             at librustc_typeck/check/mod.rs:617
             at /home/vegard/rust/src/librustc/infer/mod.rs:453
             at /home/vegard/rust/src/librustc/ty/context.rs:1578
             at /home/vegard/rust/src/librustc/ty/context.rs:1844
             at /home/vegard/rust/src/librustc/ty/context.rs:1787
             at /home/vegard/rust/src/librustc/ty/context.rs:1843
             at /home/vegard/rust/src/librustc/ty/context.rs:1577
             at /home/vegard/rust/src/librustc/ty/context.rs:1905
             at /home/vegard/rust/src/librustc/ty/context.rs:1889
             at /home/vegard/rust/src/librustc/ty/context.rs:1880
             at /home/vegard/rust/src/librustc/ty/context.rs:1889
             at /home/vegard/rust/src/librustc/ty/context.rs:1900
             at /home/vegard/rust/src/librustc/ty/context.rs:1570
             at /home/vegard/rust/src/librustc/infer/mod.rs:453
             at librustc_typeck/check/mod.rs:617
             at librustc_typeck/check/mod.rs:855
  37: rustc::dep_graph::graph::DepGraph::with_task_impl
             at librustc/ty/maps/plumbing.rs:723
             at librustc/dep_graph/graph.rs:343
  38: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
             at librustc/dep_graph/graph.rs:209
             at librustc/ty/maps/plumbing.rs:530
             at librustc/ty/maps/plumbing.rs:200
             at librustc/ty/context.rs:1844
             at librustc/ty/context.rs:1787
             at librustc/ty/context.rs:1843
             at librustc/ty/maps/plumbing.rs:199
             at librustc/ty/context.rs:1905
             at librustc/ty/context.rs:1889
             at librustc/ty/context.rs:1880
             at librustc/ty/context.rs:1889
             at librustc/ty/context.rs:1900
             at librustc/ty/maps/plumbing.rs:189
             at librustc/ty/maps/plumbing.rs:523
  39: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
             at librustc/ty/maps/plumbing.rs:372
             at librustc/ty/maps/plumbing.rs:599
             at librustc/ty/maps/plumbing.rs:606
  40: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
             at librustc/ty/maps/plumbing.rs:574
             at librustc/ty/maps/plumbing.rs:740
  41: rustc_typeck::check::typeck_item_bodies
             at librustc_typeck/check/mod.rs:715
             at /home/vegard/rust/src/librustc/session/mod.rs:318
             at librustc_typeck/check/mod.rs:713
  42: rustc::dep_graph::graph::DepGraph::with_task_impl
             at librustc/ty/maps/plumbing.rs:723
             at librustc/dep_graph/graph.rs:343
  43: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
             at librustc/dep_graph/graph.rs:209
             at librustc/ty/maps/plumbing.rs:530
             at librustc/ty/maps/plumbing.rs:200
             at librustc/ty/context.rs:1844
             at librustc/ty/context.rs:1787
             at librustc/ty/context.rs:1843
             at librustc/ty/maps/plumbing.rs:199
             at librustc/ty/context.rs:1905
             at librustc/ty/context.rs:1889
             at librustc/ty/context.rs:1880
             at librustc/ty/context.rs:1889
             at librustc/ty/context.rs:1900
             at librustc/ty/maps/plumbing.rs:189
             at librustc/ty/maps/plumbing.rs:523
  44: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
             at librustc/ty/maps/plumbing.rs:372
             at librustc/ty/maps/plumbing.rs:599
             at librustc/ty/maps/plumbing.rs:606
  45: rustc_typeck::check_crate
             at librustc_typeck/check/mod.rs:706
             at librustc_typeck/lib.rs:344
             at /home/vegard/rust/src/librustc/util/common.rs:166
             at /home/vegard/rust/src/librustc/util/common.rs:160
             at librustc_typeck/lib.rs:344
  46: rustc::ty::context::TyCtxt::create_and_enter
             at librustc_driver/driver.rs:1121
             at /home/vegard/rust/src/librustc/ty/context.rs:1867
             at /home/vegard/rust/src/librustc/ty/context.rs:1844
             at /home/vegard/rust/src/librustc/ty/context.rs:1787
             at /home/vegard/rust/src/librustc/ty/context.rs:1843
             at /home/vegard/rust/src/librustc/ty/context.rs:1866
             at /home/vegard/rust/src/librustc/ty/context.rs:1833
             at /home/vegard/rust/src/libstd/thread/local.rs:294
             at /home/vegard/rust/src/libstd/thread/local.rs:248
             at /home/vegard/rust/src/librustc/ty/context.rs:1825
             at /home/vegard/rust/src/libstd/thread/local.rs:294
             at /home/vegard/rust/src/libstd/thread/local.rs:248
             at /home/vegard/rust/src/librustc/ty/context.rs:1817
             at /home/vegard/rust/src/librustc/ty/context.rs:1855
             at /home/vegard/rust/src/librustc/ty/context.rs:1299
  47: rustc_driver::driver::compile_input
             at librustc_driver/driver.rs:1095
             at librustc_driver/driver.rs:231
  48: rustc_driver::run_compiler
             at librustc_driver/lib.rs:540
             at librustc_driver/lib.rs:457
             at /home/vegard/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/scoped-tls-0.1.1/src/lib.rs:155
             at /home/vegard/rust/src/libsyntax/lib.rs:97
             at /home/vegard/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/scoped-tls-0.1.1/src/lib.rs:155
             at /home/vegard/rust/src/libsyntax/lib.rs:96
             at librustc_driver/lib.rs:456
  49: rustc_driver::monitor::{{closure}}
             at librustc_driver/lib.rs:1684
             at librustc_driver/lib.rs:174
             at librustc_driver/lib.rs:1598
  50: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  51: rustc_driver::run
             at /home/vegard/rust/src/libstd/panicking.rs:289
             at /home/vegard/rust/src/libstd/panic.rs:374
             at librustc_driver/lib.rs:1530
             at librustc_driver/lib.rs:1597
             at librustc_driver/lib.rs:173
  52: rustc_driver::main
             at librustc_driver/lib.rs:1677
  53: std::rt::lang_start::{{closure}}
             at /home/vegard/rust/src/libstd/rt.rs:74
  54: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  55: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  56: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:374
             at libstd/rt.rs:58
  57: main
  58: __libc_start_main
  59: _start
query stack during panic:
#0 [typeck_tables_of] processing `f::{{closure}}::{{initializer}}`
#1 [const_eval] const-evaluating `f::{{closure}}::{{initializer}}`
#2 [typeck_tables_of] processing `f`
#3 [typeck_item_bodies] type-checking all item bodies
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.27.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z external-macro-backtrace

On commit c166b03.

@pietroalbini pietroalbini added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 9, 2018
kennytm added a commit to kennytm/rust that referenced this issue May 22, 2018
…woerister

CheckLoopVisitor: also visit closure arguments

This turns the ICE rust-lang#50581 in this code:

```rust
fn main() {
    |_: [u8; break]| ();
}
```

from
```
    'assertion failed: self.tcx.sess.err_count() > 0', librustc_typeck/check/mod.rs
```
to
```
    librustc_mir/hair/cx/expr.rs:543: invalid loop id for break: not inside loop scope
```

which is an ICE as well but at a later stage during compilation and most importantly
fixes of bug rust-lang#50576 will fix this as well.

As this "only" moves an ICE to a later stage, I didn't add any tests.

Now I have manually verified the default impls of the visitor trait to check whether we have missed any other opportunity to visit more stuff and coudln't find anything (except the missing `break` visit I've fixed in rust-lang#50829 but that one was already r+'d so I didn't want to push more commits).
@est31
Copy link
Member

est31 commented May 23, 2018

With #50849 merged, the ICE message changed and this bug is effectively a dupe of #50576 now.

est31 added a commit to est31/rust that referenced this issue May 26, 2018
Lone breaks outside of loops create errors in the
loop check pass but as they are not fatal,
compilation continues.

MIR building code assumes all HIR break statements
to point to valid locations and fires ICEs if this
assumption is violated. In normal compilation,
this causes no issues, as code apparently prevents
MIR from being built if errors are present.

However, before that, typecheck runs and with it
MIR const eval. Here we operate differently
from normal compilation: it doesn't check for any
errors except for type checker ones and then
directly builds the MIR.

This constellation causes an ICE-on-error if
bogus break statements are being put into array
length expressions.

This commit fixes this ICE by letting typecheck
fail if bogus break statements are encountered.
This way, MIR const eval fails cleanly with a
type check error.

Fixes rust-lang#50576
Fixes rust-lang#50581
kennytm added a commit to kennytm/rust that referenced this issue May 26, 2018
Fail typecheck if we encounter a bogus break

Lone breaks outside of loops create errors in the
loop check pass but as they are not fatal,
compilation continues.

MIR building code assumes all HIR break statements
to point to valid locations and fires ICEs if this
assumption is violated. In normal compilation,
this causes no issues, as code apparently prevents
MIR from being built if errors are present.

However, before that, typecheck runs and with it
MIR const eval. Here we operate differently
from normal compilation: it doesn't check for any
errors except for type checker ones and then
directly builds the MIR.

This constellation causes an ICE-on-error if
bogus break statements are being put into array
length expressions.

This commit fixes this ICE by letting typecheck
fail if bogus break statements are encountered.
This way, MIR const eval fails cleanly with a
type check error.

Fixes rust-lang#50576
Fixes rust-lang#50581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants