From 96e202505f66ecc80747b5855916c7dbbc2a2a2b Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 22 Oct 2019 20:00:26 -0700 Subject: [PATCH] wip --- .vscode/settings.json | 4 +++- src/main.rs | 1 + src/support.rs | 4 +++- src/v8/inspector/channel.rs | 12 ++++++------ src/v8/inspector/client.rs | 18 +++++++++--------- src/v8/platform/task.rs | 11 ++++++----- src/v8/string_buffer.rs | 15 +++++++-------- src/v8/string_view.rs | 11 +++++------ 8 files changed, 40 insertions(+), 36 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index be7e87a6..dfabba5d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -119,5 +119,7 @@ "propagate_const": "cpp", "span": "cpp", "*.ipp": "cpp" - } + }, + "rust.cfg_test": true, + "rust.clippy_preference": "on" } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index c618dfff..c96b2e51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![warn(clippy::all)] #![allow(dead_code)] #![allow(non_snake_case)] diff --git a/src/support.rs b/src/support.rs index 9edc0e33..75ad9a4d 100644 --- a/src/support.rs +++ b/src/support.rs @@ -63,7 +63,9 @@ where T: Delete, { fn drop(&mut self) { - self.0.take().map(Delete::delete); + if let Some(v) = self.0.take() { + Delete::delete(v) + } } } diff --git a/src/v8/inspector/channel.rs b/src/v8/inspector/channel.rs index 831d623d..06c5536c 100644 --- a/src/v8/inspector/channel.rs +++ b/src/v8/inspector/channel.rs @@ -39,7 +39,7 @@ pub unsafe extern "C" fn v8_inspector__V8Inspector__Channel__BASE__sendResponse( this: &mut Channel, callId: int, message: UniquePtr, -) -> () { +) { ChannelBase::dispatch_mut(this).sendResponse(callId, message) } @@ -47,14 +47,14 @@ pub unsafe extern "C" fn v8_inspector__V8Inspector__Channel__BASE__sendResponse( pub unsafe extern "C" fn v8_inspector__V8Inspector__Channel__BASE__sendNotification( this: &mut Channel, message: UniquePtr, -) -> () { +) { ChannelBase::dispatch_mut(this).sendNotification(message) } #[no_mangle] pub unsafe extern "C" fn v8_inspector__V8Inspector__Channel__BASE__flushProtocolNotifications( this: &mut Channel, -) -> () { +) { ChannelBase::dispatch_mut(this).flushProtocolNotifications() } @@ -68,17 +68,17 @@ impl Channel { &mut self, callId: int, message: UniquePtr, - ) -> () { + ) { unsafe { v8_inspector__V8Inspector__Channel__sendResponse(self, callId, message) } } - pub fn sendNotification(&mut self, message: UniquePtr) -> () { + pub fn sendNotification(&mut self, message: UniquePtr) { unsafe { v8_inspector__V8Inspector__Channel__sendNotification(self, message) } } - pub fn flushProtocolNotifications(&mut self) -> () { + pub fn flushProtocolNotifications(&mut self) { unsafe { v8_inspector__V8Inspector__Channel__flushProtocolNotifications(self) } diff --git a/src/v8/inspector/client.rs b/src/v8/inspector/client.rs index 1113f4d6..e2c67647 100644 --- a/src/v8/inspector/client.rs +++ b/src/v8/inspector/client.rs @@ -88,14 +88,14 @@ extern "C" { pub unsafe extern "C" fn v8_inspector__V8InspectorClient__BASE__runMessageLoopOnPause( this: &mut Client, contextGroupId: int, -) -> () { +) { ClientBase::dispatch_mut(this).runMessageLoopOnPause(contextGroupId) } #[no_mangle] pub unsafe extern "C" fn v8_inspector__V8InspectorClient__BASE__quitMessageLoopOnPause( this: &mut Client, -) -> () { +) { ClientBase::dispatch_mut(this).quitMessageLoopOnPause() } @@ -103,7 +103,7 @@ pub unsafe extern "C" fn v8_inspector__V8InspectorClient__BASE__quitMessageLoopO pub unsafe extern "C" fn v8_inspector__V8InspectorClient__BASE__runIfWaitingForDebugger( this: &mut Client, contextGroupId: int, -) -> () { +) { ClientBase::dispatch_mut(this).runIfWaitingForDebugger(contextGroupId) } @@ -113,7 +113,7 @@ pub struct Client { } impl Client { - pub fn runMessageLoopOnPause(&mut self, contextGroupId: int) -> () { + pub fn runMessageLoopOnPause(&mut self, contextGroupId: int) { unsafe { v8_inspector__V8InspectorClient__runMessageLoopOnPause( self, @@ -121,10 +121,10 @@ impl Client { ) } } - pub fn quitMessageLoopOnPause(&mut self) -> () { + pub fn quitMessageLoopOnPause(&mut self) { unsafe { v8_inspector__V8InspectorClient__quitMessageLoopOnPause(self) } } - pub fn runIfWaitingForDebugger(&mut self, contextGroupId: int) -> () { + pub fn runIfWaitingForDebugger(&mut self, contextGroupId: int) { unsafe { v8_inspector__V8InspectorClient__runIfWaitingForDebugger( self, @@ -165,9 +165,9 @@ pub trait ClientImpl: AsClient { fn base(&self) -> &ClientBase; fn base_mut(&mut self) -> &mut ClientBase; - fn runMessageLoopOnPause(&mut self, contextGroupId: int) -> () {} - fn quitMessageLoopOnPause(&mut self) -> () {} - fn runIfWaitingForDebugger(&mut self, contextGroupId: int) -> () {} + fn runMessageLoopOnPause(&mut self, contextGroupId: int) {} + fn quitMessageLoopOnPause(&mut self) {} + fn runIfWaitingForDebugger(&mut self, contextGroupId: int) {} } pub struct ClientBase { diff --git a/src/v8/platform/task.rs b/src/v8/platform/task.rs index 13e1aa42..83b1816b 100644 --- a/src/v8/platform/task.rs +++ b/src/v8/platform/task.rs @@ -21,12 +21,12 @@ extern "C" { } #[no_mangle] -pub unsafe extern "C" fn v8__Task__BASE__DELETE(this: &mut Task) -> () { +pub unsafe extern "C" fn v8__Task__BASE__DELETE(this: &mut Task) { drop(TaskBase::dispatch_box(this)) } #[no_mangle] -pub unsafe extern "C" fn v8__Task__BASE__Run(this: &mut Task) -> () { +pub unsafe extern "C" fn v8__Task__BASE__Run(this: &mut Task) { TaskBase::dispatch_mut(this).Run() } @@ -36,7 +36,7 @@ pub struct Task { } impl Task { - pub fn Run(&mut self) -> () { + pub fn Run(&mut self) { unsafe { v8__Task__Run(self) } } } @@ -161,6 +161,7 @@ impl TaskBase { } } +#[cfg(test)] mod tests { use super::*; use std::sync::atomic::AtomicUsize; @@ -172,7 +173,7 @@ mod tests { // Using repr(C) to preserve field ordering and test that everything works // when the TaskBase field is not the first element of the struct. #[repr(C)] - pub struct TestTask { + struct TestTask { field1: i32, base: TaskBase, field2: f64, @@ -195,7 +196,7 @@ mod tests { fn base_mut(&mut self) -> &mut TaskBase { &mut self.base } - fn Run(&mut self) -> () { + fn Run(&mut self) { RUN_COUNT.fetch_add(1, SeqCst); } } diff --git a/src/v8/string_buffer.rs b/src/v8/string_buffer.rs index e9fa396d..5ef2bfed 100644 --- a/src/v8/string_buffer.rs +++ b/src/v8/string_buffer.rs @@ -44,6 +44,7 @@ impl Delete for StringBuffer { } } +#[cfg(test)] mod tests { use super::*; @@ -51,17 +52,15 @@ mod tests { fn test_string_buffer() { let chars = b"Hello Venus!"; let mut buf = { - let view1 = StringView::from(&chars[..]); - StringBuffer::create(&view1) + let src_view = StringView::from(&chars[..]); + StringBuffer::create(&src_view) }; - let view2 = buf.as_mut().unwrap().string(); + let view = buf.as_mut().unwrap().string(); - let mut count = 0usize; - for (c1, c2) in chars.iter().copied().map(|c| c as u16).zip(view2) { + assert_eq!(chars.len(), view.into_iter().len()); + assert_eq!(chars.len(), view.length()); + for (c1, c2) in chars.iter().copied().map(u16::from).zip(view) { assert_eq!(c1, c2); - count += 1; } - assert_eq!(count, chars.len()); - assert_eq!(count, view2.length()); } } diff --git a/src/v8/string_view.rs b/src/v8/string_view.rs index d986d2cc..e0122750 100644 --- a/src/v8/string_view.rs +++ b/src/v8/string_view.rs @@ -176,7 +176,7 @@ impl<'a: 'b, 'b> Iterator for StringViewIterator<'a, 'b> { fn next(&mut self) -> Option { let result = Some(match self.view { StringView::U16(v) => v.get_at(self.pos)?, - StringView::U8(v) => v.get_at(self.pos)? as u16, + StringView::U8(v) => u16::from(v.get_at(self.pos)?), }); self.pos += 1; result @@ -189,6 +189,7 @@ impl<'a: 'b, 'b> ExactSizeIterator for StringViewIterator<'a, 'b> { } } +#[cfg(test)] mod tests { use super::*; @@ -197,12 +198,10 @@ mod tests { let chars = b"Hello world!"; let view = StringView::from(&chars[..]); - let mut count = 0usize; - for (c1, c2) in chars.iter().copied().map(|c| c as u16).zip(&view) { + assert_eq!(chars.len(), view.into_iter().len()); + assert_eq!(chars.len(), view.length()); + for (c1, c2) in chars.iter().copied().map(u16::from).zip(&view) { assert_eq!(c1, c2); - count += 1; } - assert_eq!(count, chars.len()); - assert_eq!(count, view.length()); } }