rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.13k stars 12.8k forks source link

ICE when using enum variant as type #38862

Closed philipc closed 7 years ago

philipc commented 7 years ago

For this malformed code:

enum Foo { Bar }
struct Bar;

fn main() {
    use Foo::Bar;
    Bar::test();
}

rustc 1.14 gives the following expected error:

error[E0248]: found value `Foo::Bar` used as a type

But nightly gives an ICE:

error: internal compiler error: /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/astconv.rs:1516: unexpected definition: Variant(DefId { krate: CrateNum(0), node: DefIndex(4) => 4/38d5a863ce60d9b6fd14c5b598ccd3ed-exe::Foo[0]::Bar[0] })
 --> src/main.rs:6:5
  |
6 |     Bar::test();
  |     ^^^^^^^^^

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>', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_errors/lib.rs:382
stack backtrace:
   1:     0x7f2d1ade3dfc - std::sys::imp::backtrace::tracing::imp::write::h9c41d2f69e5caabf
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7f2d1adf229e - std::panicking::default_hook::{{closure}}::h1f61f3c769fffe7a
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:351
   3:     0x7f2d1adf1e43 - std::panicking::default_hook::hd5bda4e453dfb4be
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:361
   4:     0x7f2d1adf2747 - std::panicking::rust_panic_with_hook::hffbc74969c7b5d87
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:555
   5:     0x7f2d1919914b - std::panicking::begin_panic::h74ad4f050841c998
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:517
   6:     0x7f2d191da393 - rustc::session::opt_span_bug_fmt::{{closure}}::h8e30a0fda5e6d8ea
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/<panic macros>:3
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/session/mod.rs:787
   7:     0x7f2d191da1b6 - rustc::session::span_bug_fmt::h918b2dc33c0dfd9b
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:997
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:986
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/local.rs:253
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:982
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:997
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/session/mod.rs:784
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/session/mod.rs:777
   8:     0x7f2d192991ae - <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::def_to_ty::hd583143f2dff496f
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/astconv.rs:1516
   9:     0x7f2d1929a7c2 - <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::ast_ty_to_ty::hc8f39c96e200cd4f
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/astconv.rs:1649
  10:     0x7f2d19284487 - rustc_typeck::check::FnCtxt::resolve_ty_and_def_ufcs::h4636785be77450da
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:1857
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:4052
  11:     0x7f2d1927493d - rustc_typeck::check::FnCtxt::check_expr_kind::h7172316f2afc3db4
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:3615
  12:     0x7f2d19273312 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h58cbaadb2bb31008
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:3450
  13:     0x7f2d192420ae - rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_call::h388fc4549b25dc5a
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:2789
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:2793
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/callee.rs:50
  14:     0x7f2d19274441 - rustc_typeck::check::FnCtxt::check_expr_kind::h7172316f2afc3db4
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:3803
  15:     0x7f2d19273312 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h58cbaadb2bb31008
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:3450
  16:     0x7f2d19284c1d - rustc_typeck::check::FnCtxt::check_stmt::h5f0c409d0347ada0
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:2789
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:2793
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:4159
  17:     0x7f2d1928501e - rustc_typeck::check::FnCtxt::check_block_with_expected::h5fabdeff5662cd10
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:4194
  18:     0x7f2d1927379a - rustc_typeck::check::FnCtxt::check_expr_kind::h7172316f2afc3db4
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:3800
  19:     0x7f2d19273312 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h58cbaadb2bb31008
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:3450
  20:     0x7f2d1925a3be - rustc_typeck::check::check_fn::h7512874de533d1c6
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:2789
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:2783
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:2776
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:807
  21:     0x7f2d19259445 - rustc_typeck::check::check_bare_fn::hff8cbad9cd9ca12c
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:675
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:501
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/infer/mod.rs:443
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:970
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/local.rs:253
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:967
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:795
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/infer/mod.rs:443
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:501
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:665
  22:     0x7f2d1925be6d - rustc_typeck::check::check_item_body::h2a877e8ee0d16484
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:909
  23:     0x7f2d192569bb - rustc_typeck::check::check_item_bodies::hf9c5a615b1a27ce2
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:575
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/dep_graph/visit.rs:44
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/hir/mod.rs:457
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/dep_graph/visit.rs:75
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/mod.rs:2660
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:605
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/session/mod.rs:234
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:603
  24:     0x7f2d192c39ef - rustc_typeck::check_crate::h93455a3168487f9e
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/lib.rs:347
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/util/common.rs:48
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/lib.rs:347
  25:     0x7f2d1b195081 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::haccf5097991f72ff
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/driver.rs:896
  26:     0x7f2d1b187cc8 - rustc_driver::driver::phase_3_run_analysis_passes::hc8affcb7a7c3c449
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:970
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/local.rs:253
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:967
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:954
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/local.rs:253
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:951
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:730
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/driver.rs:867
  27:     0x7f2d1b1722e9 - rustc_driver::driver::compile_input::h44853ffed84a12cb
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/driver.rs:166
  28:     0x7f2d1b1b8d78 - rustc_driver::run_compiler::hdc4bb0fcf7d0917a
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/lib.rs:221
  29:     0x7f2d1b0c5b08 - std::panicking::try::do_call::ha583797d32a865bd
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/lib.rs:1119
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/lib.rs:137
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/lib.rs:1053
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panic.rs:296
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:460
  30:     0x7f2d1adfb5ba - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
  31:     0x7f2d1b0eef1b - <F as alloc::boxed::FnBox<A>>::call_box::h6903719257a678be
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:436
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panic.rs:361
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/mod.rs:357
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:605
  32:     0x7f2d1adf10f4 - std::sys::imp::thread::Thread::new::thread_start::h76badbf9b0ecaf58
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:615
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys_common/thread.rs:21
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84
  33:     0x7f2d12bf36b9 - start_thread
  34:     0x7f2d1aaa882c - clone
  35:                0x0 - <unknown>

rustc --version --verbose:

rustc 1.16.0-nightly (5d994d8b7 2017-01-05)
binary: rustc
commit-hash: 5d994d8b7e482e87467d4a521911477bd8284ce3
commit-date: 2017-01-05
host: x86_64-unknown-linux-gnu
release: 1.16.0-nightly
LLVM version: 3.9
petrochenkov commented 7 years ago

Slightly minimized:

enum E { V }

fn main() {
    E::V::associated_item;
}

The regression is introduced in https://github.com/rust-lang/rust/pull/38154 I thought this situation is always caught by resolve now. Preferable fix: actually catch this in resolve, rather than reintroducing the old error E0248 in typeck.