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

Internal compiler error when matching non-existant enum case (PathResolution) #34209

Closed
FabianEmmes opened this issue Jun 10, 2016 · 2 comments · Fixed by #34365
Closed

Internal compiler error when matching non-existant enum case (PathResolution) #34209

FabianEmmes opened this issue Jun 10, 2016 · 2 comments · Fixed by #34365
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@FabianEmmes
Copy link

Compiling the following program yields an internal compiler error:

enum S {
    A,
}

fn bug(l: S) {
    match l {
        S::B{ } => { },
    }
}

fn main () {}
$ rustc --version
rustc 1.11.0-nightly (7d2f75a95 2016-06-09)
$ rustc bug.rs
error: internal compiler error: ../src/librustc/hir/def.rs:77: path not fully resolved: PathResolution { base_def: Enum(DefId { krate: 0, node: DefIndex(4) => S }), depth: 1 }
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', ../src/libsyntax/errors/mod.rs:584
stack backtrace:
   1:     0x7fe96e1cc62f - std::sys::backtrace::tracing::imp::write::h6528da8103c51ab9
   2:     0x7fe96e1da26b - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hbe741a5cc3c49508
   3:     0x7fe96e1d9e08 - std::panicking::default_hook::he0146e6a74621cb4
   4:     0x7fe96e1a016e - std::panicking::rust_panic_with_hook::h983af77c1a2e581b
   5:     0x7fe96938d887 - std::panicking::begin_panic::hf9f206df23a555af
   6:     0x7fe96938d1ee - syntax::errors::Handler::bug::hd25802f012f6858b
   7:     0x7fe96a5b0134 - rustc::session::opt_span_bug_fmt::_$u7b$$u7b$closure$u7d$$u7d$::h083e19915ee66466
   8:     0x7fe96a5aff3d - rustc::session::opt_span_bug_fmt::h157ddeb5b4622d22
   9:     0x7fe96a5ca8b6 - rustc::session::bug_fmt::h166f9667daf4dd54
  10:     0x7fe96a5afdaf - rustc::ty::_<impl rustc..ty..context..TyCtxt<'a, 'gcx, 'tcx>>::expect_def::h1bba3da31e27b082
  11:     0x7fe96cd4c2a4 - rustc_typeck::check::_match::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::check_pat_struct::hb2aac908ea2f3898
  12:     0x7fe96ccebad2 - rustc_typeck::check::_match::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::check_pat::hb68aedceeb2eae7b
  13:     0x7fe96cd36ec2 - rustc_typeck::check::_match::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::check_match::he1e7f5ae9b0c3187
  14:     0x7fe96cd126cf - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::hc65ba746f75e2d76
  15:     0x7fe96ccedc3d - rustc_typeck::check::FnCtxt::check_block_with_expected::h66a8dcc154a53b83
  16:     0x7fe96cce4d7e - rustc_typeck::check::check_fn::h74a0e95f02904d77
  17:     0x7fe96cce1e6e - rustc_typeck::check::check_bare_fn::h7683dfd1c7fc31d1
  18:     0x7fe96ccdd5c2 - rustc_typeck::check::check_item_body::h33cafe2320cee00a
  19:     0x7fe96ccd50ce - rustc_typeck::check::check_item_bodies::h0649c58896094a63
  20:     0x7fe96cccaec6 - rustc_typeck::check_crate::h9ad81a238efa1992
  21:     0x7fe96e6ff7cc - rustc_driver::driver::phase_3_run_analysis_passes::_$u7b$$u7b$closure$u7d$$u7d$::hd565ad56c5876a16
  22:     0x7fe96e6fd8b9 - rustc::ty::context::TyCtxt::create_and_enter::habef58c7230d34f9
  23:     0x7fe96e6c7d7f - rustc_driver::driver::compile_input::hfd60b020f6d0208d
  24:     0x7fe96e6b3cc4 - rustc_driver::run_compiler::h884d01d12eb76bbb
  25:     0x7fe96e6b0d9e - std::panicking::try::call::hd72cf79141f67e60
  26:     0x7fe96e1e872b - __rust_try
  27:     0x7fe96e1e86ce - __rust_maybe_catch_panic
  28:     0x7fe96e6b1884 - _<F as alloc..boxed..FnBox<A>>::call_box::h589d2091babf223a
  29:     0x7fe96e1d8394 - std::sys::thread::Thread::new::thread_start::h9c883b6d445ece46
  30:     0x7fe965b1f473 - start_thread
  31:     0x7fe96de2769c - clone
  32:                0x0 - <unknown>

return code: 101
@petrochenkov
Copy link
Contributor

Ouch, this is a consequence of #34095.
It affects only erroneous programs, but it's still pretty bad.
I hoped to submit a fix until no one noticed... but, well. Expect it in a couple of days.

@petrochenkov
Copy link
Contributor

To explain what happens, before #34095 the compiler never tried to resolve paths in braced struct patterns, like S::B{ }, as associated types, it just reported an error immediately. Now these paths are sent to type checker for further resolution, but type checker is not ready to deal with them yet.

@nagisa nagisa added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jun 10, 2016
bors added a commit that referenced this issue Jul 9, 2016
Some more pattern cleanup and bugfixing

The next part of #34095

The most significant fixed mistake is definitions for partially resolved associated types not being updated after full resolution.
```
fn f<T: Fn()>(arg: T::Output) { .... } // <- the definition of T::Output was not updated in def_map
```
For this reason unstable associated types of stable traits, like `FnOnce::Output`, could be used in stable code when written in unqualified form. Now they are properly checked, this is a **[breaking-change]** (pretty minor one, but a crater run would be nice). The fix is not to use unstable library features in stable code, alternatively `FnOnce::Output` can be stabilized.

Besides that, paths in struct patterns and expressions `S::A { .. }` are now fully resolved as associated types. Such types cannot be identified as structs at the moment, i.e. the change doesn't make previously invalid code valid, but it improves error diagnostics.

Other changes: `Def::Err` is supported better (less chances for ICEs for erroneous code), some incorrect error messages are corrected, some duplicated error messages are not reported, ADT definitions are now available through constructor IDs, everything else is cleanup and code audit.

Fixes #34209
Closes #22933 (adds tests)

r? @eddyb
petrochenkov added a commit to petrochenkov/rust that referenced this issue Jul 21, 2016
alexcrichton added a commit that referenced this issue Jul 21, 2016
pmatos pushed a commit to LinkiTools/rust that referenced this issue Sep 27, 2016
pmatos pushed a commit to LinkiTools/rust that referenced this issue Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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