ICE: `error performing ParamEnvAnd { ... }` possibly related to (lack of) HRTBs in closures
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the minimal example with the listed rustc 1.77.2 toolchain and compare it with the explicitly typed and identity-function variants. The relevant compiler location named in the report is compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs:164; investigate the ParamEnvAnd/ProvePredicate ICE and verify that the original example produces a diagnostic rather than an internal compiler error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100