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 casting a reference to a static closure as usize, inside array length #52432

Closed
DutchGhost opened this issue Jul 16, 2018 · 4 comments · Fixed by #66331
Closed

ICE casting a reference to a static closure as usize, inside array length #52432

DutchGhost opened this issue Jul 16, 2018 · 4 comments · Fixed by #66331
Labels
A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

This issue might be related to #52023 , which has been fixed in #52314

fn main() {
    [(); &(static |x| {}) as *const _ as usize]
}

playground link: https://play.rust-lang.org/?gist=b0d76bcfc33acb632a1527d8a9a97c84&version=nightly&mode=debug&edition=2015

Backtrace:

error[E0697]: closures cannot be static
   --> src\lib.rs:143:16
    |
143 |         [(); &(static |x| {}) as *const _ as usize]
    |                ^^^^^^^^^^

error: internal compiler error: librustc_mir\hair\cx\expr.rs:286: type of & not region
   --> src\lib.rs:143:15
    |
143 |         [(); &(static |x| {}) as *const _ as usize]
    |               ^^^^^^^^^^^^^^^

thread 'main' panicked at 'Box<Any>', librustc_errors\lib.rs:499:9
stack backtrace:
   0: <std::sys::windows::args::Args as core::ops::drop::Drop>::drop
   1: std::error::<impl core::convert::From<alloc::borrow::Cow<'b, str>> for alloc::boxed::Box<(dyn std::error::Error + core::marker::Sync + core::marker::Send + 'a)>>::from
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: <rustc::ty::SymbolName as core::fmt::Display>::fmt
   5: std::panicking::rust_panic_with_hook
   6: <rustc_mir::dataflow::move_paths::indexes::BorrowIndex as rustc_data_structures::indexed_vec::Idx>::new
   7: <rustc_mir::dataflow::graphviz::Edge as core::fmt::Debug>::fmt
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: rustc_mir::dataflow::move_paths::MoveData::gather_moves
  15: rustc_mir::hair::cx::expr::<impl rustc_mir::hair::Mirror<'tcx> for &'tcx rustc::hir::Expr>::make_mirror
  16: <rustc_mir::hair::ExprRef<'tcx> as rustc_mir::hair::Mirror<'tcx>>::make_mirror
  17: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  18: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  19: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  20: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  21: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  22: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  23: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  24: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  25: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  26: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  27: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  28: <rustc_mir::build::GlobalizeMir<'a, 'gcx> as rustc::mir::visit::MutVisitor<'tcx>>::visit_substs
  29: <unknown>
  30: <rustc_mir::interpret::eval_context::ValTy<'tcx> as core::fmt::Debug>::fmt
  31: rustc_mir::build::mir_build
  32: rustc_mir::transform::mir_built
  33: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  34: rustc::ty::context::tls::track_diagnostic
  35: rustc::ty::context::tls::track_diagnostic
  36: rustc::dep_graph::graph::DepGraph::assert_ignored
  37: rustc::ty::context::tls::track_diagnostic
  38: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  40: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_built
  41: <rustc_mir::transform::check_unsafety::UnusedUnsafeVisitor<'a> as rustc::hir::intravisit::Visitor<'tcx>>::visit_block
  42: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  43: rustc::ty::context::tls::track_diagnostic
  44: rustc::ty::context::tls::track_diagnostic
  45: rustc::dep_graph::graph::DepGraph::assert_ignored
  46: rustc::ty::context::tls::track_diagnostic
  47: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  48: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  49: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::unsafety_check_result
  50: rustc_mir::transform::mir_const
  51: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  52: rustc::ty::context::tls::track_diagnostic
  53: rustc::ty::context::tls::track_diagnostic
  54: rustc::dep_graph::graph::DepGraph::assert_ignored
  55: rustc::ty::context::tls::track_diagnostic
  56: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  57: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  58: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_const
  59: rustc_mir::transform::qualify_consts::provide
  60: rustc::ty::context::tls::track_diagnostic
  61: rustc::ty::context::tls::track_diagnostic
  62: rustc::dep_graph::graph::DepGraph::assert_ignored
  63: rustc::ty::context::tls::track_diagnostic
  64: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  65: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  66: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_const_qualif
  67: rustc_mir::interpret::const_eval::const_eval_provider
  68: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  69: rustc::ty::context::tls::track_diagnostic
  70: rustc::ty::context::tls::track_diagnostic
  71: rustc::dep_graph::graph::DepGraph::assert_ignored
  72: rustc::ty::context::tls::track_diagnostic
  73: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  74: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  75: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::const_eval
  76: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  77: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  78: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  79: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  80: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  81: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  82: <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_pat
  83: <rustc_typeck::collect::has_late_bound_regions::LateBoundRegionsDetector<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_lifetime
  84: <rustc_typeck::check::method::probe::ProbeScope as core::fmt::Debug>::fmt
  85: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  86: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  87: rustc::ty::context::tls::track_diagnostic
  88: rustc::ty::context::tls::track_diagnostic
  89: rustc::dep_graph::graph::DepGraph::assert_ignored
  90: rustc::ty::context::tls::track_diagnostic
  91: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  92: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  93: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  94: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  95: rustc::ty::context::tls::track_diagnostic
  96: rustc::ty::context::tls::track_diagnostic
  97: rustc::dep_graph::graph::DepGraph::assert_ignored
  98: rustc::ty::context::tls::track_diagnostic
  99: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
