A puzzle and why generics are not generic enough right now

The problem isn't that consume_generic isn't generic enough – it is that built-in references have implicit reborrowing operation applied to them; your second example is the same as:

let v: &mut i32 = get_value();
consume(&mut *v);
consume(&mut *v);

Therefore the values passed into consume are indeed not Copy but they are different values from each others, and they get consumed as move.

So the semantics of your Revive trait don't match the current language semantics.

3 Likes