My (limited) understanding is that format!("{}", v) and format!("{}", &v) are essentially identical, and should generate identical assembly code and identical performance results. This is based on reading Does println! borrow or own the variable?). Yet, when comparing these two functions, the assembly is somewhat different. Is this expected, or is this a missing Rust compiler optimization? Or is there some edge case in which it is important to generate different code?
pub fn bar(j: i32) -> String {
format!("bar {}", j)
}
// vs
pub fn foo(i: i32) -> String {
format!("foo {}", &i)
}
Benchmarks
Running benchmarks produces ~6% difference in performance:

<&i32 as core::fmt::Display>::fmtdoesn't get inlined. If it did, then I would expect the assembly to be identical. You can see this function gets emitted in the&icase, and then -- obviously --foohas to actually give it the address of thei32instead of thei32itself.#[inline]?