Closed as not planned
Description
let x = "Hello".to_string();
dbg!(x);
println!("{x}");
The above code returns this following error:
borrow of moved value: `x`
value borrowed here after move
To solve this, you'd normally have to add a reference character like this:
dbg!(&x);
But I think that Rust compiler should be able to understand what i'm trying to do without me having to manually add a reference on the variable x
. I think this could be achieved by making an implementation that follows a similar logic as the following pseudocode:
fn dbg_reference_checker<T>(
x: T
) -> Result<(), DbgError> {
if !error_w_moved_value {
use_moved_value(x)?;
} else if !error_with_reference {
use_reference(x)?;
} else {
return Err(DbgError::CannotDebugTheVariable)
}
}