Box with a function field fails in rustc: the lowered closure’s Box::pin resolves to the program’s BoxOpen and answer this issue on GitHub.
ready · opened 2026-11-01 · updated 2026-11-01 · 0 comments
Part I names a struct Box[T] in its own example, so Box is a free name for a program. When such a struct holds a function value, the lowered Rust wraps the lambda in Box::pin(..), which resolves to the program’s struct, and rustc’s error comes back to the user.
Probe (0.0.1335):
struct Box {
run: fn(i64) -> i64,
}
fn main() {
let b = Box { run: fn(x) { x + 1 } }
print(b.run(1))
}
error: No associated function or constant named `pin` found for struct `Box` in the current scope.
--> b.nika:6:5
Renamed to Holder, the program prints 2.
::std::boxed::Box) wherever it writes one (closures, pinned futures, trait objects), so a program’s Box (or Pin, Arc, …) does not shadow it; check the other std names the lowering writes bare.tests/compiler/: the probe prints 2.