Code
extern "C" fn foo(v: &i32) {
dbg!(v);
}
static BAR: for<'a> fn(&'a i32) = foo; // this is a type mismatch
Current output
error[E0308]: mismatched types
--> src/lib.rs:5:35
|
5 | static BAR: for<'a> fn(&'a i32) = foo;
| ^^^ expected "Rust" fn, found "C" fn
|
= note: expected fn pointer `for<'a> fn(&'a _)`
found fn item `extern "C" for<'a> fn(&'a _) {foo}`
For more information about this error, try `rustc --explain E0308`.
Desired output
error[E0308]: mismatched types
--> src/lib.rs:5:35
|
5 | static BAR: for<'a> fn(&'a i32) = foo;
| ^^^ expected "Rust" fn, found "C" fn
|
= note: expected fn pointer `for<'a> fn(&'a _)`
found fn item `for<'a> extern "C" fn(&'a _) {foo}` // <- Order swapped
For more information about this error, try `rustc --explain E0308`.
Rationale and extra context
extern "C" for<'a> fn(...) is currently not a valid type signature:
error: expected type, found keyword `extern`
--> src/lib.rs:16:13
|
16 | static BAZ: extern "C" for<'a> fn(&'a i32) = foo;
| ^^^^^^ expected type
The user trying to use the found type will meet a parsing error.
The correct way to express the type is actually for<'a> extern "C" fn(...).
Other cases
Rust Version
rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3
(also tested with latest nightly in playground: 1.95.0-nightly (2026-01-19 d940e56841ddcc05671e))
Anything else?
No response
Code
Current output
Desired output
Rationale and extra context
extern "C" for<'a> fn(...)is currently not a valid type signature:The user trying to use the found type will meet a parsing error.
The correct way to express the type is actually
for<'a> extern "C" fn(...).Other cases
Rust Version
rustc 1.92.0 (ded5c06cf 2025-12-08) binary: rustc commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234 commit-date: 2025-12-08 host: x86_64-unknown-linux-gnu release: 1.92.0 LLVM version: 21.1.3 (also tested with latest nightly in playground: 1.95.0-nightly (2026-01-19 d940e56841ddcc05671e))Anything else?
No response