From adfe9d249ec872c5d95e806ee4d4e9694699c472 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 14 Aug 2015 00:06:11 +0530 Subject: [PATCH 1/9] Integrate clippy into Servo --- components/plugins/Cargo.toml | 7 +++++++ components/plugins/lib.rs | 13 ++++++++++++- components/servo/Cargo.lock | 6 ++++++ ports/cef/Cargo.lock | 6 ++++++ ports/gonk/Cargo.lock | 6 ++++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/components/plugins/Cargo.toml b/components/plugins/Cargo.toml index 138ce7f9baf..0162a1f5516 100644 --- a/components/plugins/Cargo.toml +++ b/components/plugins/Cargo.toml @@ -11,3 +11,10 @@ plugin = true [dependencies.tenacious] git = "https://github.com/servo/rust-tenacious" +[dependencies.clippy] +git = "https://github.com/Manishearth/rust-clippy" +branch = "servo" +optional = true + +[features] +default = [] diff --git a/components/plugins/lib.rs b/components/plugins/lib.rs index ba64164f9f6..88f702c1c0c 100644 --- a/components/plugins/lib.rs +++ b/components/plugins/lib.rs @@ -21,6 +21,8 @@ extern crate syntax; extern crate rustc; extern crate tenacious; +#[cfg(feature = "clippy")] +extern crate clippy; use rustc::lint::LintPassObject; use rustc::plugin::Registry; @@ -53,10 +55,19 @@ pub fn plugin_registrar(reg: &mut Registry) { reg.register_lint_pass(box lints::unrooted_must_root::UnrootedPass::new() as LintPassObject); reg.register_lint_pass(box lints::privatize::PrivatizePass as LintPassObject); reg.register_lint_pass(box lints::inheritance_integrity::InheritancePass as LintPassObject); - reg.register_lint_pass(box lints::str_to_string::StrToStringPass as LintPassObject); reg.register_lint_pass(box lints::ban::BanPass as LintPassObject); reg.register_lint_pass(box tenacious::TenaciousPass as LintPassObject); reg.register_attribute("must_root".to_string(), Whitelisted); reg.register_attribute("servo_lang".to_string(), Whitelisted); reg.register_attribute("allow_unrooted_interior".to_string(), Whitelisted); + register_clippy(reg); } + +#[cfg(feature = "clippy")] +fn register_clippy(reg: &mut Registry) { + ::clippy::plugin_registrar(reg); +} +#[cfg(not(feature = "clippy"))] +fn register_clippy(reg: &mut Registry) { + reg.register_lint_pass(box lints::str_to_string::StrToStringPass as LintPassObject); +} \ No newline at end of file diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 02a96a64acd..91a40d13482 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -166,6 +166,11 @@ dependencies = [ "winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clippy" +version = "0.0.11" +source = "git+https://github.com/Manishearth/rust-clippy?branch=servo#4d5e15ee6e1061ed7da0a91df3510728cabc0a21" + [[package]] name = "clock_ticks" version = "0.0.6" @@ -1104,6 +1109,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "plugins" version = "0.0.1" dependencies = [ + "clippy 0.0.11 (git+https://github.com/Manishearth/rust-clippy?branch=servo)", "tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)", ] diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 04470eea902..fd9edc59963 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -165,6 +165,11 @@ dependencies = [ "winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clippy" +version = "0.0.11" +source = "git+https://github.com/Manishearth/rust-clippy?branch=servo#4d5e15ee6e1061ed7da0a91df3510728cabc0a21" + [[package]] name = "clock_ticks" version = "0.0.6" @@ -1082,6 +1087,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "plugins" version = "0.0.1" dependencies = [ + "clippy 0.0.11 (git+https://github.com/Manishearth/rust-clippy?branch=servo)", "tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)", ] diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 9e5f5c4d1d8..5f4f0d1493b 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -151,6 +151,11 @@ dependencies = [ "winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clippy" +version = "0.0.11" +source = "git+https://github.com/Manishearth/rust-clippy?branch=servo#4d5e15ee6e1061ed7da0a91df3510728cabc0a21" + [[package]] name = "clock_ticks" version = "0.0.6" @@ -988,6 +993,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "plugins" version = "0.0.1" dependencies = [ + "clippy 0.0.11 (git+https://github.com/Manishearth/rust-clippy?branch=servo)", "tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)", ] From f749881eeac94cccd2c45e65caa5dd2f01ed0ace Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Aug 2015 04:58:30 +0530 Subject: [PATCH 2/9] Eta-reduce some functions in devtools --- components/devtools_traits/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index fa562744a33..b7ef2ebf5c4 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -192,8 +192,8 @@ impl Decodable for Modification { fn decode(d: &mut D) -> Result { d.read_struct("Modification", 2, |d| Ok(Modification { - attributeName: try!(d.read_struct_field("attributeName", 0, |d| Decodable::decode(d))), - newValue: match d.read_struct_field("newValue", 1, |d| Decodable::decode(d)) { + attributeName: try!(d.read_struct_field("attributeName", 0, Decodable::decode)), + newValue: match d.read_struct_field("newValue", 1, Decodable::decode) { Ok(opt) => opt, Err(_) => None } From 94cd004c286b05c31ea56144d94b257e550947db Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Aug 2015 04:45:12 +0530 Subject: [PATCH 3/9] Cleanup script_task --- components/script/script_task.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 60d8887484c..8d342a9eaf5 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -267,7 +267,7 @@ pub struct SendableMainThreadScriptChan(pub Sender); impl ScriptChan for SendableMainThreadScriptChan { fn send(&self, msg: CommonScriptMsg) -> Result<(), ()> { let SendableMainThreadScriptChan(ref chan) = *self; - return chan.send(msg).map_err(|_| ()); + chan.send(msg).map_err(|_| ()) } fn clone(&self) -> Box { @@ -550,7 +550,7 @@ unsafe extern "C" fn debug_gc_callback(_rt: *mut JSRuntime, status: JSGCStatus, unsafe extern "C" fn shadow_check_callback(_cx: *mut JSContext, _object: HandleObject, _id: HandleId) -> DOMProxyShadowsResult { // XXX implement me - return DOMProxyShadowsResult::ShadowCheckFailed; + DOMProxyShadowsResult::ShadowCheckFailed } impl ScriptTask { @@ -1062,7 +1062,7 @@ impl ScriptTask { return ScriptState::DocumentLoading; } - return ScriptState::DocumentLoaded; + ScriptState::DocumentLoaded } fn handle_new_layout(&self, new_layout_info: NewLayoutInfo) { @@ -1406,7 +1406,7 @@ impl ScriptTask { if let Some(ref mut child_page) = page.remove(id) { shut_down_layout(&*child_page, exit_type); } - return false; + false } /// Handles when layout task finishes all animation in one tick @@ -1550,7 +1550,7 @@ impl ScriptTask { DocumentSource::FromParser, loader); - let frame_element = frame_element.r().map(|elem| ElementCast::from_ref(elem)); + let frame_element = frame_element.r().map(ElementCast::from_ref); window.r().init_browsing_context(document.r(), frame_element); // Create the root frame From b21df4844c60dc0bcbf5e427be1431003ce2fbce Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Aug 2015 04:53:43 +0530 Subject: [PATCH 4/9] Cleanup node.rs --- components/script/dom/node.rs | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 72855380540..bc5af4af038 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -264,7 +264,7 @@ impl LayoutDataRef { /// Borrows the layout data immutably. This function is *not* thread-safe. #[inline] - pub fn borrow<'a>(&'a self) -> Ref<'a, Option> { + pub fn borrow(&self) -> Ref> { debug_assert!(task_state::get().is_layout()); self.data_cell.borrow() } @@ -275,7 +275,7 @@ impl LayoutDataRef { /// prevent CSS selector matching from mutably accessing nodes it's not supposed to and racing /// on it. This has already resulted in one bug! #[inline] - pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, Option> { + pub fn borrow_mut(self) -> RefMut> { debug_assert!(task_state::get().is_layout()); self.data_cell.borrow_mut() } @@ -908,7 +908,7 @@ impl<'a> NodeHelpers for &'a Node { // Step 1. match parse_author_origin_selector_list_from_str(&selectors) { // Step 2. - Err(()) => return Err(Syntax), + Err(()) => Err(Syntax), // Step 3. Ok(ref selectors) => { let root = self.ancestors().last(); @@ -1326,7 +1326,7 @@ impl Iterator for FollowingNodeIterator { } } self.current = None; - return None + None } } @@ -1372,7 +1372,7 @@ impl Iterator for PrecedingNodeIterator { } self.current = None; - return None + None } } @@ -1663,7 +1663,7 @@ impl Node { Node::insert(node, parent, reference_child, SuppressObserver::Unsuppressed); // Step 6. - return Ok(Root::from_ref(node)) + Ok(Root::from_ref(node)) } // https://dom.spec.whatwg.org/#concept-node-insert @@ -2088,24 +2088,18 @@ impl<'a> NodeMethods for &'a Node { // https://dom.spec.whatwg.org/#dom-node-nodevalue fn GetNodeValue(self) -> Option { - match self.type_id { - NodeTypeId::CharacterData(..) => { - let chardata: &CharacterData = CharacterDataCast::to_ref(self).unwrap(); - Some(chardata.Data()) - } - _ => { - None - } + if let NodeTypeId::CharacterData(..) = self.type_id { + let chardata: &CharacterData = CharacterDataCast::to_ref(self).unwrap(); + Some(chardata.Data()) + } else { + None } } // https://dom.spec.whatwg.org/#dom-node-nodevalue fn SetNodeValue(self, val: Option) { - match self.type_id { - NodeTypeId::CharacterData(..) => { - self.SetTextContent(val) - } - _ => {} + if let NodeTypeId::CharacterData(..) = self.type_id { + self.SetTextContent(val) } } @@ -2565,7 +2559,7 @@ pub fn window_from_node(derived: &T) -> Root } impl<'a> VirtualMethods for &'a Node { - fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> { + fn super_type(&self) -> Option<&VirtualMethods> { let eventtarget: &&EventTarget = EventTargetCast::from_borrowed_ref(self); Some(eventtarget as &VirtualMethods) } From 53e155e8ac62c4ce2f2e2bd930b15ecebd41465e Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Aug 2015 05:04:23 +0530 Subject: [PATCH 5/9] Cleanup treewalker --- components/script/dom/treewalker.rs | 56 +++++++++++------------------ 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/components/script/dom/treewalker.rs b/components/script/dom/treewalker.rs index b859a2f0277..0c8e6065709 100644 --- a/components/script/dom/treewalker.rs +++ b/components/script/dom/treewalker.rs @@ -104,12 +104,9 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { node = n; // "2. If node is not null and filtering node returns FILTER_ACCEPT, // then set the currentNode attribute to node, return node." - match try!(self.accept_node(node.r())) { - NodeFilterConstants::FILTER_ACCEPT => { - self.current_node.set(JS::from_rooted(&node)); - return Ok(Some(node)) - }, - _ => {} + if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) { + self.current_node.set(JS::from_rooted(&node)); + return Ok(Some(node)) } }, None => break, @@ -195,12 +192,9 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { } // "5. Filter node and if the return value is FILTER_ACCEPT, then // set the currentNode attribute to node and return node." - match try!(self.accept_node(node.r())) { - NodeFilterConstants::FILTER_ACCEPT => { - self.current_node.set(JS::from_rooted(&node)); - return Ok(Some(node)) - }, - _ => {} + if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) { + self.current_node.set(JS::from_rooted(&node)); + return Ok(Some(node)) } } // "6. Return null." @@ -217,9 +211,8 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { loop { // "1. While result is not FILTER_REJECT and node has a child, run these subsubsteps:" loop { - match result { - NodeFilterConstants::FILTER_REJECT => break, - _ => {} + if let NodeFilterConstants::FILTER_REJECT = result { + break; } match node.r().GetFirstChild() { None => break, @@ -230,12 +223,9 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { result = try!(self.accept_node(node.r())); // "3. If result is FILTER_ACCEPT, then // set the currentNode attribute to node and return node." - match result { - NodeFilterConstants::FILTER_ACCEPT => { - self.current_node.set(JS::from_rooted(&node)); - return Ok(Some(node)) - }, - _ => {} + if let NodeFilterConstants::FILTER_ACCEPT = result { + self.current_node.set(JS::from_rooted(&node)); + return Ok(Some(node)) } } } @@ -251,12 +241,9 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { result = try!(self.accept_node(node.r())); // "4. If result is FILTER_ACCEPT, then // set the currentNode attribute to node and return node." - match result { - NodeFilterConstants::FILTER_ACCEPT => { - self.current_node.set(JS::from_rooted(&node)); - return Ok(Some(node)) - }, - _ => {} + if let NodeFilterConstants::FILTER_ACCEPT = result { + self.current_node.set(JS::from_rooted(&node)); + return Ok(Some(node)) } } } @@ -391,13 +378,11 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker { let result = try!(self.accept_node(node.r())); // "3. If result is FILTER_ACCEPT, then set the currentNode // attribute to node and return node." - match result { - NodeFilterConstants::FILTER_ACCEPT => { - self.current_node.set(JS::from_rooted(&node)); - return Ok(Some(node)) - }, - _ => {} + if let NodeFilterConstants::FILTER_ACCEPT = result { + self.current_node.set(JS::from_rooted(&node)); + return Ok(Some(node)) } + // "4. Set sibling to node's first child if type is next, // and node's last child if type is previous." sibling_op = next_child(node.r()); @@ -418,9 +403,8 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker { // "5. Filter node and if the return value is FILTER_ACCEPT, then return null." Some(n) => { node = n; - match try!(self.accept_node(node.r())) { - NodeFilterConstants::FILTER_ACCEPT => return Ok(None), - _ => {} + if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) { + return Ok(None) } } } From ac1b7a3896c5e05d9ae0af71fc3c82e73c9a05f4 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Aug 2015 05:06:21 +0530 Subject: [PATCH 6/9] Cleanup textinput, timers --- components/script/textinput.rs | 7 ++++--- components/script/timers.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 31fc7dc2e25..5ecf6a4f312 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -292,10 +292,11 @@ impl TextInput { /// Deal with a newline input. pub fn handle_return(&mut self) -> KeyReaction { if !self.multiline { - return KeyReaction::TriggerDefaultAction; + KeyReaction::TriggerDefaultAction + } else { + self.insert_char('\n'); + KeyReaction::DispatchInput } - self.insert_char('\n'); - return KeyReaction::DispatchInput; } /// Select all text in the input control. diff --git a/components/script/timers.rs b/components/script/timers.rs index 579c0d9a2c3..8cc317f83ac 100644 --- a/components/script/timers.rs +++ b/components/script/timers.rs @@ -222,8 +222,8 @@ impl TimerManager { for _ in 0..arguments.len() { timer.data.args.push(Heap::default()); } - for i in 0..arguments.len() { - timer.data.args.get_mut(i).unwrap().set(arguments[i].get()); + for (i, item) in arguments.iter().enumerate() { + timer.data.args.get_mut(i).unwrap().set(item.get()); } handle } From 5c4f91c0f1a94335d3903cb11c21c8bf1770f596 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Aug 2015 05:09:00 +0530 Subject: [PATCH 7/9] Cleanup Window, XHR --- components/script/dom/window.rs | 8 +++---- components/script/dom/xmlhttprequest.rs | 22 +++++++++---------- .../script/dom/xmlhttprequesteventtarget.rs | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 43e4ca6e642..82e3247dc8e 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -269,19 +269,19 @@ impl Window { (box SendableMainThreadScriptChan(tx), box rx) } - pub fn image_cache_task<'a>(&'a self) -> &'a ImageCacheTask { + pub fn image_cache_task(&self) -> &ImageCacheTask { &self.image_cache_task } - pub fn compositor<'a>(&'a self) -> &'a IpcSender { + pub fn compositor(&self) -> &IpcSender { &self.compositor } - pub fn browsing_context<'a>(&'a self) -> Ref<'a, Option> { + pub fn browsing_context(&self) -> Ref> { self.browsing_context.borrow() } - pub fn page<'a>(&'a self) -> &'a Page { + pub fn page(&self) -> &Page { &*self.page } diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index e28482e3f16..577416fe700 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -784,19 +784,17 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { fn process_headers_available(self, cors_request: Option, gen_id: GenerationId, metadata: Metadata) -> Result<(), Error> { - match cors_request { - Some(ref req) => { - match metadata.headers { - Some(ref h) if allow_cross_origin_request(req, h) => {}, - _ => { - self.process_partial_response(XHRProgress::Errored(gen_id, Network)); - return Err(Network); - } - } - }, - _ => {} - }; + if let Some(ref req) = cors_request { + match metadata.headers { + Some(ref h) if allow_cross_origin_request(req, h) => {}, + _ => { + self.process_partial_response(XHRProgress::Errored(gen_id, Network)); + return Err(Network); + } + } + } + // XXXManishearth Clear cache entries in case of a network error self.process_partial_response(XHRProgress::HeadersReceived(gen_id, metadata.headers, diff --git a/components/script/dom/xmlhttprequesteventtarget.rs b/components/script/dom/xmlhttprequesteventtarget.rs index d93746fed0f..3bf1aa408b0 100644 --- a/components/script/dom/xmlhttprequesteventtarget.rs +++ b/components/script/dom/xmlhttprequesteventtarget.rs @@ -28,7 +28,7 @@ impl XMLHttpRequestEventTarget { } #[inline] - pub fn eventtarget<'a>(&'a self) -> &'a EventTarget { + pub fn eventtarget(&self) -> &EventTarget { &self.eventtarget } } From a53b86f1073a1c7d331cfc7630d01a5687790307 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Aug 2015 05:16:39 +0530 Subject: [PATCH 8/9] Cleanup WebGLRenderingContext, Websocker, WorkerGlobalScope --- components/script/dom/webglrenderingcontext.rs | 14 ++++++-------- components/script/dom/websocket.rs | 2 +- components/script/dom/workerglobalscope.rs | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 0b6fa7b3869..4acf36256c8 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -514,15 +514,13 @@ impl<'a> WebGLRenderingContextMethods for &'a WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn VertexAttribPointer(self, attrib_id: u32, size: i32, data_type: u32, normalized: bool, stride: i32, offset: i64) { - match data_type { - constants::FLOAT => { - let msg = CanvasMsg::WebGL( - CanvasWebGLMsg::VertexAttribPointer2f(attrib_id, size, normalized, stride, offset)); - self.ipc_renderer.send(msg).unwrap() - } - _ => panic!("VertexAttribPointer: Data Type not supported") + if let constants::FLOAT = data_type { + let msg = CanvasMsg::WebGL( + CanvasWebGLMsg::VertexAttribPointer2f(attrib_id, size, normalized, stride, offset)); + self.ipc_renderer.send(msg).unwrap() + } else { + panic!("VertexAttribPointer: Data Type not supported") } - } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.4 diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 7855c3e453b..1e00a9e507a 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -277,7 +277,7 @@ impl<'a> WebSocketMethods for &'a WebSocket { let mut other_sender = self.sender.borrow_mut(); let my_sender = other_sender.as_mut().unwrap(); let _ = my_sender.lock().unwrap().send_message(Message::Text(data.unwrap().0)); - return Ok(()) + Ok(()) } // https://html.spec.whatwg.org/multipage/#dom-websocket-close diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 70477846627..468de091271 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -143,11 +143,11 @@ impl WorkerGlobalScope { self.runtime.cx() } - pub fn resource_task<'a>(&'a self) -> &'a ResourceTask { + pub fn resource_task(&self) -> &ResourceTask { &self.resource_task } - pub fn get_url<'a>(&'a self) -> &'a Url { + pub fn get_url(&self) -> &Url { &self.worker_url } From 19241c95f7b2aa0c781de54b5fba0913b5614b4d Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 15 Aug 2015 05:32:51 +0530 Subject: [PATCH 9/9] Cleanup NodeIterator, Range, ServoHTMLParser, TextEncoder, URLHelper, URL, VirtualMethods --- components/plugins/lib.rs | 2 +- components/script/dom/node.rs | 9 ++------- components/script/dom/nodeiterator.rs | 4 ++-- components/script/dom/range.rs | 18 ++++++------------ components/script/dom/servohtmlparser.rs | 2 +- components/script/dom/textencoder.rs | 4 ++-- components/script/dom/treewalker.rs | 14 +++++++------- components/script/dom/url.rs | 2 +- components/script/dom/urlhelper.rs | 2 +- components/script/dom/virtualmethods.rs | 2 +- components/servo/Cargo.lock | 6 ------ ports/cef/Cargo.lock | 6 ------ ports/gonk/Cargo.lock | 6 ------ 13 files changed, 24 insertions(+), 53 deletions(-) diff --git a/components/plugins/lib.rs b/components/plugins/lib.rs index 88f702c1c0c..8b69f2049bb 100644 --- a/components/plugins/lib.rs +++ b/components/plugins/lib.rs @@ -70,4 +70,4 @@ fn register_clippy(reg: &mut Registry) { #[cfg(not(feature = "clippy"))] fn register_clippy(reg: &mut Registry) { reg.register_lint_pass(box lints::str_to_string::StrToStringPass as LintPassObject); -} \ No newline at end of file +} diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index bc5af4af038..6ca62f181e3 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -275,7 +275,7 @@ impl LayoutDataRef { /// prevent CSS selector matching from mutably accessing nodes it's not supposed to and racing /// on it. This has already resulted in one bug! #[inline] - pub fn borrow_mut(self) -> RefMut> { + pub fn borrow_mut(&self) -> RefMut> { debug_assert!(task_state::get().is_layout()); self.data_cell.borrow_mut() } @@ -2088,12 +2088,7 @@ impl<'a> NodeMethods for &'a Node { // https://dom.spec.whatwg.org/#dom-node-nodevalue fn GetNodeValue(self) -> Option { - if let NodeTypeId::CharacterData(..) = self.type_id { - let chardata: &CharacterData = CharacterDataCast::to_ref(self).unwrap(); - Some(chardata.Data()) - } else { - None - } + CharacterDataCast::to_ref(self).map(|c| c.Data()) } // https://dom.spec.whatwg.org/#dom-node-nodevalue diff --git a/components/script/dom/nodeiterator.rs b/components/script/dom/nodeiterator.rs index 7e641c83cfd..0958bfca992 100644 --- a/components/script/dom/nodeiterator.rs +++ b/components/script/dom/nodeiterator.rs @@ -138,7 +138,7 @@ impl<'a> NodeIteratorMethods for &'a NodeIterator { } } - return Ok(None); + Ok(None) } // https://dom.spec.whatwg.org/#dom-nodeiterator-previousnode @@ -183,7 +183,7 @@ impl<'a> NodeIteratorMethods for &'a NodeIterator { } } - return Ok(None); + Ok(None) } // https://dom.spec.whatwg.org/#dom-nodeiterator-detach diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index b67ce2d60c8..78af618eff5 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -122,7 +122,7 @@ impl Range { return Err(HierarchyRequest); } - return Ok((first_contained_child, last_contained_child, contained_children)); + Ok((first_contained_child, last_contained_child, contained_children)) } } @@ -338,17 +338,11 @@ impl<'a> RangeMethods for &'a Range { let end = &inner.end; let end_node = end.node(); let end_offset = end.offset; - match (bp_position(parent.r(), offset + 1, start_node.r(), start_offset).unwrap(), - bp_position(parent.r(), offset, end_node.r(), end_offset).unwrap()) { - (Ordering::Greater, Ordering::Less) => { - // Step 5. - true - }, - _ => { - // Step 6. - false - } - } + // Step 5. + Ordering::Greater == bp_position(parent.r(), offset + 1, + start_node.r(), start_offset).unwrap() && + Ordering::Less == bp_position(parent.r(), offset, + end_node.r(), end_offset).unwrap() } // https://dom.spec.whatwg.org/#dom-range-clonecontents diff --git a/components/script/dom/servohtmlparser.rs b/components/script/dom/servohtmlparser.rs index e979e3f6610..b9ccd50632f 100644 --- a/components/script/dom/servohtmlparser.rs +++ b/components/script/dom/servohtmlparser.rs @@ -268,7 +268,7 @@ impl ServoHTMLParser { } #[inline] - pub fn tokenizer<'a>(&'a self) -> &'a DOMRefCell { + pub fn tokenizer(&self) -> &DOMRefCell { &self.tokenizer } } diff --git a/components/script/dom/textencoder.rs b/components/script/dom/textencoder.rs index 29a715a8ed1..1b76de05d0d 100644 --- a/components/script/dom/textencoder.rs +++ b/components/script/dom/textencoder.rs @@ -65,7 +65,7 @@ impl TextEncoder { } _ => { debug!("Encoding Not UTF"); - return Err(Range("The encoding must be utf-8, utf-16le, or utf-16be.".to_owned())) + Err(Range("The encoding must be utf-8, utf-16le, or utf-16be.".to_owned())) } } } @@ -87,7 +87,7 @@ impl<'a> TextEncoderMethods for &'a TextEncoder { let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object, ptr::null()); ptr::copy_nonoverlapping(encoded.as_ptr(), js_object_data, length as usize); - return js_object; + js_object } } } diff --git a/components/script/dom/treewalker.rs b/components/script/dom/treewalker.rs index 0c8e6065709..b8271909505 100644 --- a/components/script/dom/treewalker.rs +++ b/components/script/dom/treewalker.rs @@ -104,7 +104,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { node = n; // "2. If node is not null and filtering node returns FILTER_ACCEPT, // then set the currentNode attribute to node, return node." - if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) { + if NodeFilterConstants::FILTER_ACCEPT == try!(self.accept_node(node.r())) { self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node)) } @@ -192,7 +192,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { } // "5. Filter node and if the return value is FILTER_ACCEPT, then // set the currentNode attribute to node and return node." - if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) { + if NodeFilterConstants::FILTER_ACCEPT == try!(self.accept_node(node.r())) { self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node)) } @@ -211,7 +211,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { loop { // "1. While result is not FILTER_REJECT and node has a child, run these subsubsteps:" loop { - if let NodeFilterConstants::FILTER_REJECT = result { + if NodeFilterConstants::FILTER_REJECT == result { break; } match node.r().GetFirstChild() { @@ -223,7 +223,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { result = try!(self.accept_node(node.r())); // "3. If result is FILTER_ACCEPT, then // set the currentNode attribute to node and return node." - if let NodeFilterConstants::FILTER_ACCEPT = result { + if NodeFilterConstants::FILTER_ACCEPT == result { self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node)) } @@ -241,7 +241,7 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { result = try!(self.accept_node(node.r())); // "4. If result is FILTER_ACCEPT, then // set the currentNode attribute to node and return node." - if let NodeFilterConstants::FILTER_ACCEPT = result { + if NodeFilterConstants::FILTER_ACCEPT == result { self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node)) } @@ -378,7 +378,7 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker { let result = try!(self.accept_node(node.r())); // "3. If result is FILTER_ACCEPT, then set the currentNode // attribute to node and return node." - if let NodeFilterConstants::FILTER_ACCEPT = result { + if NodeFilterConstants::FILTER_ACCEPT == result { self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node)) } @@ -403,7 +403,7 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker { // "5. Filter node and if the return value is FILTER_ACCEPT, then return null." Some(n) => { node = n; - if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) { + if NodeFilterConstants::FILTER_ACCEPT == try!(self.accept_node(node.r())) { return Ok(None) } } diff --git a/components/script/dom/url.rs b/components/script/dom/url.rs index 9bbd0f1b5fc..d4a8b5a23ff 100644 --- a/components/script/dom/url.rs +++ b/components/script/dom/url.rs @@ -142,7 +142,7 @@ impl<'a> URLMethods for &'a URL { } } -fn parser_with_base<'a>(base: Option<&'a Url>) -> UrlParser<'a> { +fn parser_with_base(base: Option<&Url>) -> UrlParser { let mut parser = UrlParser::new(); if let Some(base) = base { parser.base_url(base); diff --git a/components/script/dom/urlhelper.rs b/components/script/dom/urlhelper.rs index cff468574b2..4376a85e390 100644 --- a/components/script/dom/urlhelper.rs +++ b/components/script/dom/urlhelper.rs @@ -84,7 +84,7 @@ impl UrlHelper { if urlA.port() != urlB.port() { return false } - return true + true } // https://url.spec.whatwg.org/#dom-urlutils-search diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index b67cbb69d4f..437f39422c6 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -48,7 +48,7 @@ use string_cache::Atom; pub trait VirtualMethods { /// Returns self as the superclass of the implementation for this trait, /// if any. - fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods>; + fn super_type(&self) -> Option<&VirtualMethods>; /// Called when changing or adding attributes, after the attribute's value /// has been updated. diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 91a40d13482..02a96a64acd 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -166,11 +166,6 @@ dependencies = [ "winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "clippy" -version = "0.0.11" -source = "git+https://github.com/Manishearth/rust-clippy?branch=servo#4d5e15ee6e1061ed7da0a91df3510728cabc0a21" - [[package]] name = "clock_ticks" version = "0.0.6" @@ -1109,7 +1104,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "plugins" version = "0.0.1" dependencies = [ - "clippy 0.0.11 (git+https://github.com/Manishearth/rust-clippy?branch=servo)", "tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)", ] diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index fd9edc59963..04470eea902 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -165,11 +165,6 @@ dependencies = [ "winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "clippy" -version = "0.0.11" -source = "git+https://github.com/Manishearth/rust-clippy?branch=servo#4d5e15ee6e1061ed7da0a91df3510728cabc0a21" - [[package]] name = "clock_ticks" version = "0.0.6" @@ -1087,7 +1082,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "plugins" version = "0.0.1" dependencies = [ - "clippy 0.0.11 (git+https://github.com/Manishearth/rust-clippy?branch=servo)", "tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)", ] diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 5f4f0d1493b..9e5f5c4d1d8 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -151,11 +151,6 @@ dependencies = [ "winapi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "clippy" -version = "0.0.11" -source = "git+https://github.com/Manishearth/rust-clippy?branch=servo#4d5e15ee6e1061ed7da0a91df3510728cabc0a21" - [[package]] name = "clock_ticks" version = "0.0.6" @@ -993,7 +988,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "plugins" version = "0.0.1" dependencies = [ - "clippy 0.0.11 (git+https://github.com/Manishearth/rust-clippy?branch=servo)", "tenacious 0.0.9 (git+https://github.com/servo/rust-tenacious)", ]