on master help sign in
remove unsafe
fa4caf7Brian Shu
helix-core/src/transaction.rs+1−1
@@ -125,7 +125,7 @@ impl ChangeSet {
125 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
125 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
126 /// returned value will represent the change `docA` → `docC`.
126 /// returned value will represent the change `docA` → `docC`.
127 pub fn compose(self, other: Self) -> Self {
127 pub fn compose(self, other: Self) -> Self {
128− debug_assert!(self.len_after == other.len);
128+ assert!(self.len_after == other.len);
129
129
130 // composing fails in weird ways if one of the sets is empty
130 // composing fails in weird ways if one of the sets is empty
131 // a: [] len: 0 len_after: 1 | b: [Insert(Tendril<UTF8>(inline: "\n")), Retain(1)] len 1
131 // a: [] len: 0 len_after: 1 | b: [Insert(Tendril<UTF8>(inline: "\n")), Retain(1)] len 1
helix-view/src/document.rs+5−12
@@ -102,7 +102,7 @@ pub struct Document {
102 language_server: Option<Arc<helix_lsp::Client>>,
102 language_server: Option<Arc<helix_lsp::Client>>,
103}
103}
104
104
105−use std::fmt;
105+use std::{fmt, mem};
106impl fmt::Debug for Document {
106impl fmt::Debug for Document {
107 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
107 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108 f.debug_struct("Document")
108 f.debug_struct("Document")
@@ -301,20 +301,13 @@ pub async fn to_writer<'a, W: tokio::io::AsyncWriteExt + Unpin + ?Sized>(
301 Ok(())
301 Ok(())
302}
302}
303
303
304−/// Like std::mem::replace() except it allows the replacement value to be mapped from the
305−/// original value.
306−fn take_with<T, F>(mut_ref: &mut T, closure: F)
304+fn take_with<T, F>(mut_ref: &mut T, f: F)
307where
305where
306+ T: Default,
308 F: FnOnce(T) -> T,
307 F: FnOnce(T) -> T,
309{
308{
310− use std::{panic, ptr};
311−
312− unsafe {
313− let old_t = ptr::read(mut_ref);
309+ let t = mem::take(mut_ref);
314− let new_t = panic::catch_unwind(panic::AssertUnwindSafe(|| closure(old_t)))
310+ let _ = mem::replace(mut_ref, f(t));
315− .unwrap_or_else(|_| ::std::process::abort());
316− ptr::write(mut_ref, new_t);
317− }
318}
311}
319
312
320use helix_lsp::lsp;
313use helix_lsp::lsp;