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

Rustc panic when wrong namespace in destructuring patern #34413

Closed
michalsrb opened this issue Jun 22, 2016 · 2 comments
Closed

Rustc panic when wrong namespace in destructuring patern #34413

michalsrb opened this issue Jun 22, 2016 · 2 comments

Comments

@michalsrb
Copy link

Rustc panics when trying to compile this (incorrect) code:

struct SomeStruct {
    a: i32
}

fn main() {
    let s = SomeStruct { a: 1 };

    let SomeStruct::SomeStruct{ a } = s;
//      ^^^^^^^^^^^^ - this part is nonsense, but instead of an error rustc crashes
}

This is the smallest example I could get. The same error happens when that pattern is used inside if let or a match.

Backtrace:

> RUST_BACKTRACE=1 rustc main.rs 
error: internal compiler error: ../src/librustc/hir/def.rs:77: path not fully resolved: PathResolution { base_def: Struct(DefId { krate: 0, node: DefIndex(4) => SomeStruct }), 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:     0x7fb77ad4d7df - std::sys::backtrace::tracing::imp::write::h6528da8103c51ab9
   2:     0x7fb77ad5b78b - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hbe741a5cc3c49508
   3:     0x7fb77ad5b328 - std::panicking::default_hook::he0146e6a74621cb4
   4:     0x7fb77ad2131e - std::panicking::rust_panic_with_hook::h983af77c1a2e581b
   5:     0x7fb776137b07 - std::panicking::begin_panic::hf9f206df23a555af
   6:     0x7fb77613746e - syntax::errors::Handler::bug::hd25802f012f6858b
   7:     0x7fb777325f14 - rustc::session::opt_span_bug_fmt::_$u7b$$u7b$closure$u7d$$u7d$::h083e19915ee66466
   8:     0x7fb777325d1d - rustc::session::opt_span_bug_fmt::h157ddeb5b4622d22
   9:     0x7fb777340696 - rustc::session::bug_fmt::h166f9667daf4dd54
  10:     0x7fb777325b8f - rustc::ty::_<impl rustc..ty..context..TyCtxt<'a, 'gcx, 'tcx>>::expect_def::h1bba3da31e27b082
  11:     0x7fb779acb834 - rustc_typeck::check::_match::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::check_pat_struct::hb2aac908ea2f3898
  12:     0x7fb779a6a9e2 - rustc_typeck::check::_match::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::check_pat::hb68aedceeb2eae7b
  13:     0x7fb779ac3eab - rustc_typeck::check::FnCtxt::check_decl_local::ha8db63787b369f3c
  14:     0x7fb779ac4041 - rustc_typeck::check::FnCtxt::check_stmt::h7bb4ce1dbc8a215f
  15:     0x7fb779a6c933 - rustc_typeck::check::FnCtxt::check_block_with_expected::h66a8dcc154a53b83
  16:     0x7fb779a63c93 - rustc_typeck::check::check_fn::h74a0e95f02904d77
  17:     0x7fb779a60d8e - rustc_typeck::check::check_bare_fn::h7683dfd1c7fc31d1
  18:     0x7fb779a5c4e2 - rustc_typeck::check::check_item_body::h33cafe2320cee00a
  19:     0x7fb779a53fde - rustc_typeck::check::check_item_bodies::h0649c58896094a63
  20:     0x7fb779a49dd6 - rustc_typeck::check_crate::h9ad81a238efa1992
  21:     0x7fb77b280ccc - rustc_driver::driver::phase_3_run_analysis_passes::_$u7b$$u7b$closure$u7d$$u7d$::hd565ad56c5876a16
  22:     0x7fb77b27edb9 - rustc::ty::context::TyCtxt::create_and_enter::habef58c7230d34f9
  23:     0x7fb77b249f5f - rustc_driver::driver::compile_input::hfd60b020f6d0208d
  24:     0x7fb77b235e84 - rustc_driver::run_compiler::h884d01d12eb76bbb
  25:     0x7fb77b232f5e - std::panicking::try::call::hd72cf79141f67e60
  26:     0x7fb77ad69c4b - __rust_try
  27:     0x7fb77ad69bee - __rust_maybe_catch_panic
  28:     0x7fb77b233a44 - _<F as alloc..boxed..FnBox<A>>::call_box::h589d2091babf223a
  29:     0x7fb77ad598b4 - std::sys::thread::Thread::new::thread_start::h9c883b6d445ece46
  30:     0x7fb7728cb0a3 - start_thread
  31:     0x7fb77a99efec - __clone
  32:                0x0 - <unknown>

It happens with nightly (installed using rustup):

> rustc --version --verbose
rustc 1.11.0-nightly (5522e678b 2016-06-20)
binary: rustc
commit-hash: 5522e678bcefe14cc2ab3d0ab329b7059ce52b36
commit-date: 2016-06-20
host: x86_64-unknown-linux-gnu
release: 1.11.0-nightly

It does not happen with stable (rustc 1.10.0-beta.2 (39f3c16cc 2016-05-26)) or beta (rustc 1.9.0 (e4e8b6668 2016-05-18)) versions. With them I get error message as expected:

main.rs:8:9: 8:31 error: failed to resolve. Use of undeclared type or module `SomeStruct` [E0433]
main.rs:8     let SomeStruct::SomeStruct{a} = s;
                  ^~~~~~~~~~~~~~~~~~~~~~
main.rs:8:9: 8:31 help: run `rustc --explain E0433` to see a detailed explanation
main.rs:8:9: 8:34 error: `SomeStruct::SomeStruct` does not name a struct or a struct variant [E0163]
main.rs:8     let SomeStruct::SomeStruct{a} = s;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~
main.rs:8:9: 8:34 help: run `rustc --explain E0163` to see a detailed explanation
error: aborting due to previous error
@petrochenkov
Copy link
Contributor

Duplicate of #34209, fixed in #34365

@alexcrichton
Copy link
Member

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants