Skip to content

Commit 375270c

Browse files
author
Vincent Prouillet
committed
Some clippy fixes
1 parent fe82e17 commit 375270c

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

src/format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a> Formatter<'a> {
6565
self.endline();
6666
}
6767
pub fn margin(&mut self) {
68-
if self.buf.len() != 0 {
68+
if !self.buf.is_empty() {
6969
self.buf.push('\n');
7070
}
7171
}
@@ -105,7 +105,7 @@ impl<'a> Formatter<'a> {
105105
self.endline();
106106
self.indent += self.style.indent;
107107
for line in s.lines() {
108-
if line.trim().len() != 0 {
108+
if !line.trim().is_empty() {
109109
self.indent();
110110
self.write(&line.replace(r#"""""#, r#"\""""#));
111111
}

src/query_format.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Displayable for Selection {
8787
}
8888

8989
fn format_arguments(arguments: &[(String, Value)], f: &mut Formatter) {
90-
if arguments.len() > 0 {
90+
if !arguments.is_empty() {
9191
f.write("(");
9292
f.write(&arguments[0].0);
9393
f.write(": ");
@@ -112,7 +112,7 @@ impl Displayable for Field {
112112
f.write(&self.name);
113113
format_arguments(&self.arguments, f);
114114
format_directives(&self.directives, f);
115-
if self.selection_set.items.len() > 0 {
115+
if !self.selection_set.items.is_empty() {
116116
f.write(" ");
117117
f.start_block();
118118
for item in &self.selection_set.items {
@@ -133,7 +133,7 @@ impl Displayable for Query {
133133
if let Some(ref name) = self.name {
134134
f.write(" ");
135135
f.write(name);
136-
if self.variable_definitions.len() > 0 {
136+
if !self.variable_definitions.is_empty() {
137137
f.write("(");
138138
self.variable_definitions[0].display(f);
139139
for var in &self.variable_definitions[1..] {
@@ -161,7 +161,7 @@ impl Displayable for Mutation {
161161
if let Some(ref name) = self.name {
162162
f.write(" ");
163163
f.write(name);
164-
if self.variable_definitions.len() > 0 {
164+
if !self.variable_definitions.is_empty() {
165165
f.write("(");
166166
for var in &self.variable_definitions {
167167
var.display(f);
@@ -187,7 +187,7 @@ impl Displayable for Subscription {
187187
if let Some(ref name) = self.name {
188188
f.write(" ");
189189
f.write(name);
190-
if self.variable_definitions.len() > 0 {
190+
if !self.variable_definitions.is_empty() {
191191
f.write("(");
192192
for var in &self.variable_definitions {
193193
var.display(f);
@@ -248,7 +248,7 @@ impl Displayable for Value {
248248
Value::Enum(ref name) => f.write(name),
249249
Value::List(ref items) => {
250250
f.write("[");
251-
if items.len() > 0 {
251+
if !items.is_empty() {
252252
items[0].display(f);
253253
for item in &items[1..] {
254254
f.write(", ");

src/query_grammar.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ pub fn variable_type<'a>(input: &mut TokenStream<'a>)
112112
.map(Box::new)
113113
.map(VariableType::ListType))
114114
.and(optional(punct("!")).map(|v| v.is_some()))
115-
.map(|(typ, strict)| match strict {
116-
true => VariableType::NonNullType(Box::new(typ)),
117-
false => typ,
118-
})
115+
.map(|(typ, strict)|
116+
if strict {
117+
VariableType::NonNullType(Box::new(typ))
118+
} else {
119+
typ
120+
}
121+
)
119122
.parse_stream(input)
120123
}
121124

@@ -137,7 +140,7 @@ pub fn float_value<'a>(input: &mut TokenStream<'a>)
137140

138141
fn unquote_string(s: &str) -> Result<String, Error<Token, Token>> {
139142
let mut res = String::with_capacity(s.len());
140-
debug_assert!(s.starts_with("\"") && s.ends_with("\""));
143+
debug_assert!(s.starts_with('"') && s.ends_with('"'));
141144
let mut chars = s[1..s.len()-1].chars();
142145
while let Some(c) = chars.next() {
143146
match c {
@@ -161,7 +164,8 @@ fn unquote_string(s: &str) -> Result<String, Error<Token, Token>> {
161164
c => res.push(c),
162165
}
163166
}
164-
return Ok(res);
167+
168+
Ok(res)
165169
}
166170

167171
fn unquote_block_string(src: &str) -> Result<String, Error<Token, Token>> {
@@ -180,7 +184,7 @@ fn unquote_block_string(src: &str) -> Result<String, Error<Token, Token>> {
180184
let mut lines = src[3..src.len()-3].lines();
181185
if let Some(first) = lines.next() {
182186
let stripped = first.trim();
183-
if stripped.len() > 0 {
187+
if !stripped.is_empty() {
184188
result.push_str(stripped);
185189
result.push('\n');
186190
}
@@ -193,10 +197,11 @@ fn unquote_block_string(src: &str) -> Result<String, Error<Token, Token>> {
193197
}
194198
result.push('\n');
195199
}
196-
if result[last_line..].trim().len() == 0 {
200+
if result[last_line..].trim().is_empty() {
197201
result.truncate(last_line);
198202
}
199-
return Ok(result);
203+
204+
Ok(result)
200205
}
201206

202207
pub fn string_value<'a>(input: &mut TokenStream<'a>)

src/tokenizer.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,26 @@ impl<'a> Resetable for TokenStream<'a> {
8484
// NOTE: we expect that first character is always digit or minus, as returned
8585
// by tokenizer
8686
fn check_int(value: &str) -> bool {
87-
return value == "0" || value == "-0" ||
87+
value == "0" || value == "-0" ||
8888
(!value.starts_with('0') && value != "-" && !value.starts_with("-0")
89-
&& value[1..].chars().all(|x| x >= '0' && x <= '9'));
89+
&& value[1..].chars().all(|x| x >= '0' && x <= '9'))
9090
}
9191

9292
fn check_dec(value: &str) -> bool {
93-
return value.len() > 0 && value.chars().all(|x| x >= '0' && x <= '9');
93+
!value.is_empty() && value.chars().all(|x| x >= '0' && x <= '9')
9494
}
9595

9696
fn check_exp(value: &str) -> bool {
97-
return (value.starts_with('-') || value.starts_with('+')) &&
97+
(value.starts_with('-') || value.starts_with('+')) &&
9898
value.len() >= 2 &&
99-
value[1..].chars().all(|x| x >= '0' && x <= '9');
99+
value[1..].chars().all(|x| x >= '0' && x <= '9')
100100
}
101101

102102
fn check_float(value: &str, exponent: Option<usize>, real: Option<usize>)
103103
-> bool
104104
{
105105
match (exponent, real) {
106-
(Some(e), Some(r)) if e < r => return false,
106+
(Some(e), Some(r)) if e < r => false,
107107
(Some(e), Some(r))
108108
=> check_int(&value[..r]) &&
109109
check_dec(&value[r+1..e]) &&
@@ -125,8 +125,9 @@ impl<'a> TokenStream<'a> {
125125
next_state: None,
126126
};
127127
me.skip_whitespace();
128-
return me;
128+
me
129129
}
130+
130131
fn peek_token(&mut self)
131132
-> Result<(Kind, usize), Error<Token<'a>, Token<'a>>>
132133
{
@@ -150,7 +151,7 @@ impl<'a> TokenStream<'a> {
150151
return Ok((Punctuator, 3))
151152
} else {
152153
return Err(Error::unexpected_message(
153-
format_args!("bare dot {:?} is not suppored, \
154+
format_args!("bare dot {:?} is not supported, \
154155
only \"...\"", cur_char)));
155156
}
156157
}
@@ -223,7 +224,7 @@ impl<'a> TokenStream<'a> {
223224
} else {
224225
let mut prev_char = cur_char;
225226
let mut nchars = 1;
226-
while let Some((idx, cur_char)) = iter.next() {
227+
for (idx, cur_char) in iter {
227228
nchars += 1;
228229
match cur_char {
229230
'"' if prev_char == '\\' => {}
@@ -250,6 +251,7 @@ impl<'a> TokenStream<'a> {
250251
format_args!("unexpected character {:?}", cur_char))),
251252
}
252253
}
254+
253255
fn skip_whitespace(&mut self) {
254256
let mut iter = self.buf[self.off..].char_indices();
255257
let idx = loop {
@@ -286,6 +288,7 @@ impl<'a> TokenStream<'a> {
286288
};
287289
self.off += idx;
288290
}
291+
289292
fn update_position(&mut self, len: usize) {
290293
let val = &self.buf[self.off..][..len];
291294
self.off += len;
@@ -294,7 +297,7 @@ impl<'a> TokenStream<'a> {
294297
if lines > 0 {
295298
let line_offset = val.rfind('\n').unwrap()+1;
296299
let num = val[line_offset..].chars().count();
297-
self.position.column = num+1;
300+
self.position.column = num + 1;
298301
} else {
299302
let num = val.chars().count();
300303
self.position.column += num;

0 commit comments

Comments
 (0)