Skip to content

Commit 33ce74f

Browse files
committed
add error message to string_enum!s string conversions
1 parent d19bdf9 commit 33ce74f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: src/tools/compiletest/src/common.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ macro_rules! string_enum {
3939
}
4040

4141
impl FromStr for $name {
42-
type Err = ();
42+
type Err = String;
4343

44-
fn from_str(s: &str) -> Result<Self, ()> {
44+
fn from_str(s: &str) -> Result<Self, Self::Err> {
4545
match s {
4646
$($repr => Ok(Self::$variant),)*
47-
_ => Err(()),
47+
_ => Err(format!(concat!("unknown `", stringify!($name), "` variant: `{}`"), s)),
4848
}
4949
}
5050
}

Diff for: src/tools/compiletest/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ fn string_enums() {
9191

9292
// Invalid conversions
9393
let animal = "nya".parse::<Animal>();
94-
assert!(matches!(animal, Err(())));
94+
assert_eq!("unknown `Animal` variant: `nya`", animal.unwrap_err());
9595
}

0 commit comments

Comments
 (0)