Skip to content

Conversation

@hovinen
Copy link
Contributor

@hovinen hovinen commented Jun 30, 2023

Previously, the match explanation when the wrong enum variant was used would just state that there was no such field:

Value of: actual
Expected: is AnEnum :: B which has field `0`, which is equal to 123
Actual: A(123),
  which has no field `0`

This is confusing, since the actual value does have such a field. It's just of the wrong enum variant.

This fixes the error message to indicate that the wrong variant was supplied:

Value of: actual
Expected: is AnEnum :: B which has field `0`, which is equal to 123
Actual: A(123),
  which has the wrong enum variant `A`

To output the supplied enum variant, it is necessary to construct the debug output and strip it of any fields it may have. This is inefficient, but unfortunately there is no obvious way to directly debug-output just the enum variant with no fields.

…t is used in `matches_pattern!`.

Previously, the match explanation when the wrong enum variant was used would just state that there was no such field:

```
Value of: actual
Expected: is AnEnum :: B which has field `0`, which is equal to 123
Actual: A(123),
  which has no field `0`
```

This is confusing, since the actual value _does_ have such a field. It's just of the wrong enum variant.

This fixes the error message to indicate that the wrong variant was supplied:

```
Value of: actual
Expected: is AnEnum :: B which has field `0`, which is equal to 123
Actual: A(123),
  which has the wrong enum variant `A`
```

To output the supplied enum variant, it is necessary to construct the debug output and strip it of any fields it may have. This is inefficient, but unfortunately there is no obvious way to directly debug-output just the enum variant with no fields.
@copybara-service copybara-service bot merged commit e8eebff into main Jun 30, 2023
@gribozavr gribozavr deleted the show-wrong-enum-variant-in-matches-pattern branch February 17, 2025 18:29
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.

2 participants