a lot of clippy::style fixes

This commit is contained in:
Matthias Krüger 2021-03-21 15:33:18 +01:00
parent ae7e55c1dd
commit 202b51bc7b
19 changed files with 52 additions and 69 deletions

View file

@ -410,7 +410,7 @@ impl CrateId {
impl CrateData {
fn add_dep(&mut self, name: CrateName, crate_id: CrateId) {
self.dependencies.push(Dependency { name, crate_id })
self.dependencies.push(Dependency { crate_id, name })
}
}

View file

@ -255,9 +255,9 @@ impl Builder {
fn make_dnf(expr: CfgExpr) -> CfgExpr {
match expr {
CfgExpr::Invalid | CfgExpr::Atom(_) | CfgExpr::Not(_) => expr,
CfgExpr::Any(e) => CfgExpr::Any(e.into_iter().map(|expr| make_dnf(expr)).collect()),
CfgExpr::Any(e) => CfgExpr::Any(e.into_iter().map(make_dnf).collect()),
CfgExpr::All(e) => {
let e = e.into_iter().map(|expr| make_nnf(expr)).collect::<Vec<_>>();
let e = e.into_iter().map(make_nnf).collect::<Vec<_>>();
CfgExpr::Any(distribute_conj(&e))
}
@ -300,8 +300,8 @@ fn distribute_conj(conj: &[CfgExpr]) -> Vec<CfgExpr> {
fn make_nnf(expr: CfgExpr) -> CfgExpr {
match expr {
CfgExpr::Invalid | CfgExpr::Atom(_) => expr,
CfgExpr::Any(expr) => CfgExpr::Any(expr.into_iter().map(|expr| make_nnf(expr)).collect()),
CfgExpr::All(expr) => CfgExpr::All(expr.into_iter().map(|expr| make_nnf(expr)).collect()),
CfgExpr::Any(expr) => CfgExpr::Any(expr.into_iter().map(make_nnf).collect()),
CfgExpr::All(expr) => CfgExpr::All(expr.into_iter().map(make_nnf).collect()),
CfgExpr::Not(operand) => match *operand {
CfgExpr::Invalid | CfgExpr::Atom(_) => CfgExpr::Not(operand.clone()), // Original negated expr
CfgExpr::Not(expr) => {

View file

@ -304,7 +304,7 @@ impl BindingsBuilder {
link_nodes: &'a Vec<LinkNode<Rc<BindingKind>>>,
nodes: &mut Vec<&'a Rc<BindingKind>>,
) {
link_nodes.into_iter().for_each(|it| match it {
link_nodes.iter().for_each(|it| match it {
LinkNode::Node(it) => nodes.push(it),
LinkNode::Parent { idx, len } => self.collect_nodes_ref(*idx, *len, nodes),
});
@ -713,10 +713,9 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
.map(|ident| Some(tt::Leaf::from(ident.clone()).into()))
.map_err(|()| err!("expected ident")),
"tt" => input.expect_tt().map(Some).map_err(|()| err!()),
"lifetime" => input
.expect_lifetime()
.map(|tt| Some(tt))
.map_err(|()| err!("expected lifetime")),
"lifetime" => {
input.expect_lifetime().map(Some).map_err(|()| err!("expected lifetime"))
}
"literal" => {
let neg = input.eat_char('-');
input

View file

@ -356,6 +356,6 @@ impl<T> ExpandResult<T> {
impl<T: Default> From<Result<T, ExpandError>> for ExpandResult<T> {
fn from(result: Result<T, ExpandError>) -> Self {
result.map_or_else(|e| Self::only_err(e), |it| Self::ok(it))
result.map_or_else(Self::only_err, Self::ok)
}
}

View file

@ -57,7 +57,7 @@ impl<'a> Iterator for OpDelimitedIter<'a> {
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.inner.len() + if self.delimited.is_some() { 2 } else { 0 };
let remain = len.checked_sub(self.idx).unwrap_or(0);
let remain = len.saturating_sub(self.idx);
(remain, Some(remain))
}
}

View file

@ -362,7 +362,7 @@ trait TokenConvertor {
if let Some((kind, closed)) = delim {
let mut subtree = tt::Subtree::default();
let (id, idx) = self.id_alloc().open_delim(range);
subtree.delimiter = Some(tt::Delimiter { kind, id });
subtree.delimiter = Some(tt::Delimiter { id, kind });
while self.peek().map(|it| it.kind() != closed).unwrap_or(false) {
self.collect_leaf(&mut subtree.token_trees);

View file

@ -242,11 +242,8 @@ impl GlobalState {
}
BuildDataProgress::End(collector) => {
self.fetch_build_data_completed();
let workspaces = (*self.workspaces)
.clone()
.into_iter()
.map(|it| Ok(it))
.collect();
let workspaces =
(*self.workspaces).clone().into_iter().map(Ok).collect();
self.switch_workspaces(workspaces, Some(collector));
(Some(Progress::End), None)
}

View file

@ -237,7 +237,7 @@ impl GlobalState {
None => None,
};
if &*self.workspaces == &workspaces && self.workspace_build_data == workspace_build_data {
if *self.workspaces == workspaces && self.workspace_build_data == workspace_build_data {
return;
}

View file

@ -54,7 +54,7 @@ impl<'a> Project<'a> {
}
pub(crate) fn server(self) -> Server {
let tmp_dir = self.tmp_dir.unwrap_or_else(|| TestDir::new());
let tmp_dir = self.tmp_dir.unwrap_or_else(TestDir::new);
static INIT: Once = Once::new();
INIT.call_once(|| {
env_logger::builder().is_test(true).parse_env("RA_LOG").try_init().unwrap();

View file

@ -595,7 +595,7 @@ impl IndentLevel {
pub fn from_node(node: &SyntaxNode) -> IndentLevel {
match node.first_token() {
Some(it) => Self::from_token(&it),
None => return IndentLevel(0),
None => IndentLevel(0),
}
}

View file

@ -11,16 +11,16 @@ impl ast::AttrsOwner for ast::Expr {}
impl ast::Expr {
pub fn is_block_like(&self) -> bool {
match self {
matches!(
self,
ast::Expr::IfExpr(_)
| ast::Expr::LoopExpr(_)
| ast::Expr::ForExpr(_)
| ast::Expr::WhileExpr(_)
| ast::Expr::BlockExpr(_)
| ast::Expr::MatchExpr(_)
| ast::Expr::EffectExpr(_) => true,
_ => false,
}
| ast::Expr::LoopExpr(_)
| ast::Expr::ForExpr(_)
| ast::Expr::WhileExpr(_)
| ast::Expr::BlockExpr(_)
| ast::Expr::MatchExpr(_)
| ast::Expr::EffectExpr(_)
)
}
pub fn name_ref(&self) -> Option<ast::NameRef> {
@ -151,20 +151,20 @@ pub enum BinOp {
impl BinOp {
pub fn is_assignment(self) -> bool {
match self {
matches!(
self,
BinOp::Assignment
| BinOp::AddAssign
| BinOp::DivAssign
| BinOp::MulAssign
| BinOp::RemAssign
| BinOp::ShrAssign
| BinOp::ShlAssign
| BinOp::SubAssign
| BinOp::BitOrAssign
| BinOp::BitAndAssign
| BinOp::BitXorAssign => true,
_ => false,
}
| BinOp::AddAssign
| BinOp::DivAssign
| BinOp::MulAssign
| BinOp::RemAssign
| BinOp::ShrAssign
| BinOp::ShlAssign
| BinOp::SubAssign
| BinOp::BitOrAssign
| BinOp::BitAndAssign
| BinOp::BitXorAssign
)
}
}

View file

@ -58,10 +58,7 @@ impl From<ast::MacroDef> for Macro {
impl AstNode for Macro {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF => true,
_ => false,
}
matches!(kind, SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF)
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
let res = match syntax.kind() {
@ -462,10 +459,8 @@ impl ast::FieldExpr {
pub fn field_access(&self) -> Option<FieldKind> {
if let Some(nr) = self.name_ref() {
Some(FieldKind::Name(nr))
} else if let Some(tok) = self.index_token() {
Some(FieldKind::Index(tok))
} else {
None
self.index_token().map(FieldKind::Index)
}
}
}
@ -482,16 +477,10 @@ impl ast::SlicePat {
let prefix = args
.peeking_take_while(|p| match p {
ast::Pat::RestPat(_) => false,
ast::Pat::IdentPat(bp) => match bp.pat() {
Some(ast::Pat::RestPat(_)) => false,
_ => true,
},
ast::Pat::IdentPat(bp) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))),
ast::Pat::RefPat(rp) => match rp.pat() {
Some(ast::Pat::RestPat(_)) => false,
Some(ast::Pat::IdentPat(bp)) => match bp.pat() {
Some(ast::Pat::RestPat(_)) => false,
_ => true,
},
Some(ast::Pat::IdentPat(bp)) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))),
_ => true,
},
_ => true,

View file

@ -494,9 +494,8 @@ pub trait HasFormatSpecifier: AstToken {
}
_ => {
while let Some((_, Ok(next_char))) = chars.peek() {
match next_char {
'{' => break,
_ => {}
if next_char == &'{' {
break;
}
chars.next();
}

View file

@ -43,7 +43,7 @@ impl CheckReparse {
TextRange::at(delete_start.try_into().unwrap(), delete_len.try_into().unwrap());
let edited_text =
format!("{}{}{}", &text[..delete_start], &insert, &text[delete_start + delete_len..]);
let edit = Indel { delete, insert };
let edit = Indel { insert, delete };
Some(CheckReparse { text, edit, edited_text })
}

View file

@ -297,7 +297,7 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
}
};
}
return None;
None
}
fn all_supers(path: &ast::Path) -> bool {
@ -314,7 +314,7 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
return all_supers(subpath);
}
return true;
true
}
}

View file

@ -239,9 +239,8 @@ impl Subtree {
let mut res = String::new();
res.push_str(delim.0);
let mut iter = self.token_trees.iter();
let mut last = None;
while let Some(child) = iter.next() {
for child in &self.token_trees {
let s = match child {
TokenTree::Leaf(it) => {
let s = match it {

View file

@ -707,7 +707,7 @@ fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str
let mut to_remove = Vec::new();
for (i, field) in node.fields.iter().enumerate() {
let method_name = field.method_name().to_string();
if methods.iter().any(|&it| it == &method_name) {
if methods.iter().any(|&it| it == method_name) {
to_remove.push(i);
}
}

View file

@ -37,7 +37,7 @@ fn main() -> Result<()> {
match flags.subcommand {
flags::XtaskCmd::Help(_) => {
println!("{}", flags::Xtask::HELP);
return Ok(());
Ok(())
}
flags::XtaskCmd::Install(cmd) => cmd.run(),
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(),

View file

@ -193,7 +193,7 @@ https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/#redo-after-
}
}
fn deny_clippy(path: &PathBuf, text: &String) {
fn deny_clippy(path: &Path, text: &str) {
let ignore = &[
// The documentation in string literals may contain anything for its own purposes
"ide_completion/src/generated_lint_completions.rs",