Skip to content

Make TestError an effectively-never instantiated struct#18

Closed
wiktor-k wants to merge 1 commit into
mainfrom
make-test-error-a-struct
Closed

Make TestError an effectively-never instantiated struct#18
wiktor-k wants to merge 1 commit into
mainfrom
make-test-error-a-struct

Conversation

@wiktor-k

@wiktor-k wiktor-k commented Nov 21, 2025

Copy link
Copy Markdown
Owner

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 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.

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>
@wiktor-k wiktor-k force-pushed the make-test-error-a-struct branch from 0fa5d11 to f052f2b Compare November 24, 2025 11:07
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>
@wiktor-k

wiktor-k commented Dec 2, 2025

Copy link
Copy Markdown
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.

@wiktor-k wiktor-k closed this Dec 2, 2025
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