diff --git a/html5ever/examples/tokenize.rs b/html5ever/examples/tokenize.rs index 094c1bee..912a6ce6 100644 --- a/html5ever/examples/tokenize.rs +++ b/html5ever/examples/tokenize.rs @@ -85,7 +85,9 @@ impl TokenSink for TokenPrinter { /// In this example we implement the TokenSink trait in such a way that each token is printed. /// If a there's an error while processing a token it is printed as well. fn main() { - let sink = TokenPrinter { in_char_run: Cell::new(false) }; + let sink = TokenPrinter { + in_char_run: Cell::new(false), + }; // Read HTML from standard input let mut chunk = ByteTendril::new(); diff --git a/html5ever/src/driver.rs b/html5ever/src/driver.rs index b178c469..af2bfdbd 100644 --- a/html5ever/src/driver.rs +++ b/html5ever/src/driver.rs @@ -116,7 +116,7 @@ impl TendrilSink for Parser { type Output = Sink::Output; - fn finish(mut self) -> Self::Output { + fn finish(self) -> Self::Output { // FIXME: Properly support somehow. while let TokenizerResult::Script(_) = self.tokenizer.feed(&self.input_buffer) {} assert!(self.input_buffer.is_empty()); diff --git a/html5ever/src/macros.rs b/html5ever/src/macros.rs index 4d4e422c..a220a940 100644 --- a/html5ever/src/macros.rs +++ b/html5ever/src/macros.rs @@ -8,12 +8,10 @@ // except according to those terms. macro_rules! unwrap_or_else { - ($opt:expr, $else_block:block) => { - { - let Some(x) = $opt else { $else_block }; - x - } - }; + ($opt:expr, $else_block:block) => {{ + let Some(x) = $opt else { $else_block }; + x + }}; } macro_rules! unwrap_or_return { diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index f4b3d5e4..59e417e1 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -288,7 +288,6 @@ impl Tokenizer { if self.reconsume.get() { self.reconsume.set(false); Some(self.current_char.get()) - } else { input .next() @@ -321,12 +320,7 @@ impl Tokenizer { // BufferQueue::eat. // // NB: this doesn't set the current input character. - fn eat( - &self, - input: &BufferQueue, - pat: &str, - eq: fn(&u8, &u8) -> bool, - ) -> Option { + fn eat(&self, input: &BufferQueue, pat: &str, eq: fn(&u8, &u8) -> bool) -> Option { if self.ignore_lf.get() { self.ignore_lf.set(false); if self.peek(input) == Some('\n') { @@ -491,7 +485,10 @@ impl Tokenizer { fn have_appropriate_end_tag(&self) -> bool { match self.last_start_tag_name.borrow().as_ref() { - Some(last) => (self.current_tag_kind.get() == EndTag) && (**self.current_tag_name.borrow() == **last), + Some(last) => { + (self.current_tag_kind.get() == EndTag) + && (**self.current_tag_name.borrow() == **last) + }, None => false, } } @@ -1469,8 +1466,12 @@ impl Tokenizer { } fn dump_profile(&self) { - let mut results: Vec<(states::State, u64)> = - self.state_profile.borrow().iter().map(|(s, t)| (*s, *t)).collect(); + let mut results: Vec<(states::State, u64)> = self + .state_profile + .borrow() + .iter() + .map(|(s, t)| (*s, *t)) + .collect(); results.sort_by(|&(_, x), &(_, y)| y.cmp(&x)); let total: u64 = results @@ -1478,7 +1479,10 @@ impl Tokenizer { .map(|&(_, t)| t) .fold(0, ::std::ops::Add::add); println!("\nTokenizer profile, in nanoseconds"); - println!("\n{:12} total in token sink", self.time_in_sink.get()); + println!( + "\n{:12} total in token sink", + self.time_in_sink.get() + ); println!("\n{:12} total in tokenizer", total); for (k, v) in results.into_iter() { @@ -1629,11 +1633,7 @@ mod test { impl TokenSink for LinesMatch { type Handle = (); - fn process_token( - &self, - token: Token, - line_number: u64, - ) -> TokenSinkResult { + fn process_token(&self, token: Token, line_number: u64) -> TokenSinkResult { match token { CharacterTokens(b) => { self.current_str.borrow_mut().push_slice(&b); diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs index 8f57fa68..fa1a3b9d 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -25,7 +25,7 @@ use crate::tokenizer::states as tok_state; use crate::tokenizer::{Doctype, EndTag, StartTag, Tag, TokenSink, TokenSinkResult}; use std::borrow::Cow::Borrowed; -use std::cell::{Cell, RefCell, Ref, RefMut}; +use std::cell::{Cell, Ref, RefCell, RefMut}; use std::collections::VecDeque; use std::iter::{Enumerate, Rev}; use std::mem; @@ -274,9 +274,18 @@ where _ => (), } } - self.head_elem.borrow().as_ref().map(|h| tracer.trace_handle(h)); - self.form_elem.borrow().as_ref().map(|h| tracer.trace_handle(h)); - self.context_elem.borrow().as_ref().map(|h| tracer.trace_handle(h)); + self.head_elem + .borrow() + .as_ref() + .map(|h| tracer.trace_handle(h)); + self.form_elem + .borrow() + .as_ref() + .map(|h| tracer.trace_handle(h)); + self.context_elem + .borrow() + .as_ref() + .map(|h| tracer.trace_handle(h)); } #[allow(dead_code)] @@ -451,11 +460,7 @@ where { type Handle = Handle; - fn process_token( - &self, - token: tokenizer::Token, - line_number: u64, - ) -> TokenSinkResult { + fn process_token(&self, token: tokenizer::Token, line_number: u64) -> TokenSinkResult { if line_number != self.current_line.get() { self.sink.set_current_line(line_number); } @@ -546,10 +551,10 @@ struct ActiveFormattingView<'a, Handle: 'a> { data: Ref<'a, Vec>>, } -impl <'a, Handle: 'a> ActiveFormattingView<'a, Handle> { +impl<'a, Handle: 'a> ActiveFormattingView<'a, Handle> { fn iter(&'a self) -> impl Iterator + 'a { ActiveFormattingIter { - iter: self.data.iter().enumerate().rev() + iter: self.data.iter().enumerate().rev(), } } } @@ -625,10 +630,13 @@ where } fn position_in_active_formatting(&self, element: &Handle) -> Option { - self.active_formatting.borrow().iter().position(|n| match n { - &Marker => false, - &Element(ref handle, _) => self.sink.same_node(handle, element), - }) + self.active_formatting + .borrow() + .iter() + .position(|n| match n { + &Marker => false, + &Element(ref handle, _) => self.sink.same_node(handle, element), + }) } fn set_quirks_mode(&self, mode: QuirksMode) { @@ -659,7 +667,9 @@ where //ยง END fn current_node(&self) -> Ref { - Ref::map(self.open_elems.borrow(), |elems| elems.last().expect("no current element")) + Ref::map(self.open_elems.borrow(), |elems| { + elems.last().expect("no current element") + }) } fn adjusted_current_node(&self) -> Ref { @@ -819,7 +829,8 @@ where tag.attrs.clone(), ); self.open_elems.borrow_mut()[node_index] = new_element.clone(); - self.active_formatting.borrow_mut()[node_formatting_index] = Element(new_element.clone(), tag); + self.active_formatting.borrow_mut()[node_formatting_index] = + Element(new_element.clone(), tag); node = new_element; // 13.8. @@ -902,7 +913,11 @@ where } fn pop(&self) -> Handle { - let elem = self.open_elems.borrow_mut().pop().expect("no current element"); + let elem = self + .open_elems + .borrow_mut() + .pop() + .expect("no current element"); self.sink.pop(&elem); elem } @@ -1386,7 +1401,9 @@ where } let elem = self.insert_element(Push, ns!(html), tag.name.clone(), tag.attrs.clone()); - self.active_formatting.borrow_mut().push(Element(elem.clone(), tag)); + self.active_formatting + .borrow_mut() + .push(Element(elem.clone(), tag)); elem } @@ -1671,7 +1688,11 @@ where } fn foreign_start_tag(&self, mut tag: Tag) -> ProcessResult { - let current_ns = self.sink.elem_name(&self.adjusted_current_node()).ns.clone(); + let current_ns = self + .sink + .elem_name(&self.adjusted_current_node()) + .ns + .clone(); match current_ns { ns!(mathml) => self.adjust_mathml_attributes(&mut tag), ns!(svg) => { diff --git a/markup5ever/util/buffer_queue.rs b/markup5ever/util/buffer_queue.rs index 75ca96c2..95a571e2 100644 --- a/markup5ever/util/buffer_queue.rs +++ b/markup5ever/util/buffer_queue.rs @@ -241,7 +241,10 @@ impl BufferQueue { } pub fn swap_with(&self, other: &BufferQueue) { - mem::swap(&mut *self.buffers.borrow_mut(), &mut *other.buffers.borrow_mut()); + mem::swap( + &mut *self.buffers.borrow_mut(), + &mut *other.buffers.borrow_mut(), + ); } } diff --git a/rcdom/lib.rs b/rcdom/lib.rs index b9b1ede1..45553cc1 100644 --- a/rcdom/lib.rs +++ b/rcdom/lib.rs @@ -264,12 +264,7 @@ impl TreeSink for RcDom { }; } - fn create_element( - &self, - name: QualName, - attrs: Vec, - flags: ElementFlags, - ) -> Handle { + fn create_element(&self, name: QualName, attrs: Vec, flags: ElementFlags) -> Handle { Node::new(NodeData::Element { name, attrs: RefCell::new(attrs), diff --git a/rcdom/tests/html-tree-sink.rs b/rcdom/tests/html-tree-sink.rs index c2c804fd..c5d05ae2 100644 --- a/rcdom/tests/html-tree-sink.rs +++ b/rcdom/tests/html-tree-sink.rs @@ -48,13 +48,10 @@ impl TreeSink for LineCountingDOM { self.rcdom.elem_name(target) } - fn create_element( - &self, - name: QualName, - attrs: Vec, - flags: ElementFlags, - ) -> Handle { - self.line_vec.borrow_mut().push((name.clone(), self.current_line.get())); + fn create_element(&self, name: QualName, attrs: Vec, flags: ElementFlags) -> Handle { + self.line_vec + .borrow_mut() + .push((name.clone(), self.current_line.get())); self.rcdom.create_element(name, attrs, flags) } diff --git a/rcdom/tests/xml-tokenizer.rs b/rcdom/tests/xml-tokenizer.rs index 683cd2de..5bcc7fcd 100644 --- a/rcdom/tests/xml-tokenizer.rs +++ b/rcdom/tests/xml-tokenizer.rs @@ -10,10 +10,10 @@ use serde_json::{Map, Value}; use std::borrow::Cow::Borrowed; use std::cell::RefCell; +use std::env; use std::ffi::OsStr; use std::io::Read; use std::path::Path; -use std::env; use util::find_tests::foreach_xml5lib_test; use util::runner::Test; diff --git a/xml5ever/examples/xml_tokenizer.rs b/xml5ever/examples/xml_tokenizer.rs index 796d1e9c..2776ed50 100644 --- a/xml5ever/examples/xml_tokenizer.rs +++ b/xml5ever/examples/xml_tokenizer.rs @@ -89,7 +89,9 @@ impl TokenSink for TokenPrinter { } fn main() { - let sink = TokenPrinter { in_char_run: Cell::new(false) }; + let sink = TokenPrinter { + in_char_run: Cell::new(false), + }; let mut input = ByteTendril::new(); io::stdin().read_to_tendril(&mut input).unwrap(); let input_buffer = BufferQueue::default(); diff --git a/xml5ever/src/tokenizer/mod.rs b/xml5ever/src/tokenizer/mod.rs index 2bd0efea..84f296ec 100644 --- a/xml5ever/src/tokenizer/mod.rs +++ b/xml5ever/src/tokenizer/mod.rs @@ -417,7 +417,10 @@ impl XmlTokenizer { fn emit_current_tag(&self) { self.finish_attribute(); - let qname = process_qname(replace(&mut *self.current_tag_name.borrow_mut(), StrTendril::new())); + let qname = process_qname(replace( + &mut *self.current_tag_name.borrow_mut(), + StrTendril::new(), + )); match self.current_tag_kind.get() { StartTag | EmptyTag => {}, @@ -463,7 +466,8 @@ impl XmlTokenizer { fn consume_char_ref(&self, addnl_allowed: Option) { // NB: The char ref tokenizer assumes we have an additional allowed // character iff we're tokenizing in an attribute value. - *self.char_ref_tokenizer.borrow_mut() = Some(Box::new(CharRefTokenizer::new(addnl_allowed))); + *self.char_ref_tokenizer.borrow_mut() = + Some(Box::new(CharRefTokenizer::new(addnl_allowed))); } fn emit_eof(&self) { @@ -1116,8 +1120,12 @@ impl XmlTokenizer { #[cfg(not(for_c))] fn dump_profile(&self) { - let mut results: Vec<(states::XmlState, u64)> = - self.state_profile.borrow().iter().map(|(s, t)| (*s, *t)).collect(); + let mut results: Vec<(states::XmlState, u64)> = self + .state_profile + .borrow() + .iter() + .map(|(s, t)| (*s, *t)) + .collect(); results.sort_by(|&(_, x), &(_, y)| y.cmp(&x)); let total: u64 = results @@ -1125,7 +1133,10 @@ impl XmlTokenizer { .map(|&(_, t)| t) .fold(0, ::std::ops::Add::add); debug!("\nTokenizer profile, in nanoseconds"); - debug!("\n{:12} total in token sink", self.time_in_sink.get()); + debug!( + "\n{:12} total in token sink", + self.time_in_sink.get() + ); debug!("\n{:12} total in tokenizer", total); for (k, v) in results.into_iter() { @@ -1249,7 +1260,10 @@ impl XmlTokenizer { self.current_attr_name.borrow_mut().clear(); self.current_attr_value.borrow_mut().clear(); } else { - let qname = process_qname(replace(&mut self.current_attr_name.borrow_mut(), StrTendril::new())); + let qname = process_qname(replace( + &mut self.current_attr_name.borrow_mut(), + StrTendril::new(), + )); let attr = Attribute { name: qname.clone(), value: replace(&mut self.current_attr_value.borrow_mut(), StrTendril::new()), diff --git a/xml5ever/src/tree_builder/mod.rs b/xml5ever/src/tree_builder/mod.rs index 8c06b219..b76eff0b 100644 --- a/xml5ever/src/tree_builder/mod.rs +++ b/xml5ever/src/tree_builder/mod.rs @@ -14,7 +14,7 @@ use mac::unwrap_or_return; use markup5ever::{local_name, namespace_prefix, namespace_url, ns}; use std::borrow::Cow; use std::borrow::Cow::Borrowed; -use std::cell::{Cell, RefCell, Ref}; +use std::cell::{Cell, Ref, RefCell}; use std::collections::btree_map::Iter; use std::collections::{BTreeMap, HashSet, VecDeque}; use std::fmt::{Debug, Error, Formatter}; @@ -362,7 +362,10 @@ where self.bind_qname(&mut tag.name); // Finally, we dump current namespace if its unneeded. - let x = mem::replace(&mut *self.current_namespace.borrow_mut(), NamespaceMap::empty()); + let x = mem::replace( + &mut *self.current_namespace.borrow_mut(), + NamespaceMap::empty(), + ); // Only start tag doesn't dump current namespace. However,