Skip to content

Commit 4cd3b5a

Browse files
committed
Clippy
1 parent e945d22 commit 4cd3b5a

File tree

11 files changed

+59
-62
lines changed

11 files changed

+59
-62
lines changed

examples/print_events.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,38 @@ fn main() {
1818

1919
match e {
2020
XmlEvent::StartDocument { version, encoding, .. } => {
21-
println!("StartDocument({version}, {encoding})")
21+
println!("StartDocument({version}, {encoding})");
2222
},
2323
XmlEvent::EndDocument => {
2424
println!("EndDocument");
2525
break;
2626
}
2727
XmlEvent::ProcessingInstruction { name, data } => {
28-
println!("ProcessingInstruction({name}={:?})", data.as_deref().unwrap_or_default())
28+
println!("ProcessingInstruction({name}={:?})", data.as_deref().unwrap_or_default());
2929
},
3030
XmlEvent::StartElement { name, attributes, .. } => {
3131
if attributes.is_empty() {
32-
println!("StartElement({name})")
32+
println!("StartElement({name})");
3333
} else {
3434
let attrs: Vec<_> = attributes
3535
.iter()
3636
.map(|a| format!("{}={:?}", &a.name, a.value))
3737
.collect();
38-
println!("StartElement({name} [{}])", attrs.join(", "))
38+
println!("StartElement({name} [{}])", attrs.join(", "));
3939
}
4040
}
4141
XmlEvent::EndElement { name } => {
42-
println!("EndElement({name})")
42+
println!("EndElement({name})");
4343
},
4444
XmlEvent::Comment(data) => {
45-
println!(r#"Comment("{}")"#, data.escape_debug())
45+
println!(r#"Comment("{}")"#, data.escape_debug());
4646
}
4747
XmlEvent::CData(data) => println!(r#"CData("{}")"#, data.escape_debug()),
4848
XmlEvent::Characters(data) => {
49-
println!(r#"Characters("{}")"#, data.escape_debug())
49+
println!(r#"Characters("{}")"#, data.escape_debug());
5050
}
5151
XmlEvent::Whitespace(data) => {
52-
println!(r#"Whitespace("{}")"#, data.escape_debug())
52+
println!(r#"Whitespace("{}")"#, data.escape_debug());
5353
}
5454
}
5555
}

src/macros.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ macro_rules! gen_setter {
99
///
1010
/// <small>See [`ParserConfig`][crate::ParserConfig] fields docs for details</small>
1111
#[inline]
12+
#[must_use]
1213
pub fn $field<T: Into<$t>>(mut self, value: T) -> Self {
1314
self.$field = value.into();
1415
self
@@ -19,7 +20,8 @@ macro_rules! gen_setter {
1920
///
2021
/// <small>See [`ParserConfig`][crate::ParserConfig] fields docs for details</small>
2122
#[inline]
22-
#[must_use] pub fn $field(mut self, value: $t) -> Self {
23+
#[must_use]
24+
pub fn $field(mut self, value: $t) -> Self {
2325
self.$field = value;
2426
self
2527
}
@@ -29,7 +31,8 @@ macro_rules! gen_setter {
2931
///
3032
/// <small>See [`ParserConfig`][crate::ParserConfig] fields docs for details</small>
3133
#[inline]
32-
#[must_use] pub fn $field(mut self, value: $t) -> Self {
34+
#[must_use]
35+
pub fn $field(mut self, value: $t) -> Self {
3336
self.c.$field = value;
3437
self
3538
}

src/reader/config.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl ParserConfig {
165165
/// .add_entity("reg", "®")
166166
/// .create_reader(&mut source);
167167
/// ```
168+
#[must_use]
168169
pub fn add_entity<S: Into<String>, T: Into<String>>(mut self, entity: S, value: T) -> ParserConfig {
169170
self.extra_entities.insert(entity.into(), value.into());
170171
self
@@ -257,11 +258,8 @@ impl ParserConfig2 {
257258
.and_then(|(_, args)| args.split_once('='));
258259
if let Some((_, charset)) = charset {
259260
let name = charset.trim().trim_matches('"');
260-
match name.parse() {
261-
Ok(enc) => {
262-
self.override_encoding = Some(enc);
263-
},
264-
Err(_) => {},
261+
if let Ok(enc) = name.parse() {
262+
self.override_encoding = Some(enc);
265263
}
266264
}
267265
self

src/reader/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) enum SyntaxError {
7070
}
7171

7272
impl fmt::Display for SyntaxError {
73-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
73+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7474
self.to_cow().fmt(f)
7575
}
7676
}

src/reader/lexer.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl fmt::Display for Token {
8787
}
8888

8989
impl Token {
90-
pub fn as_static_str(&self) -> Option<&'static str> {
91-
match *self {
90+
pub fn as_static_str(self) -> Option<&'static str> {
91+
match self {
9292
Token::OpeningTagStart => Some("<"),
9393
Token::ProcessingInstructionStart => Some("<?"),
9494
Token::DoctypeStart => Some("<!DOCTYPE"),
@@ -110,11 +110,11 @@ impl Token {
110110
}
111111

112112
// using String.push_str(token.to_string()) is simply way too slow
113-
pub fn push_to_string(&self, target: &mut String) {
114-
match *self {
113+
pub fn push_to_string(self, target: &mut String) {
114+
match self {
115115
Token::Character(c) => {
116116
debug_assert!(is_xml10_char(c) || is_xml11_char(c));
117-
target.push(c)
117+
target.push(c);
118118
},
119119
_ => if let Some(s) = self.as_static_str() {
120120
target.push_str(s);
@@ -172,11 +172,13 @@ enum ClosingSubstate {
172172
}
173173

174174
#[derive(Copy, Clone)]
175+
#[allow(clippy::upper_case_acronyms)]
175176
enum DoctypeStartedSubstate {
176177
D, DO, DOC, DOCT, DOCTY, DOCTYP
177178
}
178179

179180
#[derive(Copy, Clone)]
181+
#[allow(clippy::upper_case_acronyms)]
180182
enum CDataStartedSubstate {
181183
E, C, CD, CDA, CDAT, CDATA
182184
}
@@ -297,12 +299,9 @@ impl Lexer {
297299

298300
// Check if we have saved a char or two for ourselves
299301
while let Some(c) = self.char_queue.pop_front() {
300-
match self.dispatch_char(c)? {
301-
Some(t) => {
302-
self.inside_token = false;
303-
return Ok(Some(t));
304-
}
305-
None => {} // continue
302+
if let Some(t) = self.dispatch_char(c)? {
303+
self.inside_token = false;
304+
return Ok(Some(t));
306305
}
307306
}
308307
// if char_queue is empty, all circular reparsing is done
@@ -319,14 +318,9 @@ impl Lexer {
319318
self.head_pos.advance(1);
320319
}
321320

322-
match self.dispatch_char(c)? {
323-
Some(t) => {
324-
self.inside_token = false;
325-
return Ok(Some(t));
326-
}
327-
None => {
328-
// continue
329-
}
321+
if let Some(t) = self.dispatch_char(c)? {
322+
self.inside_token = false;
323+
return Ok(Some(t));
330324
}
331325
}
332326

@@ -689,7 +683,7 @@ mod tests {
689683

690684
#[test]
691685
fn tricky_pi() {
692-
let (mut lex, mut buf) = make_lex_and_buf(r#"<?x<!-- &??><x>"#);
686+
let (mut lex, mut buf) = make_lex_and_buf(r"<?x<!-- &??><x>");
693687

694688
assert_oks!(for lex and buf ;
695689
Token::ProcessingInstructionStart
@@ -711,7 +705,7 @@ mod tests {
711705

712706
#[test]
713707
fn reparser() {
714-
let (mut lex, mut buf) = make_lex_and_buf(r#"&a;"#);
708+
let (mut lex, mut buf) = make_lex_and_buf(r"&a;");
715709

716710
assert_oks!(for lex and buf ;
717711
Token::ReferenceStart
@@ -794,7 +788,7 @@ mod tests {
794788
#[test]
795789
fn special_chars_test() {
796790
let (mut lex, mut buf) = make_lex_and_buf(
797-
r#"?x!+ // -| ]z]]"#
791+
r"?x!+ // -| ]z]]"
798792
);
799793

800794
assert_oks!(for lex and buf ;
@@ -820,7 +814,7 @@ mod tests {
820814
#[test]
821815
fn cdata_test() {
822816
let (mut lex, mut buf) = make_lex_and_buf(
823-
r#"<a><![CDATA[x y ?]]> </a>"#
817+
r"<a><![CDATA[x y ?]]> </a>"
824818
);
825819

826820
assert_oks!(for lex and buf ;
@@ -845,7 +839,7 @@ mod tests {
845839
#[test]
846840
fn cdata_closers_test() {
847841
let (mut lex, mut buf) = make_lex_and_buf(
848-
r#"<![CDATA[] > ]> ]]><!---->]]<a>"#
842+
r"<![CDATA[] > ]> ]]><!---->]]<a>"
849843
);
850844

851845
assert_oks!(for lex and buf ;
@@ -872,7 +866,7 @@ mod tests {
872866
#[test]
873867
fn doctype_test() {
874868
let (mut lex, mut buf) = make_lex_and_buf(
875-
r#"<a><!DOCTYPE ab xx z> "#
869+
r"<a><!DOCTYPE ab xx z> "
876870
);
877871
assert_oks!(for lex and buf ;
878872
Token::OpeningTagStart
@@ -896,7 +890,7 @@ mod tests {
896890
#[test]
897891
fn tricky_comments() {
898892
let (mut lex, mut buf) = make_lex_and_buf(
899-
r#"<a><!-- C ->--></a>"#
893+
r"<a><!-- C ->--></a>"
900894
);
901895
assert_oks!(for lex and buf ;
902896
Token::OpeningTagStart
@@ -1146,7 +1140,7 @@ mod tests {
11461140
#[test]
11471141
fn issue_98_cdata_ending_with_right_bracket() {
11481142
let (mut lex, mut buf) = make_lex_and_buf(
1149-
r#"<![CDATA[Foo [Bar]]]>"#
1143+
r"<![CDATA[Foo [Bar]]]>"
11501144
);
11511145

11521146
assert_oks!(for lex and buf ;

src/reader/parser.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ enum QuoteToken {
275275

276276
impl QuoteToken {
277277
#[inline]
278-
fn from_token(t: &Token) -> Option<QuoteToken> {
279-
match *t {
278+
fn from_token(t: Token) -> Option<QuoteToken> {
279+
match t {
280280
Token::SingleQuote => Some(QuoteToken::SingleQuoteToken),
281281
Token::DoubleQuote => Some(QuoteToken::DoubleQuoteToken),
282282
_ => {
@@ -489,7 +489,7 @@ impl PullParser {
489489
let name = this.take_buf();
490490
match name.parse() {
491491
Ok(name) => on_name(this, t, name),
492-
Err(_) => Some(this.error(SyntaxError::InvalidQualifiedName(name.into()))),
492+
Err(()) => Some(this.error(SyntaxError::InvalidQualifiedName(name.into()))),
493493
}
494494
};
495495

@@ -535,7 +535,7 @@ impl PullParser {
535535

536536
Token::DoubleQuote | Token::SingleQuote => match self.data.quote {
537537
None => { // Entered attribute value
538-
self.data.quote = QuoteToken::from_token(&t);
538+
self.data.quote = QuoteToken::from_token(t);
539539
None
540540
}
541541
Some(q) if q.as_token() == t => {
@@ -716,9 +716,9 @@ mod tests {
716716

717717
#[test]
718718
fn issue_140_entity_reference_inside_tag() {
719-
let (mut r, mut p) = test_data!(r#"
719+
let (mut r, mut p) = test_data!(r"
720720
<bla>&#9835;</bla>
721-
"#);
721+
");
722722

723723
expect_event!(r, p, Ok(XmlEvent::StartDocument { .. }));
724724
expect_event!(r, p, Ok(XmlEvent::StartElement { ref name, .. }) => *name == OwnedName::local("bla"));
@@ -729,18 +729,18 @@ mod tests {
729729

730730
#[test]
731731
fn issue_220_comment() {
732-
let (mut r, mut p) = test_data!(r#"<x><!-- <!--></x>"#);
732+
let (mut r, mut p) = test_data!(r"<x><!-- <!--></x>");
733733
expect_event!(r, p, Ok(XmlEvent::StartDocument { .. }));
734734
expect_event!(r, p, Ok(XmlEvent::StartElement { .. }));
735735
expect_event!(r, p, Ok(XmlEvent::EndElement { .. }));
736736
expect_event!(r, p, Ok(XmlEvent::EndDocument));
737737

738-
let (mut r, mut p) = test_data!(r#"<x><!-- <!---></x>"#);
738+
let (mut r, mut p) = test_data!(r"<x><!-- <!---></x>");
739739
expect_event!(r, p, Ok(XmlEvent::StartDocument { .. }));
740740
expect_event!(r, p, Ok(XmlEvent::StartElement { .. }));
741741
expect_event!(r, p, Err(_)); // ---> is forbidden in comments
742742

743-
let (mut r, mut p) = test_data!(r#"<x><!--<text&x;> <!--></x>"#);
743+
let (mut r, mut p) = test_data!(r"<x><!--<text&x;> <!--></x>");
744744
p.config.c.ignore_comments = false;
745745
expect_event!(r, p, Ok(XmlEvent::StartDocument { .. }));
746746
expect_event!(r, p, Ok(XmlEvent::StartElement { .. }));
@@ -786,9 +786,9 @@ mod tests {
786786

787787
#[test]
788788
fn reference_err() {
789-
let (mut r, mut p) = test_data!(r#"
789+
let (mut r, mut p) = test_data!(r"
790790
<a>&&amp;</a>
791-
"#);
791+
");
792792

793793
expect_event!(r, p, Ok(XmlEvent::StartDocument { .. }));
794794
expect_event!(r, p, Ok(XmlEvent::StartElement { .. }));

src/reader/parser/inside_doctype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl PullParser {
2323
},
2424
Token::SingleQuote | Token::DoubleQuote => {
2525
// just discard string literals
26-
self.data.quote = super::QuoteToken::from_token(&t);
26+
self.data.quote = super::QuoteToken::from_token(t);
2727
self.into_state_continue(State::InsideDoctype(DoctypeSubstate::String))
2828
},
2929
Token::CDataEnd | Token::CDataStart => Some(self.error(SyntaxError::UnexpectedToken(t))),
@@ -98,12 +98,12 @@ impl PullParser {
9898
// SYSTEM/PUBLIC not supported
9999
Token::Character('S' | 'P') => {
100100
let name = self.data.take_name();
101-
self.entities.entry(name).or_insert_with(String::new); // Dummy value, but at least the name is recognized
101+
self.entities.entry(name).or_default(); // Dummy value, but at least the name is recognized
102102

103103
self.into_state_continue(State::InsideDoctype(DoctypeSubstate::SkipDeclaration))
104104
},
105105
Token::SingleQuote | Token::DoubleQuote => {
106-
self.data.quote = super::QuoteToken::from_token(&t);
106+
self.data.quote = super::QuoteToken::from_token(t);
107107
self.into_state_continue(State::InsideDoctype(DoctypeSubstate::EntityValue))
108108
},
109109
_ => Some(self.error(SyntaxError::UnexpectedTokenInEntity(t))),

src/util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ mod tests {
234234
assert!(matches!(CharReader::new().next_char_from(&mut bytes), Err(CharReadError::UnexpectedEof)));
235235

236236
let mut bytes: &[u8] = b"\xEF\xBB\x42"; // Nothing after BO
237-
assert!(matches!(CharReader::new().next_char_from(&mut bytes), Err(_)));
237+
assert!(CharReader::new().next_char_from(&mut bytes).is_err());
238238

239239
let mut bytes: &[u8] = b"\xFE\xFF\x00\x42"; // UTF-16
240240
assert_eq!(CharReader::new().next_char_from(&mut bytes).unwrap(), Some('B'));
@@ -258,7 +258,7 @@ mod tests {
258258
assert_eq!(CharReader { encoding: Encoding::Utf16Le }.next_char_from(&mut bytes).unwrap(), Some('뿐'));
259259

260260
let mut bytes: &[u8] = b"\xD8\xD8\x80";
261-
assert!(matches!(CharReader { encoding: Encoding::Utf16 }.next_char_from(&mut bytes), Err(_)));
261+
assert!(CharReader { encoding: Encoding::Utf16 }.next_char_from(&mut bytes).is_err());
262262

263263
let mut bytes: &[u8] = b"\x00\x42";
264264
assert_eq!(CharReader { encoding: Encoding::Utf16 }.next_char_from(&mut bytes).unwrap(), Some('B'));
@@ -267,7 +267,7 @@ mod tests {
267267
assert_eq!(CharReader { encoding: Encoding::Utf16 }.next_char_from(&mut bytes).unwrap(), Some('B'));
268268

269269
let mut bytes: &[u8] = b"\x00";
270-
assert!(matches!(CharReader { encoding: Encoding::Utf16Be }.next_char_from(&mut bytes), Err(_)));
270+
assert!(CharReader { encoding: Encoding::Utf16Be }.next_char_from(&mut bytes).is_err());
271271

272272
let mut bytes: &[u8] = "😊".as_bytes(); // correct non-BMP
273273
assert_eq!(CharReader::new().next_char_from(&mut bytes).unwrap(), Some('😊'));

src/writer/emitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl Emitter {
327327

328328
pub fn emit_attributes<W: Write>(&mut self, target: &mut W,
329329
attributes: &[Attribute<'_>]) -> Result<()> {
330-
for attr in attributes.iter() {
330+
for attr in attributes {
331331
write!(target, " {}=\"", attr.name.repr_display())?;
332332
if self.config.perform_escaping {
333333
write!(target, "{}", Escaped::<AttributeEscapes>::new(attr.value))?;

0 commit comments

Comments
 (0)