RS.CLIPPY.RESULT_LARGE_ERR

Function returning `Result` with large `Err` 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: result_large_err. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for functions that return Result with an unusually large Err-variant.

Why is this bad?

A Result is at least as large as the Err-variant. While we expect that variant to be seldom used, the compiler needs to reserve and move that much memory every single time. Furthermore, errors are often simply passed up the call-stack, making use of the ?-operator and its type-conversion mechanics. If the Err-variant further up the call-stack stores the Err-variant in question (as library code often does), it itself needs to be at least as large, propagating the problem.

Known problems

The size determined by Clippy is platform-dependent.

Examples

pub enum ParseError {
    UnparsedBytes([u8; 512]),
    UnexpectedEof,
}

// The `Result` has at least 512 bytes, even in the `Ok`-case
pub fn parse() -> Result<(), ParseError> {
    Ok(())
}

should be

pub enum ParseError {
    UnparsedBytes(Box<[u8; 512]>),
    UnexpectedEof,
}

// The `Result` is slightly larger than a pointer
pub fn parse() -> Result<(), ParseError> {
    Ok(())
}

Configuration

  • large-error-threshold: The maximum size of the Err-variant in a Result returned from a function

    (default: 128)