Skip to content

Conversation

@tarcieri
Copy link
Member

@tarcieri tarcieri commented Jan 4, 2026

It was previously derived, which would use the Default impl of the underlying T which, in almost every case, will return zero, violating the invariant of the type.

This adds a custom Default impl similar to the one on NonZero which is bounded on One trait, and returns Odd(T::one()).

Fixes #1070

It was previously derived, which would use the `Default` impl of the
underlying `T` which, in almost every case, will return zero, violating
the invariant of the type.

This adds a custom `Default` impl similar to the one on `NonZero` which
is bounded on `One` trait, and returns `Odd(T::one())`.

Fixes #1070
impl<T> Default for NonZero<T>
where
T: Constants,
T: One,
Copy link
Member Author

Choose a reason for hiding this comment

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

Went ahead and relaxed this bound considerably too

@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.86%. Comparing base (613a471) to head (4caad8d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1071      +/-   ##
==========================================
+ Coverage   78.83%   78.86%   +0.02%     
==========================================
  Files         173      173              
  Lines       17716    17725       +9     
==========================================
+ Hits        13966    13978      +12     
+ Misses       3750     3747       -3     

☔ View full report in Codecov by Sentry.
📢 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.

@tarcieri tarcieri merged commit 30626b4 into master Jan 4, 2026
26 checks passed
@tarcieri tarcieri deleted the fix-odd-default-impl branch January 4, 2026 16:25
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.

Default impl for Odd is the default of T (zero)

2 participants