RS.CLIPPY.ALLOC_INSTEAD_OF_CORE

Type is imported from alloc when available in core

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: alloc_instead_of_core. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Finds items imported through alloc when available through core.

Why restrict this?

Crates which have no_std compatibility and may optionally require alloc may wish to ensure types are imported from core to ensure disabling alloc does not cause the crate to fail to compile. This lint is also useful for crates migrating to become no_std compatible.

Known problems

The lint is only partially aware of the required MSRV for items that were originally in std but moved to core.

Example

use alloc::slice::from_ref;

Use instead:

use core::slice::from_ref;