Skip to content

Commit 8845b71

Browse files
authored
Merge pull request #99 from Centril/clippy-fixes-and-others
Clippy fixes and others
2 parents 99c9bf7 + 7218dbb commit 8845b71

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

src/generate/rust.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,18 @@ impl<Pat: PartialEq> RuleWithNamedFields<Pat> {
6464
.collect();
6565
for (field, paths) in &self.fields {
6666
for path in paths {
67-
if path.len() == 0 {
68-
return None;
69-
}
70-
if path.len() == 1 {
71-
if variants[path[0]].name != "" {
72-
return None;
67+
match path[..] {
68+
[] => return None,
69+
[variant] if variants[variant].name != "" => return None,
70+
[variant] => variants[variant].name = field,
71+
// FIXME: use [variant, rest @ ..] when possible.
72+
_ => {
73+
variants[path[0]]
74+
.fields
75+
.entry(&field[..])
76+
.or_insert_with(OrderSet::new)
77+
.insert(path[1..].to_vec());
7378
}
74-
variants[path[0]].name = field;
75-
} else {
76-
variants[path[0]]
77-
.fields
78-
.entry(&field[..])
79-
.or_insert_with(OrderSet::new)
80-
.insert(path[1..].to_vec());
8179
}
8280
}
8381
}
@@ -711,17 +709,12 @@ impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
711709
Thunk::new(move |cont| match (self, rc_self_and_rules) {
712710
(Rule::Empty, _) => cont,
713711
(Rule::Eat(pat), _) => {
714-
// HACK(eddyb) remove extra variables post-NLL
715712
let pat = pat.rust_matcher();
716-
let cont = check(quote!(let Some(_range) = p.input_consume_left(_range, #pat)))
717-
.apply(cont);
718-
cont
713+
check(quote!(let Some(_range) = p.input_consume_left(_range, #pat))).apply(cont)
719714
}
720715
(Rule::NegativeLookahead(pat), _) => {
721-
// HACK(eddyb) remove extra variables post-NLL
722716
let pat = pat.rust_matcher();
723-
let cont = check(quote!(p.input_consume_left(_range, #pat).is_none())).apply(cont);
724-
cont
717+
check(quote!(p.input_consume_left(_range, #pat).is_none())).apply(cont)
725718
}
726719
(Rule::Call(r), _) => call(Rc::new(CodeLabel::NamedRule(r.clone()))).apply(cont),
727720
(Rule::Concat([left, right]), None) => {

src/generate/src.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,8 @@ impl Src {
296296
};
297297
if new_line {
298298
frag.lines.push(Line::default());
299-
} else {
300-
if !frag.last().is_empty() {
301-
frag.push(Elem::Char(' ', Spacing::Alone));
302-
}
299+
} else if !frag.last().is_empty() {
300+
frag.push(Elem::Char(' ', Spacing::Alone));
303301
}
304302
}
305303
}

src/indexing_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ unsafe impl Contiguous for Str {
3333
self.0.as_ptr()
3434
}
3535
fn end(&self) -> *const Self::Item {
36-
unsafe { self.begin().offset(self.0.len() as isize) }
36+
unsafe { self.begin().add(self.0.len()) }
3737
}
3838
fn as_slice(&self) -> &[Self::Item] {
3939
self.0.as_bytes()

src/runtime.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl fmt::Debug for LineColumn {
6161
impl LineColumn {
6262
fn count(prefix: &str) -> Self {
6363
let (line, column) = prefix
64-
.split("\n")
64+
.split('\n')
6565
.enumerate()
6666
.last()
6767
.map_or((0, 0), |(i, s)| (i, s.chars().count()));
@@ -407,7 +407,8 @@ impl<'i, C: CodeLabel> Threads<'i, C> {
407407
let old = self.seen.iter().rev().next().cloned();
408408
if let Some(old) = old {
409409
// TODO also check end point for proper "t.range includes old.range".
410-
if !t.range.contains(old.range.start()).is_some() {
410+
let new_includes_old = t.range.contains(old.range.start()).is_some();
411+
if !new_includes_old {
411412
self.seen.remove(&old);
412413
continue;
413414
}

0 commit comments

Comments
 (0)