rust-lang / rust

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

Crash on const expr overflow followed by display #84178

Closed lgarczyn closed 3 years ago

lgarczyn commented 3 years ago

Code

#![cfg(test)]

#[test]
fn test_nz() {
    const u8:u8 = 40u32.pow(2) as u8;
    dbg!(u8);
}

Meta

note: rustc 1.53.0-nightly (d0695c908 2021-04-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental

Error output

query stack during panic:
#0 [predicates_of] computing predicates of `std::fmt::Display`
#1 [typeck] type-checking `test_nz`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Some(Fingerprint(709981240673635011, 11067457998711857432))`,
 right: `Some(Fingerprint(18243125685095569025, 15011316703844057886))`: found unstable fingerprints for predicates_of(core[ec89]::fmt::Display): GenericPredicates { parent: None, predicates: [(Binder(TraitPredicate(<Self as std::fmt::Display>), []), /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:644:1: 644:18 (#0))] }', /rustc/d0695c9081b16077d0aed368bccaf437d77ff497/compiler/rustc_query_system/src/query/plumbing.rs:593:5
Backtrace

```stack backtrace: 0: rust_begin_unwind at /rustc/d0695c9081b16077d0aed368bccaf437d77ff497/library/std/src/panicking.rs:493:5 1: core::panicking::panic_fmt at /rustc/d0695c9081b16077d0aed368bccaf437d77ff497/library/core/src/panicking.rs:92:14 2: core::panicking::assert_failed_inner 3: core::panicking::assert_failed 4: rustc_query_system::query::plumbing::incremental_verify_ich 5: rustc_query_system::query::plumbing::load_from_disk_and_cache_in_memory 6: rustc_query_system::query::plumbing::get_query_impl 7: ::predicates_of 8: rustc_middle::ty::generics::GenericPredicates::instantiate_into 9: rustc_middle::ty::generics::GenericPredicates::instantiate 10: rustc_typeck::check::fn_ctxt::_impl::::instantiate_bounds 11: rustc_typeck::check::fn_ctxt::_impl::::add_required_obligations 12: rustc_typeck::check::fn_ctxt::_impl::::instantiate_value_path 13: rustc_typeck::check::expr::::check_expr_kind 14: rustc_typeck::check::expr::::check_expr_with_expectation 15: rustc_typeck::check::fn_ctxt::checks::::check_argument_types 16: rustc_typeck::check::callee::::confirm_builtin_call 17: rustc_typeck::check::callee::::check_call 18: rustc_typeck::check::expr::::check_expr_kind 19: rustc_typeck::check::expr::::check_expr_with_expectation 20: rustc_typeck::check::expr::::check_expr_kind 21: rustc_typeck::check::expr::::check_expr_with_expectation 22: rustc_typeck::check::_match::::check_match 23: rustc_typeck::check::expr::::check_expr_kind 24: rustc_typeck::check::expr::::check_expr_with_expectation 25: rustc_typeck::check::expr::::check_expr_kind 26: rustc_typeck::check::expr::::check_expr_with_expectation 27: rustc_typeck::check::fn_ctxt::checks::::check_argument_types 28: rustc_typeck::check::callee::::confirm_builtin_call 29: rustc_typeck::check::callee::::check_call 30: rustc_typeck::check::expr::::check_expr_kind 31: rustc_typeck::check::expr::::check_expr_with_expectation 32: rustc_typeck::check::fn_ctxt::checks::::check_argument_types 33: rustc_typeck::check::callee::::confirm_builtin_call 34: rustc_typeck::check::callee::::check_call 35: rustc_typeck::check::expr::::check_expr_kind 36: rustc_typeck::check::expr::::check_expr_with_expectation 37: rustc_typeck::check::fn_ctxt::checks::::check_stmt 38: rustc_typeck::check::fn_ctxt::checks::::check_block_with_expected 39: rustc_typeck::check::expr::::check_expr_with_expectation 40: rustc_typeck::check::fn_ctxt::checks::::check_stmt 41: rustc_typeck::check::fn_ctxt::checks::::check_block_with_expected 42: rustc_typeck::check::expr::::check_expr_with_expectation 43: rustc_typeck::check::_match::::check_match 44: rustc_typeck::check::expr::::check_expr_kind 45: rustc_typeck::check::expr::::check_expr_with_expectation 46: rustc_typeck::check::fn_ctxt::checks::::check_stmt 47: rustc_typeck::check::fn_ctxt::checks::::check_block_with_expected 48: rustc_typeck::check::expr::::check_expr_with_expectation 49: rustc_typeck::check::expr::::check_return_expr 50: rustc_typeck::check::check::check_fn 51: rustc_infer::infer::InferCtxtBuilder::enter 52: rustc_typeck::check::typeck 53: rustc_middle::dep_graph::::with_deps 54: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 55: rustc_data_structures::stack::ensure_sufficient_stack 56: rustc_query_system::query::plumbing::force_query_with_job 57: rustc_query_system::query::plumbing::get_query_impl 58: ::typeck 59: rustc_middle::ty::::par_body_owners 60: rustc_typeck::check::typeck_item_bodies 61: rustc_middle::dep_graph::::with_deps 62: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 63: rustc_data_structures::stack::ensure_sufficient_stack 64: rustc_query_system::query::plumbing::force_query_with_job 65: rustc_query_system::query::plumbing::get_query_impl 66: ::typeck_item_bodies 67: rustc_session::utils::::time 68: rustc_typeck::check_crate 69: rustc_interface::passes::analysis 70: rustc_middle::dep_graph::::with_deps 71: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 72: rustc_data_structures::stack::ensure_sufficient_stack 73: rustc_query_system::query::plumbing::force_query_with_job 74: rustc_query_system::query::plumbing::get_query_impl 75: ::analysis 76: rustc_interface::passes::QueryContext::enter 77: rustc_interface::queries::::enter 78: rustc_span::with_source_map 79: rustc_interface::interface::create_compiler_and_run 80: scoped_tls::ScopedKey::set note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ```

osa1 commented 3 years ago

How do I reproduce this? Just building it with cargo +nightly build in a library, or with rustc +nightly test.rs --crate-type=rlib do not generate any errors.

lgarczyn commented 3 years ago

After running rustup default stable then rustup default nightly, the crash has disappeared. I have no more information, sorry.

I was testing out const_panic to try and get casting overflow errors in const expr

lgarczyn commented 3 years ago

Managed to recreate it, it's probably due to my macro library

Here's the full project as it was during the last crash: https://github.com/lgarczyn/polymorphic-constant/tree/rust-crash

To cause the crash simply run cargo test on nightly

wesleywiser commented 3 years ago

Thanks for filing the bug report! We just shipped a patch release to work around this issue and are currently triaging related issues related to ensure each underlying problem gets resolved. Since this appears to be a duplicate of #83259, I'm going to close in favor of that issue.