refactor(core): Remove unneeded unsafe in UnwrapInfallible and Unquoted

This commit is contained in:
Jade Ellis committed 2026-11-21 18:04:50 +00:00
1 parent 9744a6e332
commit 7e678869ec
2 files changed
+8 -9

No files matched your search

+3 -5
View File
@@ -1,7 +1,6 @@
use std::convert::Infallible;
use super::{DebugInspect, Result};
use crate::error;
use super::Result;
pub trait UnwrapInfallible<T> {
fn unwrap_infallible(self) -> T;
@@ -10,8 +9,7 @@ pub trait UnwrapInfallible<T> {
impl<T> UnwrapInfallible<T> for Result<T, Infallible> {
#[inline]
fn unwrap_infallible(self) -> T {
// SAFETY: Branchless unwrap for errors that can never happen. In debug
// mode this is asserted.
unsafe { self.debug_inspect_err(error::infallible).unwrap_unchecked() }
let Ok(val) = self;
val
}
}
+5 -4
View File
@@ -32,11 +32,12 @@ impl<'a> From<&'a str> for &'a Unquoted {
fn from(s: &'a str) -> &'a Unquoted {
let s: &'a str = s.unquote_infallible();
//SAFETY: This is a pattern I lifted from ruma-identifiers for
// strong-type strs by wrapping in a tuple-struct.
#[allow(clippy::transmute_ptr_to_ptr)]
// SAFETY: `Unquoted` is `#[repr(transparent)]` over `str`, so
// `*const str` and `*const Unquoted` have identical layout and
// metadata, and the returned reference preserves lifetime `'a`.
#[allow(clippy::as_conversions)]
unsafe {
std::mem::transmute(s)
&*(std::ptr::from_ref::<str>(s) as *const Unquoted)
}
}
}