query stack during panic:
#0 [mir_built] processing `internal_compiler_errors::type_not_region::{{constant}}`
#1 [unsafety_check_result] processing `internal_compiler_errors::type_not_region::{{constant}}`
#2 [mir_const] processing `internal_compiler_errors::type_not_region::{{constant}}`
#3 [mir_const_qualif] processing `internal_compiler_errors::type_not_region::{{constant}}`
#4 [const_eval] const-evaluating `internal_compiler_errors::type_not_region::{{constant}}`
#5 [typeck_tables_of] processing `internal_compiler_errors::type_not_region`
#6 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to 2 previous errors

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

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.29.0-nightly (31f1bc7b4 2018-07-15) 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`.
@DutchGhost
Copy link
Contributor Author

removing the argument inside the closure gives a different ICE. Interestingly stable refuses to compile this, but beta and nightly ICE's

fn main() {
    [(); &(static || {}) as *const _ as usize]
}

playground: https://play.rust-lang.org/?gist=e21e79c33b6428a56c0bb07df6f0a950&version=nightly&mode=debug&edition=2015

Backtrace:

error[E0697]: closures cannot be static
   --> src\lib.rs:154:16
    |
154 |         [(); &(static || {}) as *const _ as usize]
    |                ^^^^^^^^^

error[E0018]: raw pointers cannot be cast to integers in constants
   --> src\lib.rs:154:14
    |
154 |         [(); &(static || {}) as *const _ as usize]
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: librustc\ty\sty.rs:2008: expected constant usize, got Const {
    ty: usize,
    val: Scalar(
        Ptr(
            Pointer {
                alloc_id: AllocId(
                    1
                ),
                offset: Size {
                    raw: 0
                }
            }
        )
    )
}

thread 'main' panicked at 'Box<Any>', librustc_errors\lib.rs:554:9
stack backtrace:
   0: <std::sys::windows::args::Args as core::ops::drop::Drop>::drop
   1: std::error::<impl core::convert::From<alloc::borrow::Cow<'b, str>> for alloc::boxed::Box<(dyn std::error::Error + core::marker::Sync + core::marker::Send + 'a)>>::from
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: <rustc::ty::SymbolName as core::fmt::Display>::fmt
   5: std::panicking::rust_panic_with_hook
   6: <rustc_errors::emitter::ColorConfig as core::fmt::Debug>::fmt
   7: rustc_errors::Handler::bug
   8: rustc::session::config::Externs::new
   9: rustc::ty::context::tls::track_diagnostic
  10: rustc::ty::context::tls::track_diagnostic
  11: rustc::ty::context::tls::track_diagnostic
  12: rustc::session::bug_fmt
  13: rustc::session::bug_fmt
  14: rustc::ty::context::tls::track_diagnostic
  15: rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::sty::TraitRef<'tcx>>::fmt
  16: <rustc::util::common::ErrorReported as core::fmt::Debug>::fmt
  17: core::fmt::write
  18: alloc::fmt::format
  19: rustc::infer::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::report_region_errors
  20: rustc::infer::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::report_and_explain_type_error
  21: rustc::infer::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::note_type_err
  22: rustc::infer::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::report_and_explain_type_error
  23: rustc::infer::InferCtxt::report_mismatched_types
  24: <rustc_typeck::coherence::orphan::OrphanChecker<'cx, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_impl_item
  25: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  26: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  27: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  28: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  29: <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_pat
  30: <rustc_typeck::collect::has_late_bound_regions::LateBoundRegionsDetector<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_lifetime
  31: <rustc_typeck::check::method::probe::ProbeScope as core::fmt::Debug>::fmt
  32: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  33: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  34: rustc::ty::context::tls::track_diagnostic
  35: rustc::ty::context::tls::track_diagnostic
  36: rustc::dep_graph::graph::DepGraph::assert_ignored
  37: rustc::ty::context::tls::track_diagnostic
  38: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  41: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  42: rustc::ty::context::tls::track_diagnostic
  43: rustc::ty::context::tls::track_diagnostic
  44: rustc::dep_graph::graph::DepGraph::assert_ignored
  45: rustc::ty::context::tls::track_diagnostic
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  47: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  48: rustc_typeck::check_crate
  49: <unknown>
  50: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_impl_item
  51: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  52: rustc_driver::driver::compile_input
  53: rustc_driver::run_compiler
  54: rustc_driver::target_features::add_configuration
  55: <unknown>
  56: _rust_maybe_catch_panic
  57: rustc_driver::profile::dump
  58: rustc_driver::main
  59: <unknown>
  60: std::panicking::update_panic_count
  61: _rust_maybe_catch_panic
  62: std::rt::lang_start_internal
  63: <unknown>
  64: <unknown>
  65: BaseThreadInitThunk
  66: RtlUserThreadStart
query stack during panic:
#0 [typeck_tables_of] processing `internal_compiler_errors::expected_const_got`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to 3 previous errors

Some errors occurred: E0018, E0697.
For more information about an error, try `rustc --explain E0018`.

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.29.0-nightly (31f1bc7b4 2018-07-15) 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`.

