Fix miscellaneous Clippy lints

This commit is contained in:
Aramis Razzaghipour 2021-10-03 23:45:08 +11:00
parent 55c0b86cde
commit eff195852d
No known key found for this signature in database
GPG key ID: F788F7E990136003
21 changed files with 40 additions and 51 deletions

View file

@ -112,14 +112,14 @@ impl TreeDiff {
pub fn into_text_edit(&self, builder: &mut TextEditBuilder) {
let _p = profile::span("into_text_edit");
for (anchor, to) in self.insertions.iter() {
for (anchor, to) in &self.insertions {
let offset = match anchor {
TreeDiffInsertPos::After(it) => it.text_range().end(),
TreeDiffInsertPos::AsFirstChild(it) => it.text_range().start(),
};
to.iter().for_each(|to| builder.insert(offset, to.to_string()));
}
for (from, to) in self.replacements.iter() {
for (from, to) in &self.replacements {
builder.replace(from.text_range(), to.to_string());
}
for text_range in self.deletions.iter().map(SyntaxElement::text_range) {
@ -217,9 +217,8 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
cov_mark::hit!(diff_insertions);
insert = true;
break;
} else {
look_ahead_scratch.push(rhs_child);
}
look_ahead_scratch.push(rhs_child);
}
let drain = look_ahead_scratch.drain(..);
if insert {

View file

@ -275,7 +275,7 @@ impl ast::PathSegment {
impl ast::UseTree {
pub fn remove(&self) {
for &dir in [Direction::Next, Direction::Prev].iter() {
for dir in [Direction::Next, Direction::Prev] {
if let Some(next_use_tree) = neighbor(self, dir) {
let separators = self
.syntax()

View file

@ -276,9 +276,9 @@ impl ast::Path {
impl ast::Use {
pub fn is_simple_glob(&self) -> bool {
self.use_tree()
.map(|use_tree| use_tree.use_tree_list().is_none() && use_tree.star_token().is_some())
.unwrap_or(false)
self.use_tree().map_or(false, |use_tree| {
use_tree.use_tree_list().is_none() && use_tree.star_token().is_some()
})
}
}

View file

@ -688,7 +688,7 @@ impl Radix {
pub const ALL: &'static [Radix] =
&[Radix::Binary, Radix::Octal, Radix::Decimal, Radix::Hexadecimal];
const fn prefix_len(&self) -> usize {
const fn prefix_len(self) -> usize {
match self {
Self::Decimal => 0,
_ => 2,

View file

@ -44,8 +44,7 @@ impl<'t> TokenSource for TextTokenSource<'t> {
fn is_keyword(&self, kw: &str) -> bool {
self.token_offset_pairs
.get(self.curr.1)
.map(|(token, offset)| &self.text[TextRange::at(*offset, token.len)] == kw)
.unwrap_or(false)
.map_or(false, |(token, offset)| &self.text[TextRange::at(*offset, token.len)] == kw)
}
}
@ -55,8 +54,7 @@ fn mk_token(pos: usize, token_offset_pairs: &[(Token, TextSize)]) -> parser::Tok
token.kind,
token_offset_pairs
.get(pos + 1)
.map(|(_, next_offset)| offset + token.len == *next_offset)
.unwrap_or(false),
.map_or(false, |(_, next_offset)| offset + token.len == *next_offset),
),
None => (EOF, false),
};

View file

@ -215,7 +215,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
.flat_map(|node| node.traits.iter().map(move |t| (t, node)))
.into_group_map()
.into_iter()
.sorted_by_key(|(k, _)| k.clone())
.sorted_by_key(|(k, _)| *k)
.map(|(trait_name, nodes)| {
let name = format_ident!("Any{}", trait_name);
let trait_name = format_ident!("{}", trait_name);
@ -558,12 +558,13 @@ impl Field {
}
fn lower(grammar: &Grammar) -> AstSrc {
let mut res = AstSrc::default();
res.tokens = "Whitespace Comment String ByteString IntNumber FloatNumber"
.split_ascii_whitespace()
.map(|it| it.to_string())
.collect::<Vec<_>>();
let mut res = AstSrc {
tokens: "Whitespace Comment String ByteString IntNumber FloatNumber"
.split_ascii_whitespace()
.map(|it| it.to_string())
.collect::<Vec<_>>(),
..Default::default()
};
let nodes = grammar.iter().collect::<Vec<_>>();