Skip to content

Relax Logos::Error bounds - #570

Open
DavidCrossman wants to merge 2 commits into
maciejhirsz:masterfrom
DavidCrossman:relax_error_bounds
Open

Relax Logos::Error bounds#570
DavidCrossman wants to merge 2 commits into
maciejhirsz:masterfrom
DavidCrossman:relax_error_bounds

Conversation

@DavidCrossman

Copy link
Copy Markdown
Contributor

Motivation

Logos::Error has several trait bounds which are not necessarily required. These extra bounds impose restrictions on the custom error type the user provides. In particular, the Default bound may require adding a #[default] Other variant to an error enum even if an error callback is specified.

Relaxing the Default bound

There are three cases to consider:

  1. The user does not supply a custom error type
  2. The user supplies a custom error type with an error callback
  3. The user supplies a custom error type without an error callback

For (1), the fallback error type is (), which implements Default, so the bound is irrelevant.
For (2), the user's error callback is called rather than Default::default, so the bound isn't needed.
For (3), the _make_error function will fallback to Default::default. If the custom error type doesn't implement Default, this will cause a type error. The user gets an error message suggesting to implement Default on the custom error type.

This makes the Default bound required only if the user does not provide an error callback (case (3)), rather than unconditionally. The Logos derive already uses this technique to require Into<CustomErrorType> for each callback's error type. Relaxing the Default bound in this way would be backwards compatible.

Examples and Book

I've updated the book to reflect these changes. I have also simplified the examples which use error callbacks.

Relation to #459

This PR encompasses #459, so it could be merged before this PR (or closed).

@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing DavidCrossman:relax_error_bounds (67e4554) with master (d5fea38)

Open in CodSpeed

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.66%. Comparing base (b6dc674) to head (67e4554).
⚠️ Report is 11 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #570   +/-   ##
=======================================
  Coverage   73.66%   73.66%           
=======================================
  Files          29       29           
  Lines        1929     1929           
=======================================
  Hits         1421     1421           
  Misses        508      508           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant