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

"Attempt to subtract with overflow" in suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path #104287

Closed
jruderman opened this issue Nov 11, 2022 · 1 comment · Fixed by #104467
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. 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

@jruderman
Copy link
Contributor

jruderman commented Nov 11, 2022

Found with a modified fuzz-rustc

Code

ICEs iff the compiler is built with overflow checks:

fn main() {
    let x = not_found;
    simd_gt::<()>(x);
}

Error output

error[E0425]: cannot find value `not_found` in this scope

thread 'rustc' panicked at 'attempt to subtract with overflow', compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs:731:44
Full output with backtrace

error[E0425]: cannot find value `not_found` in this scope
 --> sb.rs:2:13
  |
2 |     let x = not_found;
  |             ^^^^^^^^^ not found in this scope

thread 'rustc' panicked at 'attempt to subtract with overflow', compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs:731:44
stack backtrace:
   0:        0x110572781 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h555cbf84463534a2
   1:        0x1105f5348 - core::fmt::write::h05afe7e253eb9347
   2:        0x11056ad48 - std::io::Write::write_fmt::ha26c40e390be1298
   3:        0x110572572 - std::sys_common::backtrace::print::h117821677ef17b9e
   4:        0x110554ed5 - std::panicking::default_hook::{{closure}}::h674c8e012ebfd956
   5:        0x110554cb7 - std::panicking::default_hook::h28919ad06af0fc69
   6:        0x121165528 - rustc_driver[c1492cbdcce6be28]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x110555596 - std::panicking::rust_panic_with_hook::he4c3c24b75675b6b
   8:        0x110570ec2 - std::panicking::begin_panic_handler::{{closure}}::h03104d95ce06f62e
   9:        0x110570e38 - std::sys_common::backtrace::__rust_end_short_backtrace::h05e95a6bb7546abd
  10:        0x110554fa8 - _rust_begin_unwind
  11:        0x110619073 - core::panicking::panic_fmt::haaf3786c9d08448a
  12:        0x110619147 - core::panicking::panic::h9614480f1ff40688
  13:        0x123ca3aa2 - <rustc_hir_analysis[9ae6f0e694055ae4]::structured_errors::wrong_number_of_generic_args::WrongNumberOfGenericArgs>::suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path
  14:        0x123ca6f60 - <rustc_hir_analysis[9ae6f0e694055ae4]::structured_errors::wrong_number_of_generic_args::WrongNumberOfGenericArgs as rustc_hir_analysis[9ae6f0e694055ae4]::structured_errors::StructuredDiagnostic>::diagnostic_common
  15:        0x123bd9577 - <rustc_hir_analysis[9ae6f0e694055ae4]::structured_errors::wrong_number_of_generic_args::WrongNumberOfGenericArgs as rustc_hir_analysis[9ae6f0e694055ae4]::structured_errors::StructuredDiagnostic>::diagnostic
  16:        0x123c92291 - <dyn rustc_hir_analysis[9ae6f0e694055ae4]::astconv::AstConv>::check_generic_arg_count
  17:        0x123c84c04 - <dyn rustc_hir_analysis[9ae6f0e694055ae4]::astconv::AstConv>::check_generic_arg_count_for_call
  18:        0x123b6e0bf - <rustc_hir_typeck[d48b2033768d742f]::method::confirm::ConfirmContext>::confirm
  19:        0x123a75cfc - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::confirm_method
  20:        0x123a426a8 - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::confirm_builtin_call
  21:        0x123a41829 - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_call
  22:        0x123aa7d2f - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_expr_kind
  23:        0x123a51ae0 - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24:        0x123aa6db4 - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  25:        0x123a6b12d - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_stmt
  26:        0x123afc196 - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::with_breakable_ctxt::<<rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_block_with_expected::{closure#0}, ()>
  27:        0x123a6b3f7 - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_block_with_expected
  28:        0x123aa8111 - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_expr_kind
  29:        0x123a51ae0 - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:        0x123aa6db4 - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  31:        0x123a52e2a - <rustc_hir_typeck[d48b2033768d742f]::fn_ctxt::FnCtxt>::check_return_expr
  32:        0x123ad8ab7 - rustc_hir_typeck[d48b2033768d742f]::check::check_fn
  33:        0x123b5afc8 - <rustc_hir_typeck[d48b2033768d742f]::inherited::InheritedBuilder>::enter::<rustc_hir_typeck[d48b2033768d742f]::typeck_with_fallback<rustc_hir_typeck[d48b2033768d742f]::typeck::{closure#0}>::{closure#0}::{closure#1}, &rustc_middle[9daaf7003dd7fae5]::ty::context::TypeckResults>
  34:        0x1239f4895 - rustc_hir_typeck[d48b2033768d742f]::typeck_with_fallback::<rustc_hir_typeck[d48b2033768d742f]::typeck::{closure#0}>
  35:        0x123b6ca79 - rustc_hir_typeck[d48b2033768d742f]::typeck
  36:        0x124c7c781 - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::try_execute_query::<rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt, rustc_query_system[90a25adb6ac2fb9e]::query::caches::DefaultCache<rustc_span[8c774867ea78c94f]::def_id::LocalDefId, &rustc_middle[9daaf7003dd7fae5]::ty::context::TypeckResults>>
  37:        0x124da08aa - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::get_query::<rustc_query_impl[8e1328d96bec24c1]::queries::typeck, rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt>
  38:        0x124e45caf - <rustc_query_impl[8e1328d96bec24c1]::Queries as rustc_middle[9daaf7003dd7fae5]::ty::query::QueryEngine>::typeck
  39:        0x123b0cdff - <core[d75b6abbf9be9949]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[14290c48d64940a]::sync::par_for_each_in<&[rustc_span[8c774867ea78c94f]::def_id::LocalDefId], <rustc_middle[9daaf7003dd7fae5]::hir::map::Map>::par_body_owners<rustc_hir_typeck[d48b2033768d742f]::typeck_item_bodies::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}> as core[d75b6abbf9be9949]::ops::function::FnOnce<()>>::call_once
  40:        0x123a119c9 - std[edb4f308383f81f7]::panicking::try::<(), core[d75b6abbf9be9949]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[14290c48d64940a]::sync::par_for_each_in<&[rustc_span[8c774867ea78c94f]::def_id::LocalDefId], <rustc_middle[9daaf7003dd7fae5]::hir::map::Map>::par_body_owners<rustc_hir_typeck[d48b2033768d742f]::typeck_item_bodies::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>>
  41:        0x1239ee3b3 - rustc_data_structures[14290c48d64940a]::sync::par_for_each_in::<&[rustc_span[8c774867ea78c94f]::def_id::LocalDefId], <rustc_middle[9daaf7003dd7fae5]::hir::map::Map>::par_body_owners<rustc_hir_typeck[d48b2033768d742f]::typeck_item_bodies::{closure#0}>::{closure#0}>
  42:        0x123b6c8af - rustc_hir_typeck[d48b2033768d742f]::typeck_item_bodies
  43:        0x124ccbc65 - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::try_execute_query::<rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt, rustc_query_system[90a25adb6ac2fb9e]::query::caches::DefaultCache<(), ()>>
  44:        0x124d653e9 - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::get_query::<rustc_query_impl[8e1328d96bec24c1]::queries::typeck_item_bodies, rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt>
  45:        0x124e45647 - <rustc_query_impl[8e1328d96bec24c1]::Queries as rustc_middle[9daaf7003dd7fae5]::ty::query::QueryEngine>::typeck_item_bodies
  46:        0x123c066a8 - <rustc_session[7b13359bdf8db9ac]::session::Session>::time::<(), rustc_hir_analysis[9ae6f0e694055ae4]::check_crate::{closure#7}>
  47:        0x123bf211e - rustc_hir_analysis[9ae6f0e694055ae4]::check_crate
  48:        0x1212769fa - rustc_interface[d27c24a0cff43249]::passes::analysis
  49:        0x124cbfe80 - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::try_execute_query::<rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt, rustc_query_system[90a25adb6ac2fb9e]::query::caches::DefaultCache<(), core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>>
  50:        0x124da0c59 - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::get_query::<rustc_query_impl[8e1328d96bec24c1]::queries::analysis, rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt>
  51:        0x124e21647 - <rustc_query_impl[8e1328d96bec24c1]::Queries as rustc_middle[9daaf7003dd7fae5]::ty::query::QueryEngine>::analysis
  52:        0x1211928a8 - <rustc_interface[d27c24a0cff43249]::passes::QueryContext>::enter::<rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>
  53:        0x121189238 - <rustc_interface[d27c24a0cff43249]::interface::Compiler>::enter::<rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}::{closure#2}, core[d75b6abbf9be9949]::result::Result<core[d75b6abbf9be9949]::option::Option<rustc_interface[d27c24a0cff43249]::queries::Linker>, rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>
  54:        0x1211789fb - rustc_span[8c774867ea78c94f]::with_source_map::<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  55:        0x12119e60a - <scoped_tls[eb29bcc2d94b2b7f]::ScopedKey<rustc_span[8c774867ea78c94f]::SessionGlobals>>::set::<rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>
  56:        0x12115e230 - std[edb4f308383f81f7]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[d27c24a0cff43249]::util::run_in_thread_pool_with_globals<rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>
  57:        0x12117585d - std[edb4f308383f81f7]::panicking::try::<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, core[d75b6abbf9be9949]::panic::unwind_safe::AssertUnwindSafe<<std[edb4f308383f81f7]::thread::Builder>::spawn_unchecked_<rustc_interface[d27c24a0cff43249]::util::run_in_thread_pool_with_globals<rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
  58:        0x121167770 - <<std[edb4f308383f81f7]::thread::Builder>::spawn_unchecked_<rustc_interface[d27c24a0cff43249]::util::run_in_thread_pool_with_globals<rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#1} as core[d75b6abbf9be9949]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  59:        0x11054de0b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7f65ec775065aafc
  60:        0x11054f9ff - std::sys::unix::thread::Thread::new::thread_start::h4513acaf2edb2674
  61:     0x7ff80d84d4e1 - __pthread_start

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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.67.0-dev running on x86_64-apple-darwin

query stack during panic:
#0 [typeck] type-checking `main`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

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

Version

Compiled stage1 from b7b7f27 with overflow-checks = true

config.toml
# Includes one of the default files in src/bootstrap/defaults
profile = "compiler"
changelog-seen = 2

[llvm]
download-ci-llvm = true     # Download a pre-built LLVM?
assertions = true           # LLVM assertions on?

[rust]
incremental = true          # Build rustc with incremental compilation?
debug-assertions = true
overflow-checks = true
@jruderman jruderman added C-bug Category: This is a bug. 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. labels Nov 11, 2022
@compiler-errors compiler-errors added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Nov 13, 2022
@fuzzypixelz
Copy link
Contributor

The code seems to (implicitly) assume that num_trait_generics_except_self <= num_generic_args_supplied_to_trait by doing an std::ops::Sub<usize>.

The code responsible for this is supposed to "just" give a suggestion. I will try to make it silently fail when the above assumption is not upheld, and hopefully have some other part of rustc catch the error.

Please correct me if I'm wrong.

@rustbot claim

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. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. 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.

3 participants