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

“Let NullaryConstructor = something;” causes internal compiler error: “tried to overwrite interned AdtDef” #37026

Closed
Rufflewind opened this issue Oct 7, 2016 · 7 comments · Fixed by #37095
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Rufflewind
Copy link
Contributor

Rufflewind commented Oct 7, 2016

I was trying an if let pattern match for a nullary constructor like this:

if let Some(::router::NoRoute) = err.error.downcast() {}

but the compiler choked on the pattern match in an unexpected way. The fact that it's qualified does not seem to matter. See minimal repro below.


I tried this code:

extern crate router;
fn test() {
    let router::NoRoute = (); // NoRoute is an empty struct in “router”
}

I expected to see this happen:

An plain, ordinary, not-scary type error.

Instead, this happened:

error: internal compiler error: src/librustc/ty/context.rs:604: Tried to overwrite interned AdtDef: router::NoRoute

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

Meta

rustc --version --verbose:

rustc 1.12.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.12.0

Backtrace:

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:634
stack backtrace:
   1:     0x7f3f96d52cd9 - std::sys::backtrace::tracing::imp::write::h00e948915d1e4c72
   2:     0x7f3f96d6351c - std::panicking::default_hook::_{{closure}}::h7b8a142818383fb8
   3:     0x7f3f96d61914 - std::panicking::default_hook::h41cf296f654245d7
   4:     0x7f3f96d62078 - std::panicking::rust_panic_with_hook::h4cbd7ca63ce1aee9
   5:     0x7f3f906c7747 - std::panicking::begin_panic::hd3e81d866d6c5b0a
   6:     0x7f3f906d8325 - rustc_errors::Handler::bug::h60f29cdeff67c1a3
   7:     0x7f3f93fe74e4 - rustc::session::opt_span_bug_fmt::_{{closure}}::ha1319a72e07cd73b
   8:     0x7f3f93f289d5 - rustc::session::opt_span_bug_fmt::h4badbc71bfeea6f9
   9:     0x7f3f93f28812 - rustc::session::bug_fmt::he780dcb9e1e8a7d5
  10:     0x7f3f93f9eabc - rustc::ty::context::TyCtxt::insert_adt_def::hf29e70e1fbb3e0ab
  11:     0x7f3f9464b4f5 - rustc_metadata::decoder::get_adt_def::h78248c8ed76d9698
  12:     0x7f3f9466a294 - rustc_metadata::csearch::_<impl rustc..middle..cstore..CrateStore<'tcx> for rustc_metadata..cstore..CStore>::adt_def::h9010a99ee3288f01
  13:     0x7f3f93fc9477 - rustc::ty::_<impl rustc..ty..context..TyCtxt<'a, 'gcx, 'tcx>>::lookup_adt_def_master::h9f53a256095087eb
  14:     0x7f3f93fc9985 - rustc::ty::_<impl rustc..ty..context..TyCtxt<'a, 'gcx, 'tcx>>::lookup_adt_def::h4a8f88c8263367bd
  15:     0x7f3f9462afd9 - rustc_metadata::tydecode::TyDecoder::parse_ty::h2699ee85579ac86e
  16:     0x7f3f9462a8a0 - rustc_metadata::tydecode::TyDecoder::parse_ty::h2699ee85579ac86e
  17:     0x7f3f9464c48d - rustc_metadata::decoder::get_type::h6f6b706ba668663d
  18:     0x7f3f94669f3f - rustc_metadata::csearch::_<impl rustc..middle..cstore..CrateStore<'tcx> for rustc_metadata..cstore..CStore>::item_type::h503a61f838833975
  19:     0x7f3f93fc80fd - rustc::ty::_<impl rustc..ty..context..TyCtxt<'a, 'gcx, 'tcx>>::lookup_item_type::h32494593dee57ed3
  20:     0x7f3f9535f985 - rustc_typeck::check::_match::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::check_pat::hb595ae90c56692e6
  21:     0x7f3f953feb43 - rustc_typeck::check::FnCtxt::check_decl_local::h3566652c6c4664a1
  22:     0x7f3f953fec7e - rustc_typeck::check::FnCtxt::check_stmt::h012039db8f7fe2ee
  23:     0x7f3f953fefe7 - rustc_typeck::check::FnCtxt::check_block_with_expected::h6457d67c748c48f5
  24:     0x7f3f953cc1a1 - rustc_typeck::check::check_fn::h116c7bc1c461e3a6
  25:     0x7f3f953ca5d5 - rustc_typeck::check::check_bare_fn::haaae113cd154037a
  26:     0x7f3f953ce741 - rustc_typeck::check::check_item_body::h169c2400d0395b3e
  27:     0x7f3f953c7308 - rustc_typeck::check::check_item_bodies::h3f9ccb4bec3365b2
  28:     0x7f3f95448293 - rustc_typeck::check_crate::h5c76faa7ac951c22
  29:     0x7f3f9713da33 - rustc_driver::driver::phase_3_run_analysis_passes::_{{closure}}::he5bb0058670d90b6
  30:     0x7f3f9708e9f8 - rustc::ty::context::TyCtxt::create_and_enter::h1ad8faffb62f0367
  31:     0x7f3f970f70bf - rustc_driver::driver::compile_input::h4d6bc655b7baad10
  32:     0x7f3f97124016 - rustc_driver::run_compiler::h9165e61fc2dd486f
  33:     0x7f3f9706af82 - std::panicking::try::do_call::hc52dd3bdae996640
  34:     0x7f3f96d6f936 - __rust_maybe_catch_panic
  35:     0x7f3f9708461a - _<F as alloc..boxed..FnBox<A>>::call_box::h3aad53cfb9d2713a
  36:     0x7f3f96d5fc72 - std::sys::thread::Thread::new::thread_start::h4c0ad33b336bc6ea
  37:     0x7f3f8fe6d453 - start_thread
  38:     0x7f3f969a97de - __GI___clone
  39:                0x0 - <unknown>
@Rufflewind Rufflewind changed the title “Let qualified::NullaryConstructor = something;” causes internal compiler error: “tried to overwrite interned AdtDef” “Let NullaryConstructor = something;” causes internal compiler error: “tried to overwrite interned AdtDef” Oct 7, 2016
@apasel422 apasel422 added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Oct 7, 2016
@TimNN TimNN added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 7, 2016
@TimNN
Copy link
Contributor

TimNN commented Oct 7, 2016

Works fine on 1.11.

@TimNN
Copy link
Contributor

TimNN commented Oct 7, 2016

Affects beta as well.

Requires the type on the lhs to come from an extern crate.

This is fixed on nightly-2016-10-06 (nightly-2016-10-04 still fails, Changes)

I suspect this was fixed by #36814 (although I may be wrong).

@TimNN
Copy link
Contributor

TimNN commented Oct 7, 2016

Originally introduced between nightly-2016-07-09 and nightly-2016-07-10 (Changes)

The most likely cause is #34365, I think.

@jseyfried
Copy link
Contributor

cc @petrochenkov

@petrochenkov
Copy link
Contributor

This happens when decoder::get_adt_def gets struct constructor DefId as an argument (as opposed to DefId of the struct itself) + it's the first time this struct is decoded.
#36814 doesn't fix this issue, only masks it, it still can be reproduced with tuple struct patterns.
How to fix this: add something like this at the beginning of decoder::get_adt_def:

if is_ctor_id(item_id) {
    item_id = get_struct_id(item_id)
}

I have no idea how is_ctor_id and get_struct_id can be implemented, need to investigate how new metadata works.

@petrochenkov
Copy link
Contributor

Fix for beta is in #37078

@nikomatsakis
Copy link
Contributor

Nice job @petrochenkov

bors added a commit that referenced this issue Oct 12, 2016
Temporary fix for metadata decoding for struct constructors

Same as #37078, but for nightly.
Ideally, metadata lookup functions should "just work" for constructor ids, but this fixes the issue as well.

Fixes #37026
r? @alexcrichton
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) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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.

7 participants