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 due to failed typecheck (on no_core) #72099

Closed
jaybosamiya opened this issue May 11, 2020 · 3 comments · Fixed by #72170
Closed

Internal compiler error due to failed typecheck (on no_core) #72099

jaybosamiya opened this issue May 11, 2020 · 3 comments · Fixed by #72170
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way.

Comments

@jaybosamiya
Copy link

jaybosamiya commented May 11, 2020

Bad types can lead to an internal compiler error, rather than an error message when compiling. Only affects no_core on nightly.

Code

#![feature(no_core, lang_items)]
#![no_core]

#[lang = "sized"]
trait Sized {}

fn foo() -> bool {
    ()
}

Expected

error[E0308]: mismatched types

Reality

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/librustc_typeck/check/demand.rs:637:35

Meta

rustc --version --verbose:

rustc 1.45.0-nightly (9912925c2 2020-05-10)
binary: rustc
commit-hash: 9912925c254589f58338cb2993163e618475ff75
commit-date: 2020-05-10
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 9.0

Backtrace:

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/librustc_typeck/check/demand.rs:637:35
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
  12: rust_begin_unwind
             at src/libstd/panicking.rs:385
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:89
  14: core::panicking::panic
             at src/libcore/panicking.rs:52
  15: rustc_typeck::check::demand::<impl rustc_typeck::check::FnCtxt>::check_ref
  16: rustc_typeck::check::FnCtxt::suggest_deref_ref_or_into
  17: rustc_typeck::check::demand::<impl rustc_typeck::check::FnCtxt>::emit_coerce_suggestions
  18: rustc_typeck::check::coercion::CoerceMany<E>::coerce_inner
  19: rustc_typeck::check::FnCtxt::check_block_with_expected
  20: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  21: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  22: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  23: rustc_typeck::check::check_fn
  24: rustc_middle::ty::context::GlobalCtxt::enter_local
  25: rustc_typeck::check::typeck_tables_of
  26: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_tables_of>::compute
  27: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  28: rustc_query_system::query::plumbing::get_query_impl
  29: rustc_query_system::query::plumbing::ensure_query_impl
  30: rustc_typeck::check::typeck_item_bodies
  31: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_query_system::query::plumbing::get_query_impl
  34: rustc_typeck::check_crate
  35: rustc_interface::passes::analysis
  36: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  37: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  38: rustc_data_structures::stack::ensure_sufficient_stack
  39: rustc_query_system::query::plumbing::get_query_impl
  40: rustc_middle::ty::context::tls::enter_global
  41: rustc_interface::interface::run_compiler_in_existing_thread_pool
  42: scoped_tls::ScopedKey<T>::set
  43: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.45.0-nightly (9912925c2 2020-05-10) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=1 -C llvm-args=--x86-asm-syntax=intel --crate-type rlib

query stack during panic:
#0 [typeck_tables_of] type-checking `foo`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
@csmoe csmoe added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. labels May 11, 2020
@RalfJung
Copy link
Member

The ICE is caused by a missing lang item:

let deref_trait = self.tcx.lang_items().deref_trait().unwrap();

Perhaps the error isn't great, but generally missing/wrong lang items leading to ICEs is not considered a bug. If you opt-out of the default lang items, it is your responsibility to figure out what to do. There's a reason no_core is unlikely to be stabilized.

@RalfJung
Copy link
Member

That said, probably it would be better to use require_lang_item unstead of unwrap; that should give a nicer error.

Or maybe the diagnostic could be skipped if the deref trait is missing.

@jaybosamiya
Copy link
Author

Thanks for looking into this! I understand that no_core is unlikely to be stabilized and it's the user's job to figure out what to do, but with the suggested fix and PRs, it makes it a much nicer experience for the user, rather than a direct ICE.

Thanks for being a wonderful language, project, and community <3

@bors bors closed this as completed in 62f1840 May 14, 2020
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) ❄️ requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants