Open
Description
I tried this code:
use std::rc::Rc;
use std::sync::Arc;
struct Data {
a: u64,
b: u64,
}
fn add_numbers(p: &Data) -> u64 {
p.a + p.b
}
pub fn add_two_numbers_arc(a: u64, b: u64) -> u64 {
let x = Arc::new(Data { a, b });
add_numbers(&x)
}
pub fn add_two_numbers_rc(a: u64, b: u64) -> u64 {
let x = Rc::new(Data { a, b });
add_numbers(&x)
}
I expected to see this happen: The heap allocation of both the Rc
and the Arc
should be optimized out.
Instead, this happened: Only Rc
got the optimization.