Skip to content

ICE: error performing ParamEnvAnd { ... } possibly related to (lack of) HRTBs in closures #124440

Description

@Carnagion

Credits to @kvverti for finding the following ICE while experimenting with some of my code that was producing HRTB-related errors.

Code

#![allow(warnings)]

trait Foo {}

impl<F> Foo for F where F: FnMut(&()) {}

struct Bar<F> {
    f: F,
}

impl<F> Foo for Bar<F> where F: Foo {}

fn assert_foo<F>(_: F)
where
    Bar<F>: Foo,
{
}

fn main() {
    assert_foo(|_| ());
}

Meta

rustc --version --verbose:

rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: x86_64-pc-windows-msvc
release: 1.77.2
LLVM version: 17.0.6

Error output

Command: cargo build

note: no errors encountered even though `span_delayed_bug` issued

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: TraitPredicate(<Bar<{closure@src\main.rs:20:16: 20:19}> as Foo>, polarity:Positive), bound_vars: [] } } }
  --> src\main.rs:20:5
   |
20 |     assert_foo(|_| ());
   |     ^^^^^^^^^^^^^^^^^^
   |
note: delayed at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\compiler\rustc_trait_selection\src\traits\query\type_op\mod.rs:164:29 - disabled backtrace    
  --> src\main.rs:20:5
   |
20 |     assert_foo(|_| ());
   |     ^^^^^^^^^^^^^^^^^^

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.77.2 (25ef9e3d8 2024-04-09) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
end of query stack
error: could not compile `rustc-ice-mre` (bin "rustc-ice-mre")
Backtrace

note: no errors encountered even though `span_delayed_bug` issued

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: TraitPredicate(<Bar<{closure@src\main.rs:20:16: 20:19}> as Foo>, polarity:Positive), bound_vars: [] } } }
  --> src\main.rs:20:5
   |
20 |     assert_foo(|_| ());
   |     ^^^^^^^^^^^^^^^^^^
   |
note: delayed at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\compiler\rustc_trait_selection\src\traits\query\type_op\mod.rs:164:29
         0: std::backtrace::Backtrace::force_capture
         1: std::backtrace::Backtrace::capture
         2: <rustc_errors::DiagCtxt>::flush_delayed
         3: <rustc_errors::DiagCtxt>::emit_diagnostic
         4: <rustc_errors::diagnostic::Diagnostic as core::cmp::PartialEq>::eq
         5: <rustc_borrowck::type_check::liveness::local_use_map::LocalUseMapBuild as rustc_middle::mir::visit::Visitor>::visit_local
         6: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
         7: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_constant
         8: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
         9: <rustc_borrowck::type_check::relate_tys::NllTypeRelatingDelegate as rustc_infer::infer::relate::nll::TypeRelatingDelegate>::push_outlives
        10: <rustc_borrowck::member_constraints::MemberConstraintSet<rustc_middle::ty::sty::RegionVid> as core::default::Default>::default
        11: <rustc_borrowck::MirBorrowckCtxt>::consume_operand
        12: rustc_borrowck::mir_borrowck
        13: <rustc_query_impl::plumbing::QueryCtxt as rustc_query_system::query::QueryContext>::load_side_effects
        14: rustc_query_impl::query_callbacks
        15: <rustc_query_impl::plumbing::QueryCtxt as rustc_query_system::query::QueryContext>::load_side_effects
        16: <rustc_query_impl::plumbing::QueryCtxt as rustc_query_system::query::QueryContext>::load_side_effects
        17: rustc_interface::proc_macro_decls::proc_macro_decls_static
        18: <time::date_time::DateTime<time::date_time::offset_kind::Fixed> as core::convert::From<std::time::SystemTime>>::from
        19: rustc_interface::passes::analysis
        20: rustc_query_impl::profiling_support::alloc_self_profile_query_strings
        21: rustc_query_impl::profiling_support::alloc_self_profile_query_strings
        22: rustc_query_impl::profiling_support::alloc_self_profile_query_strings
        23: rustc_query_impl::profiling_support::alloc_self_profile_query_strings
        24: rustc_query_impl::profiling_support::alloc_self_profile_query_strings
        25: rustc_driver_impl::args::arg_expand_all
        26: rustc_driver_impl::args::arg_expand_all
        27: <rustc_middle::ty::SymbolName as core::fmt::Debug>::fmt
        28: <rustc_middle::ty::SymbolName as core::fmt::Debug>::fmt
        29: <rustc_middle::ty::SymbolName as core::fmt::Debug>::fmt
        30: std::sys::pal::windows::thread::Thread::new
        31: BaseThreadInitThunk
        32: RtlUserThreadStart
  --> src\main.rs:20:5
   |
