rust-lang / rust

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

ICE: trivial_numeric_casts when using SDL on nightly #42007

Closed andrewhickman closed 7 years ago

andrewhickman commented 7 years ago

Compiling this short snippet causes a compiler panic

extern crate sdl2;

use sdl2::mouse::MouseButton;

enum Input {
    MouseButton(MouseButton),
}

fn main() {}

Compiler version:

PS C:\Users\me\Documents\rust\sdltest> rustc --version --verbose
rustc 1.17.0 (56124baa9 2017-04-24)
binary: rustc
commit-hash: 56124baa9e73f28c0709e59e74783cf234a978cf
commit-date: 2017-04-24
host: x86_64-pc-windows-msvc
release: 1.17.0
LLVM version: 3.9

SDL version was 0.29.0.

Backtrace:

PS C:\Users\me\Documents\rust\sdltest> cargo +nightly build
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling sdl2-sys v0.27.3
   Compiling sdltest v0.1.0 (file:///C:/Users/me/Documents/rust/sdltest)
   Compiling sdl2 v0.29.1
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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'invalid lint-id `trivial_numeric_casts`', src\librustc\lint\context.rs:1322
stack backtrace:
   0: <std::time::SystemTimeError as core::fmt::Display>::fmt
   1: std::panicking::Location::line
   2: std::panicking::Location::line
   3: std::panicking::rust_panic_with_hook
   4: std::panicking::begin_panic_fmt
   5: std::panicking::begin_panic_fmt
   6: <unknown>
   7: rustc_metadata::decoder::<impl rustc_metadata::cstore::CrateMetadata>::item_body_tables
   8: rustc_metadata::cstore_impl::provide
   9: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  10: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  11: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  12: rustc_const_eval::eval::provide
  13: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  14: rustc::ty::maps::TyCtxtAt::const_eval
  15: rustc::ty::layout::Layout::compute_uncached
  16: rustc::ty::util::<impl rustc::ty::TyS<'tcx>>::needs_drop_uncached
  17: <rustc::util::common::Indenter as core::ops::Drop>::drop
  18: rustc::ty::layout::Layout::compute_uncached
  19: <rustc_lint::types::VariantSizeDifferences as rustc::lint::LateLintPass<'a, 'tcx>>::check_item
  20: rustc::lint::context::gather_attrs
  21: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
  22: rustc::lint::context::check_crate
  23: rustc_driver::driver::count_nodes
  24: rustc_driver::driver::count_nodes
  25: rustc_driver::driver::compile_input
  26: rustc_driver::run_compiler
  27: <unknown>
  28: _rust_maybe_catch_panic
  29: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_impl_item
  30: std::sys::imp::thread::Thread::new
  31: BaseThreadInitThunk

error: Could not compile `sdltest`.

To learn more, run the command again with --verbose.
est31 commented 7 years ago

Minimal reproducible example (without sdl2 requirement):

lib.rs of crate "s":

#[repr(u8)]
pub enum E {
    B = 1 as u8,
}

main.rs of crate "t":

extern crate s;

enum I {
    E(s::E),
}

fn main() {}
kennytm commented 7 years ago

No repro on stable (Regression).

The error on this line (<LintId as Decodable>::decode()) is FindLintError::NotFound. The LintStore is actually empty at this point.

The LintStore becomes empty due to check_crate temporarily moving out the LintStore until the end of the function. But walk_crate eventually needs to decode the crate "s", which has an trivial_numeric_casts lint that is not found in the empty LintStore.

Very detailed stack trace when nothing is inlined ``` 7: std::panicking::begin_panic_fmt 8: rustc::lint::context::::decode::{{closure}} 9: rustc::ty::context::tls::with::{{closure}} 10: >::with 11: rustc::ty::context::tls::with 12: rustc::lint::context::::decode 13: core::ops::FnOnce::call_once 14: serialize::serialize::Decoder::read_struct_field 15: ::decode::{{closure}} 16: serialize::serialize::Decoder::read_struct 17: ::decode 18: as serialize::serialize::Decodable>::decode::{{closure}}::{{closure}} 19: serialize::serialize::Decoder::read_seq_elt 20: as serialize::serialize::Decodable>::decode::{{closure}} 21: serialize::serialize::Decoder::read_seq 22: as serialize::serialize::Decodable>::decode 23: serialize::collection_impls::>::decode::{{closure}}::{{closure}} 24: serialize::serialize::Decoder::read_map_elt_val 25: serialize::collection_impls::>::decode::{{closure}} 26: serialize::serialize::Decoder::read_map 27: serialize::collection_impls::>::decode 28: core::ops::FnOnce::call_once 29: serialize::serialize::Decoder::read_struct_field 30: ::decode::{{closure}} 31: serialize::serialize::Decoder::read_struct 32: ::decode 33: core::ops::FnOnce::call_once 34: serialize::serialize::Decoder::read_struct_field 35: as serialize::serialize::Decodable>::decode::{{closure}} 36: serialize::serialize::Decoder::read_struct 37: as serialize::serialize::Decodable>::decode 38: rustc_metadata::decoder::>::decode 39: rustc_metadata::decoder::::item_body_tables 40: rustc_metadata::cstore_impl::provide::typeck_tables_of 41: rustc::ty::maps::>::try_get_with::{{closure}} 42: rustc::ty::maps::>::cycle_check 43: rustc::ty::maps::>::try_get_with 44: rustc::ty::maps::>::try_get 45: rustc::ty::maps::TyCtxtAt::typeck_tables_of 46: rustc::ty::maps::>::typeck_tables_of 47: rustc_const_eval::eval::const_eval 48: rustc::ty::maps::>::try_get_with::{{closure}} 49: rustc::ty::maps::>::cycle_check 50: rustc::ty::maps::>::try_get_with 51: rustc::ty::maps::>::try_get 52: rustc::ty::maps::TyCtxtAt::const_eval 53: rustc::ty::maps::>::const_eval 54: rustc::ty::AdtDef::discriminants::{{closure}} 55: core::ops::impls:: for &'a mut F>::call_once 56: >::map 57: as core::iter::iterator::Iterator>::next 58: rustc::ty::layout::Layout::compute_uncached 59: rustc::ty::util::>::layout 60: rustc::ty::layout::Layout::compute_uncached::{{closure}} 61: core::ops::impls:: for &'a mut F>::call_once 62: >::map 63: as core::iter::iterator::Iterator>::next 64: < as core::iter::traits::FromIterator>>::from_iter::Adapter as core::iter::iterator::Iterator>::next 65: <&'a mut I as core::iter::iterator::Iterator>::next 66: as collections::vec::SpecExtend>::from_iter 67: as core::iter::traits::FromIterator>::from_iter 68: as core::iter::traits::FromIterator>>::from_iter 69: core::iter::iterator::Iterator::collect 70: rustc::ty::layout::Layout::compute_uncached 71: rustc::ty::util::>::layout 72: >::check_item::{{closure}} 73: rustc::infer::InferCtxtBuilder::enter::{{closure}} 74: rustc::ty::context::tls::enter::{{closure}} 75: >::with 76: rustc::ty::context::tls::enter 77: rustc::ty::context::GlobalCtxt::enter_local 78: rustc::infer::InferCtxtBuilder::enter 79: >::check_item 80: as rustc::hir::intravisit::Visitor<'tcx>>::visit_item::{{closure}} 81: rustc::lint::context::LintContext::with_lint_attrs 82: as rustc::hir::intravisit::Visitor<'tcx>>::visit_item 83: rustc::hir::intravisit::Visitor::visit_nested_item 84: rustc::hir::intravisit::walk_mod 85: as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod 86: rustc::hir::intravisit::walk_crate 87: rustc::lint::context::check_crate::{{closure}} 88: rustc::lint::context::LintContext::with_lint_attrs 89: rustc::lint::context::check_crate 90: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::{{closure}} ```