servo / servo/rust-smallvec

error structs prototype

Open
#622 3 comments 0 reactions 1 assignee View on GitHub

@alejandro-vaz is already working on this.

Since Sep 17, 2026.

experiment r-refactor
Dominant language
Rust
Stars
1.7k
Forks
216
Avg merge
17h 50m
Merged PRs (30d)
95

Description

prototype having the errors as separate structs that are instantiated instead of an enum

current model:

#[derive(Debug)]
pub enum CollectionAllocErr {
    /// Overflow `usize::MAX` or other error during size computation
    CapacityOverflow,
    /// The allocator return an error
    AllocErr {
        /// The layout that was passed to the allocator
        layout: Layout
    }
}

the current model is a simple enum with two variants, which means that neither variant can exist independently but as an instance of the enum

then, the infallible function is used to either panic on an error result or call handle_alloc_error

the proposal is for something like

pub struct CapacityOverflow;

pub struct AllocationError(Layout);

// if necessary an enum encompassing both

pub trait Handle { // handle the error, implemented for both errors
    // one function that either panics or handles alloc error
    // depending on the implementation for that type
}

which will allow us to have precise error signatures and avoid the infallible helper

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.