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: 'assertion failed: num_missing_args > 0', compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs:234:17 #87718

Closed
memoryruins opened this issue Aug 3, 2021 · 0 comments · Fixed by #87727
Labels
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.

Comments

@memoryruins
Copy link
Contributor

memoryruins commented Aug 3, 2021

Code

Experimenting with #83701, the following compiles without an issue:

#![feature(explicit_generic_args_with_impl_trait)]

fn f<T: ?Sized>(_: impl AsRef<T>) {}
fn g<T: ?Sized, U: ?Sized>(_: impl AsRef<T>, _: impl AsRef<U>) {}

fn main() {
    f::<[u8]>("a");
    f::<[u8]>(b"a");
    g::<[u8], [u8]>("a", b"a");
}

But with multiple APIT using the same type parameter, ICEs occur:

#![feature(explicit_generic_args_with_impl_trait)]

fn f<T: ?Sized>(_: impl AsRef<T>, _: impl AsRef<T>) {}

fn main() {
    f::<[u8]>("a", b"a");
}

playground

rustc --version:

rustc 1.56.0-nightly (e3b1c12be 2021-08-02)

Error output

The two separate panic messages:

thread 'rustc' panicked at 'assertion failed: num_missing_args > 0', compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs:234:17
thread 'rustc' panicked at 'no warnings or errors encountered even though `delayed_good_path_bugs` issued', 
Backtrace

   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'assertion failed: num_missing_args > 0', compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs:234:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.56.0-nightly (e3b1c12be 2021-08-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `main`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: internal compiler error: trimmed_def_paths constructed
  |
  = note: delayed at    0: rustc_errors::Handler::delay_good_path_bug
             1: rustc_middle::ty::print::pretty::trimmed_def_paths
             2: rustc_data_structures::stack::ensure_sufficient_stack
             3: rustc_query_system::query::plumbing::get_query_impl
             4: rustc_query_system::query::plumbing::get_query
             5: <rustc_middle::ty::print::pretty::FmtPrinter<F> as rustc_middle::ty::print::Printer>::print_def_path
             6: rustc_middle::ty::print::pretty::<impl rustc_middle::ty::context::TyCtxt>::def_path_str_with_substs
             7: rustc_middle::ty::print::pretty::<impl rustc_middle::ty::context::TyCtxt>::def_path_str
             8: <rustc_typeck::structured_errors::wrong_number_of_generic_args::WrongNumberOfGenericArgs as rustc_typeck::structured_errors::StructuredDiagnostic>::diagnostic_common
             9: rustc_typeck::structured_errors::StructuredDiagnostic::diagnostic
            10: rustc_typeck::astconv::generics::<impl dyn rustc_typeck::astconv::AstConv>::check_generic_arg_count
            11: rustc_typeck::astconv::generics::<impl dyn rustc_typeck::astconv::AstConv>::check_generic_arg_count_for_call
            12: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::instantiate_value_path
            13: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
            14: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
            15: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
            16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
            17: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
            18: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
            19: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
            20: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
            21: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
            22: rustc_typeck::check::check::check_fn
            23: rustc_infer::infer::InferCtxtBuilder::enter
            24: rustc_typeck::check::typeck
            25: rustc_query_system::query::plumbing::get_query_impl
            26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
            27: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
            28: rustc_typeck::check::typeck_item_bodies
            29: rustc_query_system::query::plumbing::get_query_impl
            30: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
            31: rustc_session::utils::<impl rustc_session::session::Session>::time
            32: rustc_typeck::check_crate
            33: rustc_interface::passes::analysis
            34: rustc_query_system::query::plumbing::get_query_impl
            35: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
            36: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
            37: rustc_span::with_source_map
            38: rustc_interface::interface::create_compiler_and_run
            39: scoped_tls::ScopedKey<T>::set
            40: std::sys_common::backtrace::__rust_begin_short_backtrace
            41: core::ops::function::FnOnce::call_once{{vtable.shim}}
            42: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/alloc/src/boxed.rs:1572:9
            43: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/alloc/src/boxed.rs:1572:9
            44: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/sys/unix/thread.rs:91:17
            45: start_thread
            46: clone
          

thread 'rustc' panicked at 'no warnings or errors encountered even though `delayed_good_path_bugs` issued', compiler/rustc_errors/src/lib.rs:1050:13
stack backtrace:
   0:     0x7fea31f246e0 - std::backtrace_rs::backtrace::libunwind::trace::h820df6e5a36600f2
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7fea31f246e0 - std::backtrace_rs::backtrace::trace_unsynchronized::h08422e102b839b36
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fea31f246e0 - std::sys_common::backtrace::_print_fmt::h57fa141da5c1d78f
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fea31f246e0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he771973a791a4e00
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7fea31f927bc - core::fmt::write::h9a6d9c74526a6c1b
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/core/src/fmt/mod.rs:1117:17
   5:     0x7fea31f15f25 - std::io::Write::write_fmt::h9d3df603db3c3ca4
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/io/mod.rs:1667:15
   6:     0x7fea31f27d2b - std::sys_common::backtrace::_print::ha158db1ea88125c4
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7fea31f27d2b - std::sys_common::backtrace::print::h342dde07e263fe00
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7fea31f27d2b - std::panicking::default_hook::{{closure}}::h642e95a669718f6e
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/panicking.rs:208:50
   9:     0x7fea31f278a0 - std::panicking::default_hook::hc5055134d92c4284
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/panicking.rs:225:9
  10:     0x7fea32705d41 - rustc_driver::DEFAULT_HOOK::{{closure}}::{{closure}}::haff05a7eace0faae
  11:     0x7fea31f28559 - std::panicking::rust_panic_with_hook::h6f45f3f96085621d
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/panicking.rs:627:17
  12:     0x7fea31f28017 - std::panicking::begin_panic_handler::{{closure}}::h8cc693a35602cb15
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/panicking.rs:520:13
  13:     0x7fea31f24bcc - std::sys_common::backtrace::__rust_end_short_backtrace::h89bf48eb2468d1e3
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7fea31f27f79 - rust_begin_unwind
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/panicking.rs:516:5
  15:     0x7fea31ef15cb - std::panicking::begin_panic_fmt::h7b704e109b8f89ba
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/panicking.rs:458:5
  16:     0x7fea34b51a59 - rustc_errors::HandlerInner::flush_delayed::h1214dd69c94464a0
  17:     0x7fea34b50531 - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h99b093f7064b7696
  18:     0x7fea34207a96 - core::ptr::drop_in_place<rustc_session::parse::ParseSess>::hf782bb3707a77e2d
  19:     0x7fea3420980e - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h30c9788e90bfa607
  20:     0x7fea341ddd1d - core::ptr::drop_in_place<rustc_interface::interface::Compiler>::h04cee182ac6141b7
  21:     0x7fea341dd73c - rustc_span::with_source_map::h8044517cb42f9e14
  22:     0x7fea341ef1ea - rustc_interface::interface::create_compiler_and_run::h600b31664ea7498c
  23:     0x7fea341e1349 - scoped_tls::ScopedKey<T>::set::h67b78cee48afc23b
  24:     0x7fea341dd85a - std::sys_common::backtrace::__rust_begin_short_backtrace::h7d4575ab5f030af1
  25:     0x7fea341dcb95 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h0e7f7efed8d1ac6c
  26:     0x7fea31f351c7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he2a466339cf4c9af
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/alloc/src/boxed.rs:1572:9
  27:     0x7fea31f351c7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1f2d848478877ebe
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/alloc/src/boxed.rs:1572:9
  28:     0x7fea31f351c7 - std::sys::unix::thread::Thread::new::thread_start::h12773e412063ea14
                               at /rustc/e3b1c12becebd21d88ca9f4364d7db8d1d380c18/library/std/src/sys/unix/thread.rs:91:17
  29:     0x7fea31e6e609 - start_thread
  30:     0x7fea31d82293 - clone
  31:                0x0 - <unknown>

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.56.0-nightly (e3b1c12be 2021-08-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

query stack during panic:
end of query stack
thread panicked while panicking. aborting.
error: could not compile `playground`

@memoryruins memoryruins 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 Aug 3, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 6, 2021
explicit_generic_args_with_impl_trait: fix min expected number of generics

Fixes rust-lang#87718

The problem was that `synth_type_param_count` was already subtracted from `named_type_param_count`, so this ended up being subtracted again. This caused `expected_min` to overflow, and ultimately resulting in weird and wrong behaviour.

I've also added another test not present in the original issue but caused by the same bug.
@bors bors closed this as completed in 5b43960 Aug 6, 2021
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. 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.

1 participant