I found interesting behavior.
A call to default on a String has one more instruction than a call to to_string on an empty &str. Why?
pub fn string_default() -> String {
Default::default()
}
pub fn string_to_string() -> String {
"".to_string()
}
example::string_default:
mov rax, rdi
mov rcx, qword ptr [rip + .L__unnamed_1]
xorps xmm0, xmm0
movups xmmword ptr [rdi + 8], xmm0
mov qword ptr [rdi], rcx
ret
example::string_to_string:
mov rax, rdi
xorps xmm0, xmm0
movups xmmword ptr [rdi + 8], xmm0
mov qword ptr [rdi], 1
ret
.L__unnamed_1:
.asciz "\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
UPD: build profile 'release'
UPD (2): before rust 1.52.0 the assembler code is the same for both functions (4 instructions). In 1.51.0 and earlier mov qword comes before xorps.