Skip to content

Commit df9bb7d

Browse files
committed
Remove all usage of unsafe
1 parent 22ee084 commit df9bb7d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#[cfg(not(feature = "std"))]
4343
extern crate alloc;
4444

45-
use core::{error::Error, fmt::Display, hint::unreachable_unchecked, mem};
45+
use core::{error::Error, fmt::Display, mem};
4646

4747
#[cfg(feature = "std")]
4848
use std::{borrow::Cow, env, fmt::Debug};
@@ -466,10 +466,12 @@ where
466466
/// ```
467467
pub fn value(&mut self) -> Option<String> {
468468
match self.state {
469-
State::LeftoverValue(_) => match mem::replace(&mut self.state, State::NotInteresting) {
470-
State::LeftoverValue(val) => Some(val),
471-
_ => unsafe { unreachable_unchecked() },
472-
},
469+
State::LeftoverValue(ref mut value) => {
470+
let value = mem::take(value);
471+
self.state = State::NotInteresting;
472+
473+
Some(value)
474+
}
473475
_ => None,
474476
}
475477
}

0 commit comments

Comments
 (0)