Skip to content

Commit a7b8acd

Browse files
committed
Clippy
1 parent 4de4170 commit a7b8acd

File tree

7 files changed

+70
-60
lines changed

7 files changed

+70
-60
lines changed

src/common.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,15 @@ pub fn is_whitespace_str(s: &str) -> bool {
133133
/// [1]: http://www.w3.org/TR/2006/REC-xml11-20060816/#sec-common-syn
134134
#[must_use]
135135
pub fn is_name_start_char(c: char) -> bool {
136-
match c {
136+
matches!(c,
137137
':' | 'A'..='Z' | '_' | 'a'..='z' |
138138
'\u{C0}'..='\u{D6}' | '\u{D8}'..='\u{F6}' | '\u{F8}'..='\u{2FF}' |
139139
'\u{370}'..='\u{37D}' | '\u{37F}'..='\u{1FFF}' |
140140
'\u{200C}'..='\u{200D}' | '\u{2070}'..='\u{218F}' |
141141
'\u{2C00}'..='\u{2FEF}' | '\u{3001}'..='\u{D7FF}' |
142142
'\u{F900}'..='\u{FDCF}' | '\u{FDF0}'..='\u{FFFD}' |
143-
'\u{10000}'..='\u{EFFFF}' => true,
144-
_ => false
145-
}
143+
'\u{10000}'..='\u{EFFFF}'
144+
)
146145
}
147146

148147
/// Checks whether the given character is a name character (`NameChar`)
@@ -151,10 +150,11 @@ pub fn is_name_start_char(c: char) -> bool {
151150
/// [1]: http://www.w3.org/TR/2006/REC-xml11-20060816/#sec-common-syn
152151
#[must_use]
153152
pub fn is_name_char(c: char) -> bool {
154-
match c {
155-
_ if is_name_start_char(c) => true,
156-
'-' | '.' | '0'..='9' | '\u{B7}' |
157-
'\u{300}'..='\u{36F}' | '\u{203F}'..='\u{2040}' => true,
158-
_ => false
153+
if is_name_start_char(c) {
154+
return true;
159155
}
156+
matches!(c,
157+
'-' | '.' | '0'..='9' | '\u{B7}' |
158+
'\u{300}'..='\u{36F}' | '\u{203F}'..='\u{2040}'
159+
)
160160
}

src/namespace.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,11 @@ impl Namespace {
9191
// a shortcut for a namespace which is definitely not empty
9292
if self.0.len() > 3 { return false; }
9393

94-
self.0.iter().all(|(k, v)| match (&**k, &**v) {
95-
(NS_NO_PREFIX, NS_EMPTY_URI) => true,
96-
(NS_XMLNS_PREFIX, NS_XMLNS_URI) => true,
97-
(NS_XML_PREFIX, NS_XML_URI) => true,
98-
_ => false
99-
})
94+
self.0.iter().all(|(k, v)| matches!((&**k, &**v),
95+
(NS_NO_PREFIX, NS_EMPTY_URI) |
96+
(NS_XMLNS_PREFIX, NS_XMLNS_URI) |
97+
(NS_XML_PREFIX, NS_XML_URI))
98+
)
10099
}
101100

102101
/// Checks whether this namespace mapping contains the given prefix.
@@ -172,6 +171,11 @@ impl Namespace {
172171
pub fn borrow(&self) -> Cow<'_, Self> {
173172
Cow::Borrowed(self)
174173
}
174+
175+
/// Namespace mappings contained in a namespace.
176+
pub fn iter(&self) -> NamespaceMappings<'_> {
177+
self.into_iter()
178+
}
175179
}
176180

177181
/// An alias for iterator type for namespace mappings contained in a namespace.
@@ -215,6 +219,7 @@ impl NamespaceStack {
215219
/// * `xmlns` → `http://www.w3.org/2000/xmlns/`.
216220
#[inline]
217221
#[must_use]
222+
#[allow(clippy::should_implement_trait)]
218223
pub fn default() -> NamespaceStack {
219224
let mut nst = NamespaceStack::empty();
220225
nst.push_empty();

src/reader/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub struct ParserConfig2 {
227227
impl Default for ParserConfig2 {
228228
fn default() -> Self {
229229
ParserConfig2 {
230-
c: Default::default(),
230+
c: ParserConfig::default(),
231231
override_encoding: None,
232232
ignore_invalid_encoding_declarations: false,
233233
allow_multiple_root_elements: true,

src/reader/lexer.rs

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) enum Token {
2323
ProcessingInstructionStart,
2424
/// `?>`
2525
ProcessingInstructionEnd,
26-
/// `<!DOCTYPE
26+
/// `<!DOCTYPE…`
2727
DoctypeStart,
2828
/// `<`
2929
OpeningTagStart,
@@ -80,7 +80,10 @@ impl fmt::Display for Token {
8080
Token::SingleQuote => "'",
8181
Token::DoubleQuote => "\"",
8282
Token::MarkupDeclarationStart => "<!",
83-
_ => unreachable!()
83+
Token::Character(_) => {
84+
debug_assert!(false);
85+
""
86+
},
8487
}.fmt(f),
8588
}
8689
}
@@ -349,14 +352,15 @@ impl Lexer {
349352
Ok(Some(Token::Character(']'))),
350353
State::InvalidCDataClosing(ClosingSubstate::Second) => {
351354
self.eof_handled = false;
352-
Ok(self.move_to_with_unread(State::Normal, &[']'], Token::Character(']')))
355+
Ok(Some(self.move_to_with_unread(State::Normal, &[']'], Token::Character(']'))))
353356
},
354357
State::Normal =>
355358
Ok(None),
356359
}
357360
}
358361

359362
#[cold]
363+
#[allow(clippy::needless_pass_by_value)]
360364
fn error(&self, e: SyntaxError) -> Error {
361365
Error {
362366
pos: self.position(),
@@ -370,21 +374,21 @@ impl Lexer {
370374
match self.st {
371375
State::Normal => Ok(self.normal(c)),
372376
State::TagStarted => self.tag_opened(c),
373-
State::EmptyTagClosing => Ok(self.empty_element_closing(c)),
377+
State::EmptyTagClosing => Ok(Some(self.empty_element_closing(c))),
374378
State::CommentOrCDataOrDoctypeStarted => self.comment_or_cdata_or_doctype_started(c),
375379
State::InsideCdata => Ok(self.inside_cdata(c)),
376380
State::CDataStarted(s) => self.cdata_started(c, s),
377381
State::InsideComment => Ok(self.inside_comment_state(c)),
378382
State::CommentStarted => self.comment_started(c),
379383
State::InsideProcessingInstruction => Ok(self.inside_processing_instruction(c)),
380-
State::ProcessingInstructionClosing => Ok(self.processing_instruction_closing(c)),
384+
State::ProcessingInstructionClosing => Ok(Some(self.processing_instruction_closing(c))),
381385
State::CommentClosing(s) => self.comment_closing(c, s),
382386
State::CDataClosing(s) => Ok(self.cdata_closing(c, s)),
383387
State::InsideDoctype => Ok(self.inside_doctype(c)),
384388
State::DoctypeStarted(s) => self.doctype_started(c, s),
385389
State::InvalidCDataClosing(s) => Ok(self.invalid_cdata_closing(c, s)),
386390
State::InsideMarkupDeclaration => self.markup_declaration(c),
387-
State::InsideMarkupDeclarationQuotedString(q) => Ok(self.markup_declaration_string(c, q)),
391+
State::InsideMarkupDeclarationQuotedString(q) => Ok(Some(self.markup_declaration_string(c, q))),
388392
}
389393
}
390394

@@ -395,19 +399,19 @@ impl Lexer {
395399
}
396400

397401
#[inline]
398-
fn move_to_with(&mut self, st: State, token: Token) -> Option<Token> {
402+
fn move_to_with(&mut self, st: State, token: Token) -> Token {
399403
self.st = st;
400-
Some(token)
404+
token
401405
}
402406

403407
#[inline]
404-
fn move_to_and_reset_normal(&mut self, st: State, token: Token) -> Option<Token> {
408+
fn move_to_and_reset_normal(&mut self, st: State, token: Token) -> Token {
405409
self.normal_state = st;
406410
self.st = st;
407-
Some(token)
411+
token
408412
}
409413

410-
fn move_to_with_unread(&mut self, st: State, cs: &[char], token: Token) -> Option<Token> {
414+
fn move_to_with_unread(&mut self, st: State, cs: &[char], token: Token) -> Token {
411415
for c in cs.iter().rev().copied() {
412416
self.char_queue.push_front(c);
413417
}
@@ -442,7 +446,7 @@ impl Lexer {
442446
let first = chars.next().unwrap_or('\0');
443447
self.char_queue.extend(chars);
444448
self.char_queue.push_back(c);
445-
return Ok(self.move_to_with(State::Normal, Token::Character(first)));
449+
return Ok(Some(self.move_to_with(State::Normal, Token::Character(first))));
446450
}
447451
Err(self.error(SyntaxError::UnexpectedTokenBefore(chunk, c)))
448452
}
@@ -496,11 +500,11 @@ impl Lexer {
496500
/// Encountered '<'
497501
fn tag_opened(&mut self, c: char) -> Result {
498502
match c {
499-
'?' => Ok(self.move_to_with(State::InsideProcessingInstruction, Token::ProcessingInstructionStart)),
500-
'/' => Ok(self.move_to_with(self.normal_state, Token::ClosingTagStart)),
503+
'?' => Ok(Some(self.move_to_with(State::InsideProcessingInstruction, Token::ProcessingInstructionStart))),
504+
'/' => Ok(Some(self.move_to_with(self.normal_state, Token::ClosingTagStart))),
501505
'!' => Ok(self.move_to(State::CommentOrCDataOrDoctypeStarted)),
502-
_ if is_whitespace_char(c) => Ok(self.move_to_with_unread(self.normal_state, &[c], Token::OpeningTagStart)),
503-
_ if is_name_char(c) => Ok(self.move_to_with_unread(self.normal_state, &[c], Token::OpeningTagStart)),
506+
_ if is_whitespace_char(c) => Ok(Some(self.move_to_with_unread(self.normal_state, &[c], Token::OpeningTagStart))),
507+
_ if is_name_char(c) => Ok(Some(self.move_to_with_unread(self.normal_state, &[c], Token::OpeningTagStart))),
504508
_ => self.handle_error("<", c)
505509
}
506510
}
@@ -512,7 +516,7 @@ impl Lexer {
512516
'[' => Ok(self.move_to(State::CDataStarted(CDataStartedSubstate::E))),
513517
'D' => Ok(self.move_to(State::DoctypeStarted(DoctypeStartedSubstate::D))),
514518
'E' | 'A' | 'N' if matches!(self.normal_state, State::InsideDoctype) => {
515-
Ok(self.move_to_with_unread(State::InsideMarkupDeclaration, &[c], Token::MarkupDeclarationStart))
519+
Ok(Some(self.move_to_with_unread(State::InsideMarkupDeclaration, &[c], Token::MarkupDeclarationStart)))
516520
},
517521
_ => self.handle_error("<!", c),
518522
}
@@ -521,7 +525,7 @@ impl Lexer {
521525
/// Encountered '<!-'
522526
fn comment_started(&mut self, c: char) -> Result {
523527
match c {
524-
'-' => Ok(self.move_to_with(State::InsideComment, Token::CommentStart)),
528+
'-' => Ok(Some(self.move_to_with(State::InsideComment, Token::CommentStart))),
525529
_ => self.handle_error("<!-", c),
526530
}
527531
}
@@ -535,28 +539,28 @@ impl Lexer {
535539
CD ; 'A' ; CDA ; "<![CD",
536540
CDA ; 'T' ; CDAT ; "<![CDA",
537541
CDAT ; 'A' ; CDATA ; "<![CDAT";
538-
CDATA ; '[' ; "<![CDATA" ; Ok(self.move_to_with(State::InsideCdata, Token::CDataStart))
542+
CDATA ; '[' ; "<![CDATA" ; Ok(Some(self.move_to_with(State::InsideCdata, Token::CDataStart)))
539543
)
540544
}
541545

542546
/// Encountered '<!…' that isn't DOCTYPE or CDATA
543547
fn markup_declaration(&mut self, c: char) -> Result {
544548
match c {
545549
'<' => self.handle_error("<!", c),
546-
'>' => Ok(self.move_to_with(self.normal_state, Token::TagEnd)),
550+
'>' => Ok(Some(self.move_to_with(self.normal_state, Token::TagEnd))),
547551
'&' => Ok(Some(Token::ReferenceStart)),
548552
';' => Ok(Some(Token::ReferenceEnd)),
549-
'"' => Ok(self.move_to_with(State::InsideMarkupDeclarationQuotedString(QuoteStyle::Double), Token::DoubleQuote)),
550-
'\'' => Ok(self.move_to_with(State::InsideMarkupDeclarationQuotedString(QuoteStyle::Single), Token::SingleQuote)),
553+
'"' => Ok(Some(self.move_to_with(State::InsideMarkupDeclarationQuotedString(QuoteStyle::Double), Token::DoubleQuote))),
554+
'\'' => Ok(Some(self.move_to_with(State::InsideMarkupDeclarationQuotedString(QuoteStyle::Single), Token::SingleQuote))),
551555
_ => Ok(Some(Token::Character(c))),
552556
}
553557
}
554558

555-
fn markup_declaration_string(&mut self, c: char, q: QuoteStyle) -> Option<Token> {
559+
fn markup_declaration_string(&mut self, c: char, q: QuoteStyle) -> Token {
556560
match c {
557561
'"' if q == QuoteStyle::Double => self.move_to_with(State::InsideMarkupDeclaration, Token::DoubleQuote),
558562
'\'' if q == QuoteStyle::Single => self.move_to_with(State::InsideMarkupDeclaration, Token::SingleQuote),
559-
_ => Some(Token::Character(c)),
563+
_ => Token::Character(c),
560564
}
561565
}
562566

@@ -569,14 +573,14 @@ impl Lexer {
569573
DOC ; 'T' ; DOCT ; "<!DOC",
570574
DOCT ; 'Y' ; DOCTY ; "<!DOCT",
571575
DOCTY ; 'P' ; DOCTYP ; "<!DOCTY";
572-
DOCTYP ; 'E' ; "<!DOCTYP" ; Ok(self.move_to_and_reset_normal(State::InsideDoctype, Token::DoctypeStart))
576+
DOCTYP ; 'E' ; "<!DOCTYP" ; Ok(Some(self.move_to_and_reset_normal(State::InsideDoctype, Token::DoctypeStart)))
573577
)
574578
}
575579

576580
/// State used while awaiting the closing bracket for the <!DOCTYPE tag
577581
fn inside_doctype(&mut self, c: char) -> Option<Token> {
578582
match c {
579-
'>' => self.move_to_and_reset_normal(State::Normal, Token::TagEnd),
583+
'>' => Some(self.move_to_and_reset_normal(State::Normal, Token::TagEnd)),
580584
'<' => self.move_to(State::TagStarted),
581585
'&' => Some(Token::ReferenceStart),
582586
';' => Some(Token::ReferenceEnd),
@@ -587,15 +591,15 @@ impl Lexer {
587591
}
588592

589593
/// Encountered '?'
590-
fn processing_instruction_closing(&mut self, c: char) -> Option<Token> {
594+
fn processing_instruction_closing(&mut self, c: char) -> Token {
591595
match c {
592596
'>' => self.move_to_with(self.normal_state, Token::ProcessingInstructionEnd),
593597
_ => self.move_to_with_unread(State::InsideProcessingInstruction, &[c], Token::Character('?')),
594598
}
595599
}
596600

597601
/// Encountered '/'
598-
fn empty_element_closing(&mut self, c: char) -> Option<Token> {
602+
fn empty_element_closing(&mut self, c: char) -> Token {
599603
match c {
600604
'>' => self.move_to_with(self.normal_state, Token::EmptyTagEnd),
601605
_ => self.move_to_with_unread(self.normal_state, &[c], Token::Character('/')),
@@ -607,10 +611,10 @@ impl Lexer {
607611
match s {
608612
ClosingSubstate::First => match c {
609613
'-' => Ok(self.move_to(State::CommentClosing(ClosingSubstate::Second))),
610-
_ => Ok(self.move_to_with_unread(State::InsideComment, &[c], Token::Character('-'))),
614+
_ => Ok(Some(self.move_to_with_unread(State::InsideComment, &[c], Token::Character('-')))),
611615
},
612616
ClosingSubstate::Second => match c {
613-
'>' => Ok(self.move_to_with(self.normal_state, Token::CommentEnd)),
617+
'>' => Ok(Some(self.move_to_with(self.normal_state, Token::CommentEnd))),
614618
// double dash not followed by a greater-than is a hard error inside comment
615619
_ => self.handle_error("--", c),
616620
},
@@ -622,11 +626,11 @@ impl Lexer {
622626
match s {
623627
ClosingSubstate::First => match c {
624628
']' => self.move_to(State::CDataClosing(ClosingSubstate::Second)),
625-
_ => self.move_to_with_unread(State::InsideCdata, &[c], Token::Character(']')),
629+
_ => Some(self.move_to_with_unread(State::InsideCdata, &[c], Token::Character(']'))),
626630
},
627631
ClosingSubstate::Second => match c {
628-
'>' => self.move_to_with(State::Normal, Token::CDataEnd),
629-
_ => self.move_to_with_unread(State::InsideCdata, &[']', c], Token::Character(']')),
632+
'>' => Some(self.move_to_with(State::Normal, Token::CDataEnd)),
633+
_ => Some(self.move_to_with_unread(State::InsideCdata, &[']', c], Token::Character(']'))),
630634
},
631635
}
632636
}
@@ -636,11 +640,11 @@ impl Lexer {
636640
match s {
637641
ClosingSubstate::First => match c {
638642
']' => self.move_to(State::InvalidCDataClosing(ClosingSubstate::Second)),
639-
_ => self.move_to_with_unread(State::Normal, &[c], Token::Character(']')),
643+
_ => Some(self.move_to_with_unread(State::Normal, &[c], Token::Character(']'))),
640644
},
641645
ClosingSubstate::Second => match c {
642-
'>' => self.move_to_with(self.normal_state, Token::CDataEnd),
643-
_ => self.move_to_with_unread(State::Normal, &[']', c], Token::Character(']')),
646+
'>' => Some(self.move_to_with(self.normal_state, Token::CDataEnd)),
647+
_ => Some(self.move_to_with_unread(State::Normal, &[']', c], Token::Character(']'))),
644648
},
645649
}
646650
}

src/reader/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ macro_rules! gen_takes(
2020
impl MarkupData {
2121
#[inline]
2222
#[allow(clippy::mem_replace_option_with_none)]
23+
#[allow(clippy::mem_replace_with_default)]
2324
fn $method(&mut self) -> $t {
2425
std::mem::replace(&mut self.$field, $def)
2526
}

src/reader/parser/inside_reference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl PullParser {
6464
let val = if let Some(hex) = num_str.strip_prefix('x') {
6565
u32::from_str_radix(hex, 16).map_err(move |_| SyntaxError::InvalidNumericEntity(num_str.into()))?
6666
} else {
67-
u32::from_str_radix(num_str, 10).map_err(move |_| SyntaxError::InvalidNumericEntity(num_str.into()))?
67+
num_str.parse::<u32>().map_err(move |_| SyntaxError::InvalidNumericEntity(num_str.into()))?
6868
};
6969
match char::from_u32(val) {
7070
Some(c) if self.is_valid_xml_char(c) => Ok(c),

src/util.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ impl fmt::Display for Encoding {
8585
#[cold]
8686
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8787
f.write_str(match self {
88-
Encoding::Utf8 => "UTF-8",
88+
Encoding::Utf8 |
8989
Encoding::Default => "UTF-8",
9090
Encoding::Latin1 => "ISO-8859-1",
9191
Encoding::Ascii => "US-ASCII",
92-
Encoding::Utf16Be => "UTF-16",
93-
Encoding::Utf16Le => "UTF-16",
92+
Encoding::Utf16Be |
93+
Encoding::Utf16Le |
9494
Encoding::Utf16 => "UTF-16",
9595
Encoding::Unknown => "(unknown)",
9696
})
@@ -142,11 +142,11 @@ impl CharReader {
142142
return Ok(Some(next.into()));
143143
},
144144
Encoding::Ascii => {
145-
if next.is_ascii() {
146-
return Ok(Some(next.into()));
145+
return if next.is_ascii() {
146+
Ok(Some(next.into()))
147147
} else {
148-
return Err(CharReadError::Io(io::Error::new(io::ErrorKind::InvalidData, "char is not ASCII")));
149-
}
148+
Err(CharReadError::Io(io::Error::new(io::ErrorKind::InvalidData, "char is not ASCII")))
149+
};
150150
},
151151
Encoding::Unknown | Encoding::Utf16 => {
152152
buf[pos] = next;

0 commit comments

Comments
 (0)