Function monomorphizes to early #141836
Labels
C-bug
Category: This is a bug.
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
Uh oh!
There was an error while loading. Please reload this page.
I am currently trying to put together my own spin (which has probably already been done but eh) on compile time reflection in rust, and since variadic generics don't exist yet, been creating heterogenous struct-based lists. To actually do anything useful with such lists without runtime checking though you need to enforce trait bounds generically, which can (afaik) only be done through bounds on other Types.
When using these Bounds with a user defined struct they perform as expected (see below), when using them with functions however they get monomorphized on the first bound (at least that's my best guess).
Aka instead of some Object F with bounds FnMut<(A,)> + FnMut<(B,)>, I get only fn(A) -> _.
I tried this code:
I expected to see this happen:
function.map(t) should perform the same as Manual.map(t)
Instead, this happened:
error[E0631]: type mismatch in function arguments
--> src/main.rs:76:19
|
68 | fn function<T: Add<Output = T> + Copy>(v: T) -> T {
| ------------------------------------------------- found signature defined here
...
76 | dbg!(function.map(t));
| ^^^ expected due to this
|
= note: expected function signature
fn(f32) -> _
found function signature
fn(i32) -> _
note: required for
fn(i32) -> i32 {function::<i32>}
to implementFunction<f32>
--> src/main.rs:42:12
|
42 | impl<F, T> Function for F
| ^^^^^^^^^^^ ^
43 | where
44 | F: FnMut<(T,)>,
| ----------- unsatisfied trait bound introduced here
Meta
Stable, Beta and Nightly all catch this though unboxed_closures is not yet stabilized.
rustc --version --verbose
:rustc +nightly --version --verbose
:The text was updated successfully, but these errors were encountered: