Store the temporary value in a variable before borrowing it to extend its lifetime. The compiler drops temporary values at the end of the statement, so you must bind the value to a named variable first to keep it alive for the borrow.
let s = String::from("hello");
let len = calculate_length(&s);
This ensures s lives long enough for calculate_length to borrow it, whereas calculate_length(&String::from("hello")) fails because the temporary string is dropped immediately after the function call.