RS.CLIPPY.UNINHABITED_REFERENCES
Reference to uninhabited type
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: uninhabited_references. Copyright ©2025 The Rust Team. All rights reserved.
What it does
It detects references to uninhabited types, such as ! and
warns when those are either dereferenced or returned from a function.
Why is this bad?
Dereferencing a reference to an uninhabited type would create
an instance of such a type, which cannot exist. This constitutes
undefined behaviour. Such a reference could have been created
by unsafe code.
Example
The following function can return a reference to an uninhabited type
(Infallible) because it uses unsafe code to create it. However,
the user of such a function could dereference the return value and
trigger an undefined behavior from safe code.
fn create_ref() -> &\'static std::convert::Infallible {
unsafe { std::mem::transmute(&()) }
}