Skip to content

ICE - ErrorReporting Overflow should not reach report_selection_err call #92148

Closed
@matheus-consoli

Description

@matheus-consoli

I slipped on ICE while trying to formulate an example of a problem I was showing to some friends. Essentially, I was trying to implement a trait Trait to a Vec<T> where T itself impls Trait. The implementation wasn't done yet, but I ran it anyway, and the compiler panicked during the error report with:

error: internal compiler error: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs:855:17: ErrorReporting Overflow should not reach `report_selection_err` call

Code

playground

trait Blah<T> {
    type Output;
    fn foo(t: T) -> Self::Output;
}

impl Blah<i32> for i32 {
    type Output = i64;

    fn foo(t: i32) -> Self::Output {
        t as Self::Output
    }
}

impl<B, F> Blah<Vec<F>> for B
where
    B: Blah<F>,
{
    type Output = Vec<T::Output>;

    fn foo(t: T) -> Self::Output {
        t.into_iter(F::foo).collect()
    }
}

I messed up with the Generics names, note that I even used a type named T that wasn't even declared (my humble guess is that this is the starting point to the overflow).

EDIT2: my guess was wrong! The code is soooo fucked up that even using a declared type the compiles stills panicking

and this also fails

impl<B, T> Blah<Vec<T>> for B
where
    B: Blah<T>,
{
    type Output = Vec<B::Output>;

    fn foo(t: T) -> Self::Output {
        t.into_iter(T::foo).collect()
    }
}

And, just for the sake of completeness, I was trying to implement this.

Meta

Found it both on Stable and Nightly:

Stable

rustc +stable --version --verbose:

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0
Nightly

rustc +nightly --version --verbose:

rustc 1.59.0-nightly (23f69235a 2021-12-20)
binary: rustc
commit-hash: 23f69235ad2eb9b44ac1a55eeaa3f9b484d9de4a
commit-date: 2021-12-20
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0

Error output

$ cargo +stable c
    Checking ice v0.1.0 (/tmp/ice)
error[E0433]: failed to resolve: use of undeclared type `T`
  --> src/main.rs:18:23
   |
18 |     type Output = Vec<T::Output>;
   |                       ^ use of undeclared type `T`

error[E0412]: cannot find type `T` in this scope
  --> src/main.rs:20:15
   |
14 | impl<B, F> Blah<Vec<F>> for B
   |      - similarly named type parameter `B` defined here
...
20 |     fn foo(t: T) -> Self::Output {
   |               ^ help: a type parameter with a similar name exists: `B`

error[E0601]: `main` function not found in crate `ice`
  --> src/main.rs:1:1
   |
1  | / trait Blah<T> {
2  | |     type Output;
3  | |     fn foo(t: T) -> Self::Output;
4  | | }
...  |
22 | |     }
23 | | }
   | |_^ consider adding a `main` function to `src/main.rs`

error: internal compiler error: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs:846:17: ErrorReporting Overflow should not reach `report_selection_err` call

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1146:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.57.0 (f1edd0429 2021-11-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C linker=/usr/bin/clang -C incremental -C link-arg=--ld-path=/usr/bin/mold --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `<impl at src/main.rs:14:1: 23:2>::foo`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
Some errors have detailed explanations: E0412, E0433, E0601.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `ice` due to 3 previous errors
Backtrace

error: internal compiler error: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs:846:17: ErrorReporting Overflow should not reach `report_selection_err` call

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1146:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_selection_error
   8: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
   9: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors
  10: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::resolve_vars_with_obligations
  11: rustc_typeck::check::coercion::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::try_coerce
  12: rustc_typeck::check::demand::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::demand_coerce_diag
  13: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  14: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_method_argument_types
  15: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  17: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  18: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  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_and_args
  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::dep_graph::graph::DepGraph<K>::with_task
  26: rustc_data_structures::stack::ensure_sufficient_stack
  27: rustc_query_system::query::plumbing::try_execute_query
  28: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  29: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  30: rustc_data_structures::sync::par_for_each_in
  31: rustc_typeck::check::typeck_item_bodies
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  33: rustc_data_structures::stack::ensure_sufficient_stack
  34: rustc_query_system::query::plumbing::try_execute_query
  35: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  36: rustc_session::utils::<impl rustc_session::session::Session>::time
  37: rustc_typeck::check_crate
  38: rustc_interface::passes::analysis
  39: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  40: rustc_data_structures::stack::ensure_sufficient_stack
  41: rustc_query_system::query::plumbing::try_execute_query
  42: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  43: rustc_interface::passes::QueryContext::enter
  44: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  45: rustc_span::with_source_map
  46: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.57.0 (f1edd0429 2021-11-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C linker=/usr/bin/clang -C incremental -C link-arg=--ld-path=/usr/bin/mold --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `<impl at src/main.rs:14:1: 23:2>::foo`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
Some errors have detailed explanations: E0412, E0433, E0601.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `ice` due to 3 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions