Back to News
Advertisement
Advertisement

⚡ Community Insights

Discussion Sentiment

50% Positive

Analyzed from 117 words in the discussion.

Trending Topics

#borrow#checker#same#rust#why#programmer#check#object#knows#mut

Discussion (2 Comments)Read Original on HackerNews

ketzu23 minutes ago
> In Rust, that question is answered by the borrow-checker at compile time:

(About zero sized objects being the same)

But why does that mean the programmer never has to check? (or if they want that information from the borrow checker how would they get it?) It's not motivated as the intro above for c++ was just "In C++, we might do this to check if two pointers refer to the same object".

So the borrow checker knows already, why does that stop the programmer from wanting to know or separate these cases?

loeg6 minutes ago
It's not obvious to me that the borrow checker actually knows, so much as it can prove there are no illegal conflicts between mut and non-mut references to the same object.

If you somehow need this property in your programs, I think you can just add a 1-byte member and use pointer equality. (I'm not a Rust expert.)