mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-22 00:17:33 +00:00
refactor(core): Remove unneeded unsafe in UnwrapInfallible and Unquoted
This commit is contained in:
2 files changed
+8
-9
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user