Post #1183626
2026-04-14 22:48 UTC
In #Rust, `struct S<T>` yields a compiler error, but `fn f<T>() {}` does not even yield a warning. Why not?
#rustlang
Replies (1)
-
@olsonseank@hachyderm.io 2026-04-15 00:22
@blp I believe this mostly comes down to variance and drop checking. Rust infers variance and "dropck" based on the usage of `T` in data structures. This doesn't apply to `fn`s, since they cannot interact with or "store" `T` directly but only via parameters. See https://doc.rust-lang.org/nomicon/subtyping.html