Expand description

Custom pointer types used to ensure that initialization was done completly. The pointer types provided by this module [NeedsPinnedInit<'init, T>] and [NeedsInit<'init, T>] will

  • panic when debug assertions are turned on
  • produce link time erros when debug assertions are turned off when they determine, that a value has not been initialized.

This catches simple errors when forgetting a variable.

The link time errors emitted by the linker will look overwhelming and are not very helpful (you might be able to interpret the LLVM symbol where the link error originated), instead they help you extend your tests or check your unused variable warnings with more scrutiny.

Example Linker error ```text TODO ERROR ``` TODO ```rust TODO EXAMPLE CODE ``` When running the debug build instead, we end up with the following panic, which is a lot more helpful at providing the relevant information: ```text TODO PANIC ```

Behaviour rationale

The correctness of the link error relies on the compiler to optimize the drop glue away. This is of course only possible, if optimizations are enabled. If you encounter such a link error and receive no runtime errors despite running all initializer functions and being very sure that you did not forget initializing a value, then feel free to report this issue at my repo.

If in some rare cases the compiler is unable to determine that all instances of NeedsPinnedInit and NeedsInit are initialized, you are able to disable the static and dynamic initialization check provided by this module: pass the pinned_init_unsafe_no_enforce_init flag to rustc:

RUSTFLAGS="--cfg pinned_init_unsafe_no_enforce_init" cargo build

This will also need to be done by all crates, that depend on your crate, because it is circumventing one of the safety guarantees of this crate and is expicitly opt-in. Please try to find a safe workaround or open an issue at [my repo].

Structs

A pointer to data that needs to be initialized. When this pointer is neglected and not initialized, it will

A pointer to pinned data that needs to be initialized while pinned. When this pointer is neglected and not initialized, it will