Add public constructors for SizeError and ValidityError - #3678
Open
barunaniket wants to merge 4 commits into
Open
barunaniket wants to merge 4 commits into
barunaniket wants to merge 4 commits into
Conversation
Callers who know, out-of-band, that a conversion would fail due to incorrect source size or invalid source data currently have no way to construct a SizeError or ValidityError directly, and must instead perform a contrived failing conversion just to obtain one (see google#3666). Make SizeError::new and ValidityError::new public so these errors can be constructed directly and forwarded via the existing From impls into ConvertError, TryReadError, etc. Fixes google#3666
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3678 +/- ##
==========================================
+ Coverage 91.90% 91.96% +0.05%
==========================================
Files 20 20
Lines 6175 6183 +8
==========================================
+ Hits 5675 5686 +11
+ Misses 500 497 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adding rustdoc to SizeError::new shifted every line below it in
error.rs down by 16, including the ValidityError struct definition
whose TryFromBytes bound is cited by rustc in trybuild UI test
snapshots (try_transmute[.mut/.ref].{msrv,stable,nightly}.stderr).
Update the embedded line number from 590 to 606 to match.
The previous fix updated the '--> src/error.rs:590:45' pointer line but
missed the quoted source excerpt line ('590 | pub struct ValidityError...')
that rustc also embeds in the same diagnostic. Update it to 606 as well.
Author
|
@joshlf This is ready for review whenever you get a chance — CI is green. Let me know if you'd like any changes. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Callers who know, out-of-band, that a conversion would fail due to incorrect source size or invalid source data currently have no way to construct a
SizeErrororValidityErrordirectly, and must instead perform a contrived failing conversion just to obtain one (see #3666).This makes
SizeError::newandValidityError::newpublic so these errors can be constructed directly and forwarded via the existingFromimpls intoConvertError,TryReadError, etc.AlignmentErroris intentionally left as-is: its constructor isunsafebecause of a soundness invariant (Dst's alignment requirement must be greater than one, relied on elsewhere viaunreachable_unchecked), so a safe public constructor would need a checked design (e.g. panicking orOption-returning) rather than a simple visibility change — that seems like a separate decision for maintainers to weigh in on.Fixes #3666
Test plan
cargo test --doc— new doc examples for both constructors compile and passcargo test --lib— full library test suite passes (112 tests)cargo test --doc(full suite) — 128 doc tests passcargo clippy— no new warnings inerror.rscargo build --no-default-features— no_std build succeedsrustfmt +nightly --checkon the changed file — no diff introduced by this change