While watching this talk on mutexes, early in the talk, the presenter shows a slide with a tiny bit of rust code where I learnt about std::hint::blackbox function. The function is essentially an identity function. The documentation gives some very clear explanation and an example.
It is very useful to prevent a value from being optimized away by the compiler. The std::hint::black_box points to core::intrinsics::black_box which is declared as a “const”c function. Any const expression is an expression that can be evaluated at compile time. It is defined as a rust intrinsic function within the core library.
I didn’t know about this function until now and it seem pretty useful.