Skip to content

Commit a8e9ca5

Browse files
authored
Merge pull request #93 from shepmaster/warnings
Address clippy warnings
2 parents 7751ffd + 5444778 commit a8e9ca5

9 files changed

Lines changed: 82 additions & 114 deletions

File tree

src/dom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ macro_rules! wrapper(
1919
fn $name(self, node: *mut $inner) -> $wrapper<'d> {
2020
$wrapper {
2121
document: self,
22-
node: node,
22+
node,
2323
}
2424
}
2525
)

src/lazy_hash_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ where
1616
LazyHashMap { map: None }
1717
}
1818

19-
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
19+
pub fn contains_key<Q>(&self, key: &Q) -> bool
2020
where
2121
K: Borrow<Q>,
22-
Q: Hash + Eq,
22+
Q: Hash + Eq + ?Sized,
2323
{
2424
self.map.as_ref().map_or(false, |m| m.contains_key(key))
2525
}
2626

27-
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
27+
pub fn get<Q>(&self, key: &Q) -> Option<&V>
2828
where
2929
K: Borrow<Q>,
30-
Q: Hash + Eq,
30+
Q: Hash + Eq + ?Sized,
3131
{
3232
self.map.as_ref().and_then(|m| m.get(key))
3333
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl Package {
189189

190190
impl PartialEq for Package {
191191
fn eq(&self, other: &Package) -> bool {
192-
self as *const Package == other as *const Package
192+
std::ptr::eq(self, other)
193193
}
194194
}
195195

src/parser.rs

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use std::ascii::AsciiExt;
1919
use std::{
2020
char,
2121
collections::{BTreeSet, HashMap},
22-
error, fmt, iter,
23-
mem::replace,
22+
error, fmt,
2423
ops::Deref,
2524
};
2625

@@ -92,22 +91,22 @@ impl Recoverable for SpecificError {
9291
fn recoverable(&self) -> bool {
9392
use self::SpecificError::*;
9493

95-
match *self {
94+
!matches!(
95+
self,
9696
ExpectedEncoding
97-
| ExpectedYesNo
98-
| InvalidProcessingInstructionTarget
99-
| MismatchedElementEndName
100-
| InvalidDecimalReference
101-
| InvalidHexReference
102-
| UnknownNamedReference
103-
| DuplicateAttribute
104-
| RedefinedNamespace
105-
| RedefinedDefaultNamespace
106-
| EmptyNamespace
107-
| UnknownNamespacePrefix
108-
| UnclosedElement => false,
109-
_ => true,
110-
}
97+
| ExpectedYesNo
98+
| InvalidProcessingInstructionTarget
99+
| MismatchedElementEndName
100+
| InvalidDecimalReference
101+
| InvalidHexReference
102+
| UnknownNamedReference
103+
| DuplicateAttribute
104+
| RedefinedNamespace
105+
| RedefinedDefaultNamespace
106+
| EmptyNamespace
107+
| UnknownNamespacePrefix
108+
| UnclosedElement
109+
)
111110
}
112111
}
113112

@@ -359,7 +358,7 @@ enum Token<'a> {
359358
DocumentTypeDeclaration,
360359
Comment(&'a str),
361360
ProcessingInstruction(&'a str, Option<&'a str>),
362-
Whitespace(&'a str),
361+
Whitespace(#[allow(dead_code)] &'a str),
363362
ElementStart(Span<PrefixedName<'a>>),
364363
ElementStartClose,
365364
ElementSelfClose,
@@ -400,7 +399,7 @@ impl<'a> PullParser<'a> {
400399
}
401400
}
402401

403-
fn parse_comment<'a>(xml: StringPoint<'a>) -> XmlProgress<'a, Token<'_>> {
402+
fn parse_comment<'a>(xml: StringPoint<'a>) -> XmlProgress<'a, Token<'a>> {
404403
let (xml, _) = try_parse!(xml
405404
.consume_literal("<!--")
406405
.map_err(|_| SpecificError::ExpectedComment));
@@ -569,7 +568,7 @@ fn parse_pi_value(xml: StringPoint<'_>) -> XmlProgress<'_, &str> {
569568
xml.consume_pi_value()
570569
}
571570

572-
fn parse_pi<'a>(xml: StringPoint<'a>) -> XmlProgress<'a, Token<'_>> {
571+
fn parse_pi<'a>(xml: StringPoint<'a>) -> XmlProgress<'a, Token<'a>> {
573572
let (xml, _) = try_parse!(xml
574573
.consume_literal("<?")
575574
.map_err(|_| SpecificError::ExpectedProcessingInstruction));
@@ -727,11 +726,11 @@ fn parse_attribute_reference<'a>(
727726
success(Token::ReferenceAttributeValue(val), xml)
728727
}
729728

730-
fn parse_char_data<'a>(xml: StringPoint<'a>) -> XmlProgress<'a, Token<'_>> {
729+
fn parse_char_data<'a>(xml: StringPoint<'a>) -> XmlProgress<'a, Token<'a>> {
731730
xml.consume_char_data().map(Token::CharData)
732731
}
733732

734-
fn parse_cdata<'a>(xml: StringPoint<'a>) -> XmlProgress<'a, Token<'_>> {
733+
fn parse_cdata<'a>(xml: StringPoint<'a>) -> XmlProgress<'a, Token<'a>> {
735734
let (xml, _) = try_parse!(xml.expect_literal("<![CDATA["));
736735
let (xml, text) = try_parse!(xml.consume_cdata());
737736
let (xml, _) = try_parse!(xml.expect_literal("]]>"));
@@ -922,7 +921,7 @@ impl<'d> DomBuilder<'d> {
922921

923922
fn finish_opening_tag(&mut self) -> DomBuilderResult<()> {
924923
let deferred_element = self.element_names.last().expect("Unknown element name");
925-
let attributes = DeferredAttributes::new(replace(&mut self.attributes, Vec::new()));
924+
let attributes = DeferredAttributes::new(std::mem::take(&mut self.attributes));
926925

927926
attributes.check_duplicates()?;
928927
let default_namespace = attributes.default_namespace()?;
@@ -971,7 +970,7 @@ impl<'d> DomBuilder<'d> {
971970
};
972971

973972
for (prefix, ns_uri) in &new_prefix_mappings {
974-
element.register_prefix(*prefix, ns_uri);
973+
element.register_prefix(prefix, ns_uri);
975974
}
976975

977976
if !self.seen_top_element {
@@ -1182,24 +1181,17 @@ where
11821181
F: FnOnce(&str),
11831182
{
11841183
match ref_data {
1184+
#[allow(clippy::from_str_radix_10)]
11851185
DecimalChar(span) => u32::from_str_radix(span.value, 10)
11861186
.ok()
11871187
.and_then(char::from_u32)
11881188
.ok_or_else(|| span.map(|_| SpecificError::InvalidDecimalReference))
1189-
.and_then(|c| {
1190-
let s: String = iter::repeat(c).take(1).collect();
1191-
cb(&s);
1192-
Ok(())
1193-
}),
1189+
.map(|c| cb(&c.to_string())),
11941190
HexChar(span) => u32::from_str_radix(span.value, 16)
11951191
.ok()
11961192
.and_then(char::from_u32)
11971193
.ok_or_else(|| span.map(|_| SpecificError::InvalidHexReference))
1198-
.and_then(|c| {
1199-
let s: String = iter::repeat(c).take(1).collect();
1200-
cb(&s);
1201-
Ok(())
1202-
}),
1194+
.map(|c| cb(&c.to_string())),
12031195
Entity(span) => {
12041196
let s = match span.value {
12051197
"amp" => "&",

src/raw.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ pub enum ChildOfRoot {
109109

110110
impl ChildOfRoot {
111111
fn is_element(&self) -> bool {
112-
match *self {
113-
ChildOfRoot::Element(_) => true,
114-
_ => false,
115-
}
112+
matches!(self, ChildOfRoot::Element(_))
116113
}
117114

118115
fn replace_parent(&self, parent: *mut Root) {
@@ -580,7 +577,7 @@ impl Connections {
580577
pub fn remove_attribute_from_parent(&self, child: *mut Attribute) {
581578
let child_r = unsafe { &mut *child };
582579
if let Some(parent) = child_r.parent {
583-
self.remove_attribute_x(parent, |attr| attr as *mut Attribute == child);
580+
self.remove_attribute_x(parent, |attr| std::ptr::eq(attr, child));
584581
}
585582
}
586583

src/str.rs

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ trait StrParseExt {
55
F2: Fn(char) -> bool;
66
}
77

8-
impl<'a> StrParseExt for &'a str {
8+
impl StrParseExt for &str {
99
fn end_of_start_rest<F1, F2>(&self, is_first: F1, is_rest: F2) -> Option<usize>
1010
where
1111
F1: Fn(char) -> bool,
@@ -55,7 +55,7 @@ pub trait XmlStr {
5555
fn end_of_int_subset(&self) -> Option<usize>;
5656
}
5757

58-
impl<'a> XmlStr for &'a str {
58+
impl XmlStr for &str {
5959
fn end_of_attribute(&self, quote: &str) -> Option<usize> {
6060
if self.is_empty()
6161
|| self.starts_with('&')
@@ -67,8 +67,7 @@ impl<'a> XmlStr for &'a str {
6767

6868
let quote_char = quote.chars().next().expect("Cant have null quote");
6969

70-
self.find(&['&', '<', quote_char][..])
71-
.or_else(|| Some(self.len()))
70+
self.find(&['&', '<', quote_char][..]).or(Some(self.len()))
7271
}
7372

7473
fn end_of_char_data(&self) -> Option<usize> {
@@ -131,7 +130,7 @@ impl<'a> XmlStr for &'a str {
131130
let mut positions = self.char_indices();
132131

133132
match positions.next() {
134-
Some((_, c)) if '<' == c => (),
133+
Some((_, '<')) => (),
135134
_ => return None,
136135
};
137136

@@ -157,6 +156,7 @@ impl<'a> XmlStr for &'a str {
157156
}
158157

159158
/// Predicates used when parsing an characters in an XML document.
159+
#[allow(clippy::wrong_self_convention)]
160160
pub trait XmlChar {
161161
/// Is this a [NameStartChar](http://www.w3.org/TR/xml/#NT-NameStartChar)?
162162
fn is_name_start_char(self) -> bool;
@@ -184,8 +184,7 @@ impl XmlChar for char {
184184
}
185185

186186
fn is_ncname_start_char(self) -> bool {
187-
match self {
188-
'A'..='Z'
187+
matches!(self, 'A'..='Z'
189188
| '_'
190189
| 'a'..='z'
191190
| '\u{0000C0}'..='\u{0000D6}'
@@ -199,59 +198,39 @@ impl XmlChar for char {
199198
| '\u{003001}'..='\u{00D7FF}'
200199
| '\u{00F900}'..='\u{00FDCF}'
201200
| '\u{00FDF0}'..='\u{00FFFD}'
202-
| '\u{010000}'..='\u{0EFFFF}' => true,
203-
_ => false,
204-
}
201+
| '\u{010000}'..='\u{0EFFFF}')
205202
}
206203

207204
fn is_ncname_char(self) -> bool {
208205
if self.is_ncname_start_char() {
209206
return true;
210207
}
211-
match self {
212-
'-'
208+
matches!(self, '-'
213209
| '.'
214210
| '0'..='9'
215211
| '\u{00B7}'
216212
| '\u{0300}'..='\u{036F}'
217-
| '\u{203F}'..='\u{2040}' => true,
218-
_ => false,
219-
}
213+
| '\u{203F}'..='\u{2040}')
220214
}
221215

222216
fn is_space_char(self) -> bool {
223-
match self {
224-
'\x20' | '\x09' | '\x0D' | '\x0A' => true,
225-
_ => false,
226-
}
217+
matches!(self, '\x20' | '\x09' | '\x0D' | '\x0A')
227218
}
228219

229220
fn is_decimal_char(self) -> bool {
230-
match self {
231-
'0'..='9' => true,
232-
_ => false,
233-
}
221+
self.is_ascii_digit()
234222
}
235223

236224
fn is_hex_char(self) -> bool {
237-
match self {
238-
'0'..='9' | 'a'..='f' | 'A'..='F' => true,
239-
_ => false,
240-
}
225+
self.is_ascii_hexdigit()
241226
}
242227

243228
fn is_encoding_start_char(self) -> bool {
244-
match self {
245-
'A'..='Z' | 'a'..='z' => true,
246-
_ => false,
247-
}
229+
self.is_ascii_alphabetic()
248230
}
249231

250232
fn is_encoding_rest_char(self) -> bool {
251-
match self {
252-
'A'..='Z' | 'a'..='z' | '0'..='9' | '.' | '_' | '-' => true,
253-
_ => false,
254-
}
233+
matches!(self, 'A'..='Z' | 'a'..='z' | '0'..='9' | '.' | '_' | '-')
255234
}
256235
}
257236

src/string_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ impl StringPool {
142142
}
143143

144144
pub fn intern<'s>(&'s self, s: &str) -> &'s str {
145-
if s == "" {
145+
if s.is_empty() {
146146
return "";
147147
}
148148

149149
let mut index = self.index.borrow_mut();
150150
if let Some(interned) = index.get(s) {
151-
return unsafe { mem::transmute(interned as &str) };
151+
return unsafe { mem::transmute::<&str, &str>(interned) };
152152
}
153153

154154
let interned_str = self.do_intern(s);

src/thindom.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ macro_rules! node(
317317
impl<'d> $name<'d> {
318318
fn wrap(node: *mut $raw) -> $name<'d> {
319319
$name {
320-
node: node,
320+
node,
321321
lifetime: PhantomData,
322322
}
323323
}
@@ -551,9 +551,9 @@ macro_rules! conversion_trait(
551551
($res_type:ident, {
552552
$($leaf_type:ident => $variant:expr),*
553553
}) => (
554-
$(impl<'d> Into<$res_type<'d>> for $leaf_type<'d> {
555-
fn into(self) -> $res_type<'d> {
556-
$variant(self)
554+
$(impl<'d> From<$leaf_type<'d>> for $res_type<'d>{
555+
fn from(other: $leaf_type<'d>) -> $res_type<'d> {
556+
$variant(other)
557557
}
558558
})*
559559
)
@@ -576,9 +576,9 @@ conversion_trait!(
576576
}
577577
);
578578

579-
impl<'d> Into<ChildOfElement<'d>> for ChildOfRoot<'d> {
580-
fn into(self) -> ChildOfElement<'d> {
581-
match self {
579+
impl<'d> From<ChildOfRoot<'d>> for ChildOfElement<'d> {
580+
fn from(val: ChildOfRoot<'d>) -> Self {
581+
match val {
582582
ChildOfRoot::Element(n) => ChildOfElement::Element(n),
583583
ChildOfRoot::Comment(n) => ChildOfElement::Comment(n),
584584
ChildOfRoot::ProcessingInstruction(n) => ChildOfElement::ProcessingInstruction(n),

0 commit comments

Comments
 (0)