There is no influence; I checked the assembly generated for both options and it is identical.
Two versions that I compared:
"external":
fn main() { let x = 2i64; let y = 5i64; let external_res = external_plus(x,y); } fn external_plus(x: i64, y: i64) -> i64 { x + y }
"local":
fn main() { fn local_plus(x: i64, y: i64) -> i64 { x + y } let x = 2i64; let y = 5i64; let local_res = local_plus(x, y); }
And both give the same asm result (release mode in today's night mode):
.text .file "rust_out.cgu-0.rs" .section .text._ZN8rust_out4main17hb497928495d48c40E,"ax",@progbits .p2align 4, 0x90 .type _ZN8rust_out4main17hb497928495d48c40E,@function _ZN8rust_out4main17hb497928495d48c40E: .cfi_startproc retq .Lfunc_end0: .size _ZN8rust_out4main17hb497928495d48c40E, .Lfunc_end0-_ZN8rust_out4main17hb497928495d48c40E .cfi_endproc .section .text.main,"ax",@progbits .globl main .p2align 4, 0x90 .type main,@function main: .cfi_startproc movq %rsi, %rax movq %rdi, %rcx leaq _ZN8rust_out4main17hb497928495d48c40E(%rip), %rdi movq %rcx, %rsi movq %rax, %rdx jmp _ZN3std2rt10lang_start17h14cbded5fe3cd915E@PLT .Lfunc_end1: .size main, .Lfunc_end1-main .cfi_endproc .section ".note.GNU-stack","",@progbits
This means that there will be zero difference in the generated binary format (not only performance).
Also, it doesn't matter if you use a function; following approach:
fn main() { let x = 2i64; let y = 5i64; let res = x + y; }
Also gives the same build.
The bottom line is that in the general case, functions are embedded regardless of whether you declare them in main() or outside it.
Edit : as Shepmaster noted, there are no side effects in this program, so the generated assembly for both options is actually the same as for:
fn main() {}
However, the MIR output for both is the same (and different from one for the empty main() ), so there should be no difference coming from the location of the function, even if side effects were present.