Variance of extern fn vs fn



I’ve ask this question in user forum and I haven’t received any convincing answer so I was suggested to post it here.

Intuitively, we expected that extern should preserve the variance of fn wrt arguments and output types. However, for the sake of mathematical rigor, I’d like to see how it is deduced using xform or glb.

By definition primitives are bivariant, including extern type (Variance in Rust under Variance of Built-in Type Constructors). So in order to deduce the variance of extern fn(T) wrt T, it seems we should use xform, because it’s like a type composition. Therefore, it implies the bivarince (since bivariance is dominant to the left) and this is wrong and it matches the intuition, however, not my mathematical mental model.

Finally, this shows that to derive the variance of extern fn(T) glb was used, but isn’t glb for type aggregator? is extern a form a type aggregation and how?


I’m pretty sure this question isn’t appropriate for Internals. This isn’t a proposal to change the language, and it isn’t internal documentation about working on the compiler. It’s literally just a question about how the language works.

link to the users thread

closed #3

This topic was automatically closed after 8 hours. New replies are no longer allowed.