Make TestError an effectively-never instantiated struct#18
Closed
wiktor-k wants to merge 1 commit into
Closed
Conversation
One of clients of this library return errors from their test functions
and explicitly `into()` them. Rust nightly started issuing lint failures
for `TestError` being uninhabited (and as such the code being unreachable):
```
note: this expression has type `testresult::TestError`, which is uninhabited
--> nethsm/src/user.rs:804:31
|
804 | Err(error) => Err(format!("Expected to fail with a Error::InvalidUserIds but got a different error instead:\n{error}").into()),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unreachable expression
--> nethsm/src/user.rs:805:27
|
805 | Ok(user_id) =>Err(format!("Expected to fail with a Error::InvalidUserIds but succeeded instead:\n{user_id}").into())
| ^^^^-------------------------------------------------------------------------------------------------^
| | |
| | any code following this expression is unreachable
| unreachable expression
```
This PR converts the `TestError` to a struct that is never instantiated.
Additionally it marks it as `#[non_exhaustive]` so that it is not possible
to instantiate an object of this type outside of our crate.
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
0fa5d11 to
f052f2b
Compare
archlinux-github
pushed a commit
to archlinux/signstar
that referenced
this pull request
Dec 1, 2025
Clippy 1.92 will start issuing "uninhabited type" warnings on December 11th. This patch rewrites branches to use direct `panic!` macro instead of relying on `testresult::TestError` panicking conversion. See: wiktor-k/testresult#18 Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
archlinux-github
pushed a commit
to archlinux/signstar
that referenced
this pull request
Dec 2, 2025
Clippy 1.92 will start issuing "uninhabited type" warnings on December 11th. This patch rewrites branches to use direct `panic!` macro instead of relying on `testresult::TestError` panicking conversion. See: wiktor-k/testresult#18 Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
Owner
Author
|
At Signstar we decided to rewrite the test code instead of relaxing testresult. So, closing this PR as not-planned but it may be useful as a reference for others. |
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.
One of clients of this library return errors from their test functions and explicitly
into()them. Rust nightly started issuing lint failures forTestErrorbeing uninhabited (and as such the code being unreachable):This PR converts the
TestErrorto a struct that is effectively never instantiated. Additionally it marks it as#[non_exhaustive]so that it is not possible to instantiate an object of this type outside of our crate.CCing @swallez @ijackson in case you have better ideas 😅
Edit: it seems the beta (which currently complains) will become stable on December 11th so we'd need that merged and a new version released before that date.