20 |     assert_foo(|_| ());
   |     ^^^^^^^^^^^^^^^^^^

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.77.2 (25ef9e3d8 2024-04-09) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
end of query stack
error: could not compile `rustc-ice-mre` (bin "rustc-ice-mre")

Notes

The code compiles successfully if the closure is explicitly typed like so:

assert_foo(|_: &()| ()); // OK

Or if an identify function is used like so:

fn id<F: FnMut(&())>(f: F) -> F { f }

assert_foo(id(|_| ())); // OK

My original code produces an error (not ICE) that seems to be a diagnostics bug, complaining about trait bounds not being satisfied when it should really state something along the lines of implementation of FnMut is not general enough.
An MRE is provided below.

Original code and error

trait Foo {}

impl<F> Foo for F where F: FnMut(&()) {}

struct Bar<F> {
    f: F,
}

impl<F> Foo for Bar<F> where F: Foo {}

fn main() -> impl Foo {
    Bar { f: (|a| ()) }
}
error[E0277]: the trait bound `Bar<{closure@src\main.rs:12:15: 12:18}>: Foo` is not satisfied
  --> src\main.rs:11:14
   |
11 | fn main() -> impl Foo {
   |              ^^^^^^^^ the trait `Foo` is not implemented for `Bar<{closure@src\main.rs:12:15: 12:18}>`
   |
   = help: the trait `Foo` is implemented for `Bar<{closure@src\main.rs:12:15: 12:18}>`

error[E0277]: `main` has invalid return type `impl Foo`
  --> src\main.rs:11:14
   |
11 | fn main() -> impl Foo {
   |              ^^^^^^^^ `main` can only return types that implement `Termination`
   |
   = help: consider using `()`, or a `Result`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `rustc-ice-mre` (bin "rustc-ice-mre") due to 2 previous errors

Activity

  1. added
    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.
    on Apr 27, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 27, 2024
  3. Infectious-Smile commented on Apr 27, 2024

    @Infectious-Smile
  4. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on May 9, 2024
  5. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on May 9, 2024
  6. fmease commented on Sep 24, 2024

    @fmease
    Member

    The next-gen trait solver currently fails with:

    error[E0277]: the trait bound `Bar<{closure@qq.rs:22:16: 22:19}>: Foo` is not satisfied
      --> qq.rs:22:16
       |
    22 |     assert_foo(|_| ());
       |     ---------- ^^^^^^ the trait `Foo` is not implemented for `Bar<{closure@qq.rs:22:16: 22:19}>`
       |     |
       |     required by a bound introduced by this call
       |
       = help: the trait `Foo` is implemented for `Bar<F>`
    note: required by a bound in `assert_foo`
      --> qq.rs:17:13
       |
    15 | fn assert_foo<F>(_: F)
       |    ---------- required by a bound in this function
    16 | where
    17 |     Bar<F>: Foo,
       |             ^^^ required by this bound in `assert_foo`
    

    Meaning it doesn't ICE.

  7. added
    A-closuresArea: Closures (`|…| { … }`)
    fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.
    A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)
    on Sep 24, 2024
  8. added 2 commits that reference this issue on Oct 5, 2026
  9. added a commit that references this issue on Oct 5, 2026
  10. added 3 commits that reference this issue on Oct 7, 2026
  11. added a commit that references this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions