From 9361e0a61e7cfc145db5d257b875f36a22a6ec37 Mon Sep 17 00:00:00 2001 From: Max Black Date: Fri, 15 Nov 2024 14:31:42 +0000 Subject: [PATCH] Mark U16UtfExt trait as unsafe. --- src/traits.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 53b1211..f3381d9 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -119,7 +119,10 @@ impl U8UtfExt for u8 { /// Methods for working with `u16`s as UTF-16 units. -pub trait U16UtfExt { +/// +/// This trait is marked as unsafe because avoiding undefined behaviour +/// necessarily depends on it being implemented correctly. +pub unsafe trait U16UtfExt { /// Will you need an extra unit to complete this codepoint? /// /// Returns `Err` for trailing surrogates, `Ok(true)` for leading surrogates, @@ -132,7 +135,7 @@ pub trait U16UtfExt { /// Is basically an unchecked variant of `utf16_needs_extra_unit()`. fn is_utf16_leading_surrogate(self) -> bool; } -impl U16UtfExt for u16 { +unsafe impl U16UtfExt for u16 { #[inline] fn utf16_needs_extra_unit(self) -> Result { match self {