Skip to content

refactor: new error system - #624

Merged
alejandro-vaz merged 20 commits into
servo:v2from
alejandro-vaz:new-errors
Sep 21, 2026
Merged

alejandro-vaz merged 20 commits into
servo:v2from
alejandro-vaz:new-errors

Conversation

@alejandro-vaz

@alejandro-vaz alejandro-vaz commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

this PR remakes error handling to be trait-based instead of relying on fn infallible

closes #622

@alejandro-vaz alejandro-vaz self-assigned this Sep 19, 2026
@alejandro-vaz
alejandro-vaz requested a review from jdm September 20, 2026 09:36
@alejandro-vaz
alejandro-vaz marked this pull request as ready for review September 20, 2026 09:36
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

this diverges from Vec though I think

@alejandro-vaz
alejandro-vaz removed the request for review from jdm September 20, 2026 11:47
@alejandro-vaz
alejandro-vaz marked this pull request as draft September 20, 2026 11:47
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

I'm not sure I fully like this, I'll go back to working on it

@alejandro-vaz
alejandro-vaz marked this pull request as ready for review September 20, 2026 12:02
@alejandro-vaz
alejandro-vaz requested a review from jdm September 20, 2026 12:02
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

now it is cleaner

@bolshoytoster

Copy link
Copy Markdown
Contributor

Is this worth the complication? As far as I can tell there are no functions that could benefit from a more precise error signature.

@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

it kills infallible, which already wasn't being inlined properly, and is more correct in terms of naming and conventions

honestly my stance is that something better is worth merging

and the trait machinery makes the internal API better

that's about it in terms of how much can I defend this

originally it was about making function signatures more precise by letting both kinds of errors exist independently, but it isn't even used anywhere

@bolshoytoster

Copy link
Copy Markdown
Contributor

it kills infallible, which already wasn't being inlined properly

Do we want error handling code to be inlined? Allocation errors should always be the cold path, and we don't want to duplicate this code that will likely never be called.

and is more correct in terms of naming and conventions

Yeah, I was confused by the name when I first came to the repo. Do we need it to be a trait? Couldn't it just be a method on the error enum?

@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

it really can't be a method on the enum because we are implementing it on Result<Type, SmallVecError>, it has to be a trait because of the orphan rule

I think we want error handling to be inlined because it is not just error handling, it is matching the Result variants and if it is not Ok it then matches error variants

if it weren't inlined, there would be an additional jump always

but we could have something like "if it's okay then give the value, if not call this cold never inlined function which matches the error variant (a method)"

I think that's cleaner indeed

@bolshoytoster

Copy link
Copy Markdown
Contributor

it really can't be a method on the enum because we are implementing it on Result<Type, SmallVecError>, it has to be a trait because of the orphan rule

Oh, I didn't see that. So it's either a trait or use something like .unwrap_or_else(handle).

Comment thread src/errors.rs Outdated
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

yeah but unwrap_or_else(handle) wouldn't work because the handle function needs access to the error, and it will cause MSRV conflicts with reachability, because it thinks that Infallible really exists and is returned

@bolshoytoster

Copy link
Copy Markdown
Contributor

yeah but unwrap_or_else(handle) wouldn't work because the handle function needs access to the error

unwrap_or_else passes the error to the function

and it will cause MSRV conflicts with reachability, because it thinks that Infallible really exists and is returned

Does MSRV not allow arbitrary return types on functions that never return? Something like

fn hande<T>(e: CollectionAllocErr) -> T {
    panic!() or whatever
}

@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

your way is better

Comment thread src/lib.rs
@bolshoytoster

bolshoytoster commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

How come reserve wasn't just

pub fn reserve(&mut self, additional: usize) {
    infallibe(self.try_reserve(additional));
}

?

Same with {,try_}reserve_exact

That's probably out of scope for this PR though.

Comment thread src/errors.rs
Comment thread src/errors.rs Outdated
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

I do want #644 merged soon because the nightly check takes ages to complete

@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

how the hell has it been going for 20 minutes

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that the final changes in this PR are:

  • rename the error type
  • change one variant away from an struct variant
  • replace uses of the infallible function with unwrap_or_else

This ultimately feels more like idiomatic Rust, so I'm fine with that.

@alejandro-vaz
alejandro-vaz added this pull request to the merge queue Sep 21, 2026
Merged via the queue into servo:v2 with commit 9cbc438 Sep 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error structs prototype

3 participants