-
Notifications
You must be signed in to change notification settings - Fork 13.3k
ICE: encountered type variable
(2)
#140443
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
Comments
I would like to add that, for the code #[test]
fn main() {
fn take_and_return_any<F>(any: F) -> F {
any
}
let _closure_back = take_and_return_any(|arg| println!("{arg}"));
} compiler gives the error
The code above has the trait I would expect the compiler to produce similar output ("annotations needed" error) for the code in the original issue, or ideally, infer the type from |
Very slightly smaller: #![feature(unboxed_closures)]
trait Acceptable<Args> {}
impl<F> Acceptable<(f64,)> for F where F: Fn<(f64,)> {}
fn take_and_return_acceptable_closure<F, Args>(closure: F) -> F
where F: Acceptable<Args>, {
closure
}
fn main() {
// ICE
let _closure_back = take_and_return_acceptable_closure(|arg| true);
} Bisection:
Not sure how to pinpoint it better, could be either of several PRs there. @rustbot label: +T-types +S-has-mcve |
Probably #124902 |
Closing as duplicate since stacktrace, bisection and mvce are basically the same |
May be related: #131758
Context
I am trying to write a library, with an API that accepts closures of different calling signatures, such that the types of arguments are automatically deduced. For that, I tried the idea to use a trait
Acceptable
, which is implemented for closures with acceptable signatures, such that compiler can deduce the types of arguments, based on the list of acceptable signatures.I am new to the language, and would appreciate the suggestions to make this report more useful.
Code with error
For argument type annotation in the closure (or call of the closure) with the type other than
f64
, we get the expected compiler error "unsatisfied trait bound".Meta
rustc --version --verbose
:Error output
Backtrace
Contents of
rustc-ice-2025-04-28T15_53_14-386343.txt
:The text was updated successfully, but these errors were encountered: