Why would compiler need to provide it? “default warnings” and “normal explanation” are for things that people may misunderstand and use for wrong purpose.
How can you use that code to do something wrongly? You may either understand it properly and misunderstand it and either get a compile-time error (when you would attempt to use moved-out value) or program would work like you expect. Do we even need any warning in the latter case where everything works like it should just for the wrong reason?
Except Rust haven't tried to be a system language initially. It just wanted to be predictable, logical, language instead.
Then people have found out that you may do system development with such a language.
But what exactly is hidden here?
The big question is: why do you expect that expression to an expression without effect?
What if you would have something like this.
my_super_duper_func(bb);
This wouldn't be “something without effect”, right?
And if we would use drop
:
drop(bb);
This is still not an expression without effect, right?
Okay, drop
is defined like this:
pub fn drop<T>(_x: T) {
}
And if we would just manually inline it's body we end up with:
bb;
Why should this step, suddenly, change the semantic of everything?
The “proper explanation” can only be found if one may find something to explain. Why bb;
is not an expression without effect is obvious to me (the rules say that if you take value of variable and use it without &
or &mut
somewhere then you are moving it somewhere and the fact that we are moving it into fourth dimension like in a Stranger in a Strange Land doesn't change anything), but not for you… can you explained which rules you had in your head when you arrived at the conclusion that bb;
shouldn't do anything?
I was confused, at first, by the fact that let _ = bb;
doesn't do anything and that required some explanation, but after some thinking I realised that having _
as a non-binding expression is nice and if we have that then let _ = bb;
shouldn't do anything, but why bb;
should behave like that? That would have been strange and illogical to me.