Boxing obvious cases where the type is clear

For something with ergonomics closer to that of a static compiler/linter, GitHub - aviatesk/JET.jl: An experimental code analyzer for Julia. No need for additional type annotations. may be preferable.

julia> using JET

julia> function f()
           x = 1
           x = 2 # causes boxing
           () -> x
       end
f (generic function with 1 method)

julia> JET.@report_opt f() # usually a top-level function call of your choice
═════ 1 possible error found ═════
┌ f() @ Main ./REPL[2]:2
│ captured variable `x` detected
└────────────────────