the underscore expression (and wildcard pattern in let binding) does NOT drop the value: it simply discards (or, ignores) it, like nothing happened. particularly, it does NOT move the value like mem::drop() does.
so the first example, the variable non_send is NOT captured in the closure, while the second one is.
here's an example showing _ does NOT move a value:
struct NonCopy {}
fn compiles() {
let value = NonCopy {};
let _ = value; //<-- `value` NOT moved here
let moved = value;
}
fn error() {
let value = NonCopy {};
let _value = value; //<-- value MOVED here
let moved = value; //<-- error: use of moved value
}
here's another example that might be supprising to new rustaceans:
fn main() {
unsafe {
let _: i32 = *std::ptr::null(); //<-??? dereferencing a null pointer
}
}
you can run it on the playground, nothing will happen (well, except for a lint warning by the compiler), no panic, no crash, no segfault, no nothing! and miri will NOT report UB either.