@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jul 16, 2018
@DutchGhost
Copy link
Contributor Author

UPDATE:

fn main() {
    [(); &(static || {}) as *const _ as usize]
}

now also ICE's in stable.

@DutchGhost
Copy link
Contributor Author

DutchGhost commented Jul 25, 2019

UPDATE:

fn main() {
    [(); &(static || {}) as *const _ as usize]
}

now also ICE's in stable.

Now no longer ICE's since 1.32.

@jonas-schievink jonas-schievink added A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2019
@JohnTitor
Copy link
Member

The ICE doesn't appear on the latest nightly via the above playground link, marked as E-needstest

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 15, 2019
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 13, 2019
Add some tests for fixed ICEs

Closes rust-lang#30904 (fixed between nightly-2019-07-14 and nightly-2019-07-31)
Closes rust-lang#40231 (example 1 is fixed in 1.32.0, example 2 is fixed in 1.38.0)
Closes rust-lang#52432 (fixed in rustc 1.40.0-beta.1 (76b4053 2019-11-05))
Closes rust-lang#63279 (fixed in rustc 1.40.0-nightly (246be7e 2019-10-25))

r? @Centril
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 13, 2019
Add some tests for fixed ICEs

Closes rust-lang#30904 (fixed between nightly-2019-07-14 and nightly-2019-07-31)
Closes rust-lang#40231 (example 1 is fixed in 1.32.0, example 2 is fixed in 1.38.0)
Closes rust-lang#52432 (fixed in rustc 1.40.0-beta.1 (76b4053 2019-11-05))
Closes rust-lang#63279 (fixed in rustc 1.40.0-nightly (246be7e 2019-10-25))

r? @Centril
@bors bors closed this as completed in 5683fe5 Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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.

4 participants