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

ICE: No kind for cast #52442

Closed
DutchGhost opened this issue Jul 16, 2018 · 2 comments · Fixed by #52568
Closed

ICE: No kind for cast #52442

DutchGhost opened this issue Jul 16, 2018 · 2 comments · Fixed by #52568
Labels
A-const-eval Area: constant evaluation (mir interpretation) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Jul 16, 2018

The following only ICE's on stable, beta and nightly:

fn main() {
    let f = [();  { &loop { break } as *const _ as usize } ];
}

playground: https://play.rust-lang.org/?gist=b35ac8a560e0cc448e95e2a62598208a&version=stable&mode=release&edition=2015
Backtrace (stable):

error[E0019]: constant contains unimplemented expression type
   --> src\lib.rs:164:26
    |
164 |         let f = [();  { &loop { break } as *const _ as usize } ];
    |                          ^^^^^^^^^^^^^^

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: EvalError { kind: a raw memory access tried to access part of a pointer value as raw bytes, backtrace: None }', libcore\result.rs:945:5
stack backtrace:
   0: <u128 as compiler_builtins::int::Int>::min_value
   1: core::alloc::<impl core::alloc::::Opaque>::null_mut
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: rustc::ty::structural_impls::<impl rustc::ty::context::Lift<'tcx> for rustc::middle::const_val::ErrKind<'a>>::lift_to_tcx
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: <rustc::util::common::ProfileQueriesMsg as core::fmt::Debug>::fmt
  10: rustc::ty::maps::on_disk_cache::<impl serialize::serialize::SpecializedDecoder<rustc::ty::maps::on_disk_cache::IntEncodedWithFixedSize> for serialize::opaque::Decoder<'enc>>::specialized_decode
  11: rustc::ty::maps::on_disk_cache::<impl serialize::serialize::SpecializedDecoder<rustc::ty::maps::on_disk_cache::IntEncodedWithFixedSize> for serialize::opaque::Decoder<'enc>>::specialized_decode
  12: <rustc::infer::combine::Generalizer<'cx, 'gcx, 'tcx> as rustc::ty::relate::TypeRelation<'cx, 'gcx, 'tcx>>::tys
  13: rustc::ich::caching_codemap_view::CachingCodemapView::byte_pos_to_line_and_col
  14: <rustc::infer::sub::Sub<'combine, 'infcx, 'gcx, 'tcx> as rustc::ty::relate::TypeRelation<'infcx, 'gcx, 'tcx>>::tys
  15: rustc_typeck::hir_trait_to_predicates
  16: rustc_typeck::hir_trait_to_predicates
  17: <rustc::hir::HirId as rustc_typeck::check::writeback::Locatable>::to_span
  18: rustc_typeck::hir_trait_to_predicates
  19: <unknown>
  20: <unknown>
  21: <unknown>
  22: <rustc_typeck::outlives::implicit_infer::InferVisitor<'cx, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_impl_item
  23: <rustc_typeck::outlives::implicit_infer::InferVisitor<'cx, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_impl_item
  24: <rustc_typeck::outlives::implicit_infer::InferVisitor<'cx, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_impl_item
  25: <rustc_typeck::outlives::implicit_infer::InferVisitor<'cx, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_impl_item
  26: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  27: <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_pat
  28: <rustc_typeck::collect::has_late_bound_regions::LateBoundRegionsDetector<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_lifetime
  29: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  30: rustc::ty::maps::<impl rustc::ty::maps::config::QueryConfig<'tcx> for rustc::ty::maps::queries::typeck_tables_of<'tcx>>::compute
  31: rustc::ty::context::tls::track_diagnostic
  32: rustc::dep_graph::graph::DepGraph::assert_ignored
  33: rustc::ty::context::tls::track_diagnostic
  34: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  35: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  36: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  37: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  38: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  39: rustc::ty::context::tls::track_diagnostic
  40: rustc::dep_graph::graph::DepGraph::assert_ignored
  41: rustc::ty::context::tls::track_diagnostic
  42: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  43: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  44: rustc_typeck::check_crate
  45: <humantime::duration::Error as std::error::Error>::cause
  46: <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt
  47: <unknown>
  48: rustc_driver::driver::compile_input
  49: rustc_driver::run_compiler
  50: rustc_driver::driver::build_output_filenames
  51: <unknown>
  52: rustc_driver::driver::build_output_filenames
  53: _rust_maybe_catch_panic
  54: rustc_driver::profile::trace::write_style
  55: rustc_driver::main
  56: <unknown>
  57: std::panicking::update_panic_count
  58: _rust_maybe_catch_panic
  59: std::rt::lang_start_internal
  60: <unknown>
  61: <unknown>
  62: BaseThreadInitThunk
  63: RtlUserThreadStart
query stack during panic:
#0 [typeck_tables_of] processing `internal_compiler_errors::no_kind_for_cast`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0019`.

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.27.1 (5f2b325f6 2018-07-07) running on x86_64-pc-windows-msvc

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `test_bugs`.

To learn more, run the command again with --verbose.

The backtrace on nightly is verry different:

warning: unreachable expression
   --> src\lib.rs:164:25
    |
164 |         let f = [();  { &loop { break } as *const _ as usize } ];
    |                         ^^^^^^^^^^^^^^^
    |
    = note: #[warn(unreachable_code)] on by default

error: internal compiler error: no kind for cast
   --> src\lib.rs:164:25
    |
164 |         let f = [();  { &loop { break } as *const _ as usize } ];
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `test_bugs`.

To learn more, run the command again with --verbose.
@DutchGhost DutchGhost changed the title No kind for cast ICE: No kind for cast Jul 16, 2018
@estebank estebank added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-const-eval Area: constant evaluation (mir interpretation) labels Jul 16, 2018
@DutchGhost
Copy link
Contributor Author

After some more playing around, I found that break as _ gave the same ICE on nightly, but stable and beta refused to compile:

fn main() {
    
    [(); loop { break as _ } ];
}

@eddyb
Copy link
Member

eddyb commented Jul 18, 2018

v.tcx.sess.delay_span_bug(e.span, "no kind for cast");

bors added a commit that referenced this issue Jul 23, 2018
Fix loop label resolution around constants

And make `delay_span_bug` a little more helpful

r? @varkor

fixes #52442
fixes #52443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants