mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
a lot of clippy::style fixes
This commit is contained in:
parent
ae7e55c1dd
commit
202b51bc7b
19 changed files with 52 additions and 69 deletions
|
@ -410,7 +410,7 @@ impl CrateId {
|
||||||
|
|
||||||
impl CrateData {
|
impl CrateData {
|
||||||
fn add_dep(&mut self, name: CrateName, crate_id: CrateId) {
|
fn add_dep(&mut self, name: CrateName, crate_id: CrateId) {
|
||||||
self.dependencies.push(Dependency { name, crate_id })
|
self.dependencies.push(Dependency { crate_id, name })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,9 +255,9 @@ impl Builder {
|
||||||
fn make_dnf(expr: CfgExpr) -> CfgExpr {
|
fn make_dnf(expr: CfgExpr) -> CfgExpr {
|
||||||
match expr {
|
match expr {
|
||||||
CfgExpr::Invalid | CfgExpr::Atom(_) | CfgExpr::Not(_) => 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) => {
|
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))
|
CfgExpr::Any(distribute_conj(&e))
|
||||||
}
|
}
|
||||||
|
@ -300,8 +300,8 @@ fn distribute_conj(conj: &[CfgExpr]) -> Vec<CfgExpr> {
|
||||||
fn make_nnf(expr: CfgExpr) -> CfgExpr {
|
fn make_nnf(expr: CfgExpr) -> CfgExpr {
|
||||||
match expr {
|
match expr {
|
||||||
CfgExpr::Invalid | CfgExpr::Atom(_) => expr,
|
CfgExpr::Invalid | CfgExpr::Atom(_) => expr,
|
||||||
CfgExpr::Any(expr) => CfgExpr::Any(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(|expr| make_nnf(expr)).collect()),
|
CfgExpr::All(expr) => CfgExpr::All(expr.into_iter().map(make_nnf).collect()),
|
||||||
CfgExpr::Not(operand) => match *operand {
|
CfgExpr::Not(operand) => match *operand {
|
||||||
CfgExpr::Invalid | CfgExpr::Atom(_) => CfgExpr::Not(operand.clone()), // Original negated expr
|
CfgExpr::Invalid | CfgExpr::Atom(_) => CfgExpr::Not(operand.clone()), // Original negated expr
|
||||||
CfgExpr::Not(expr) => {
|
CfgExpr::Not(expr) => {
|
||||||
|
|
|
@ -304,7 +304,7 @@ impl BindingsBuilder {
|
||||||
link_nodes: &'a Vec<LinkNode<Rc<BindingKind>>>,
|
link_nodes: &'a Vec<LinkNode<Rc<BindingKind>>>,
|
||||||
nodes: &mut Vec<&'a 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::Node(it) => nodes.push(it),
|
||||||
LinkNode::Parent { idx, len } => self.collect_nodes_ref(*idx, *len, nodes),
|
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(|ident| Some(tt::Leaf::from(ident.clone()).into()))
|
||||||
.map_err(|()| err!("expected ident")),
|
.map_err(|()| err!("expected ident")),
|
||||||
"tt" => input.expect_tt().map(Some).map_err(|()| err!()),
|
"tt" => input.expect_tt().map(Some).map_err(|()| err!()),
|
||||||
"lifetime" => input
|
"lifetime" => {
|
||||||
.expect_lifetime()
|
input.expect_lifetime().map(Some).map_err(|()| err!("expected lifetime"))
|
||||||
.map(|tt| Some(tt))
|
}
|
||||||
.map_err(|()| err!("expected lifetime")),
|
|
||||||
"literal" => {
|
"literal" => {
|
||||||
let neg = input.eat_char('-');
|
let neg = input.eat_char('-');
|
||||||
input
|
input
|
||||||
|
|
|
@ -356,6 +356,6 @@ impl<T> ExpandResult<T> {
|
||||||
|
|
||||||
impl<T: Default> From<Result<T, ExpandError>> for ExpandResult<T> {
|
impl<T: Default> From<Result<T, ExpandError>> for ExpandResult<T> {
|
||||||
fn from(result: Result<T, ExpandError>) -> Self {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl<'a> Iterator for OpDelimitedIter<'a> {
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
let len = self.inner.len() + if self.delimited.is_some() { 2 } else { 0 };
|
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))
|
(remain, Some(remain))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,7 +362,7 @@ trait TokenConvertor {
|
||||||
if let Some((kind, closed)) = delim {
|
if let Some((kind, closed)) = delim {
|
||||||
let mut subtree = tt::Subtree::default();
|
let mut subtree = tt::Subtree::default();
|
||||||
let (id, idx) = self.id_alloc().open_delim(range);
|
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) {
|
while self.peek().map(|it| it.kind() != closed).unwrap_or(false) {
|
||||||
self.collect_leaf(&mut subtree.token_trees);
|
self.collect_leaf(&mut subtree.token_trees);
|
||||||
|
|
|
@ -242,11 +242,8 @@ impl GlobalState {
|
||||||
}
|
}
|
||||||
BuildDataProgress::End(collector) => {
|
BuildDataProgress::End(collector) => {
|
||||||
self.fetch_build_data_completed();
|
self.fetch_build_data_completed();
|
||||||
let workspaces = (*self.workspaces)
|
let workspaces =
|
||||||
.clone()
|
(*self.workspaces).clone().into_iter().map(Ok).collect();
|
||||||
.into_iter()
|
|
||||||
.map(|it| Ok(it))
|
|
||||||
.collect();
|
|
||||||
self.switch_workspaces(workspaces, Some(collector));
|
self.switch_workspaces(workspaces, Some(collector));
|
||||||
(Some(Progress::End), None)
|
(Some(Progress::End), None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,7 +237,7 @@ impl GlobalState {
|
||||||
None => None,
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl<'a> Project<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn server(self) -> Server {
|
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();
|
static INIT: Once = Once::new();
|
||||||
INIT.call_once(|| {
|
INIT.call_once(|| {
|
||||||
env_logger::builder().is_test(true).parse_env("RA_LOG").try_init().unwrap();
|
env_logger::builder().is_test(true).parse_env("RA_LOG").try_init().unwrap();
|
||||||
|
|
|
@ -595,7 +595,7 @@ impl IndentLevel {
|
||||||
pub fn from_node(node: &SyntaxNode) -> IndentLevel {
|
pub fn from_node(node: &SyntaxNode) -> IndentLevel {
|
||||||
match node.first_token() {
|
match node.first_token() {
|
||||||
Some(it) => Self::from_token(&it),
|
Some(it) => Self::from_token(&it),
|
||||||
None => return IndentLevel(0),
|
None => IndentLevel(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,16 +11,16 @@ impl ast::AttrsOwner for ast::Expr {}
|
||||||
|
|
||||||
impl ast::Expr {
|
impl ast::Expr {
|
||||||
pub fn is_block_like(&self) -> bool {
|
pub fn is_block_like(&self) -> bool {
|
||||||
match self {
|
matches!(
|
||||||
|
self,
|
||||||
ast::Expr::IfExpr(_)
|
ast::Expr::IfExpr(_)
|
||||||
| ast::Expr::LoopExpr(_)
|
| ast::Expr::LoopExpr(_)
|
||||||
| ast::Expr::ForExpr(_)
|
| ast::Expr::ForExpr(_)
|
||||||
| ast::Expr::WhileExpr(_)
|
| ast::Expr::WhileExpr(_)
|
||||||
| ast::Expr::BlockExpr(_)
|
| ast::Expr::BlockExpr(_)
|
||||||
| ast::Expr::MatchExpr(_)
|
| ast::Expr::MatchExpr(_)
|
||||||
| ast::Expr::EffectExpr(_) => true,
|
| ast::Expr::EffectExpr(_)
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name_ref(&self) -> Option<ast::NameRef> {
|
pub fn name_ref(&self) -> Option<ast::NameRef> {
|
||||||
|
@ -151,20 +151,20 @@ pub enum BinOp {
|
||||||
|
|
||||||
impl BinOp {
|
impl BinOp {
|
||||||
pub fn is_assignment(self) -> bool {
|
pub fn is_assignment(self) -> bool {
|
||||||
match self {
|
matches!(
|
||||||
|
self,
|
||||||
BinOp::Assignment
|
BinOp::Assignment
|
||||||
| BinOp::AddAssign
|
| BinOp::AddAssign
|
||||||
| BinOp::DivAssign
|
| BinOp::DivAssign
|
||||||
| BinOp::MulAssign
|
| BinOp::MulAssign
|
||||||
| BinOp::RemAssign
|
| BinOp::RemAssign
|
||||||
| BinOp::ShrAssign
|
| BinOp::ShrAssign
|
||||||
| BinOp::ShlAssign
|
| BinOp::ShlAssign
|
||||||
| BinOp::SubAssign
|
| BinOp::SubAssign
|
||||||
| BinOp::BitOrAssign
|
| BinOp::BitOrAssign
|
||||||
| BinOp::BitAndAssign
|
| BinOp::BitAndAssign
|
||||||
| BinOp::BitXorAssign => true,
|
| BinOp::BitXorAssign
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,7 @@ impl From<ast::MacroDef> for Macro {
|
||||||
|
|
||||||
impl AstNode for Macro {
|
impl AstNode for Macro {
|
||||||
fn can_cast(kind: SyntaxKind) -> bool {
|
fn can_cast(kind: SyntaxKind) -> bool {
|
||||||
match kind {
|
matches!(kind, SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF)
|
||||||
SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
let res = match syntax.kind() {
|
let res = match syntax.kind() {
|
||||||
|
@ -462,10 +459,8 @@ impl ast::FieldExpr {
|
||||||
pub fn field_access(&self) -> Option<FieldKind> {
|
pub fn field_access(&self) -> Option<FieldKind> {
|
||||||
if let Some(nr) = self.name_ref() {
|
if let Some(nr) = self.name_ref() {
|
||||||
Some(FieldKind::Name(nr))
|
Some(FieldKind::Name(nr))
|
||||||
} else if let Some(tok) = self.index_token() {
|
|
||||||
Some(FieldKind::Index(tok))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
self.index_token().map(FieldKind::Index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -482,16 +477,10 @@ impl ast::SlicePat {
|
||||||
let prefix = args
|
let prefix = args
|
||||||
.peeking_take_while(|p| match p {
|
.peeking_take_while(|p| match p {
|
||||||
ast::Pat::RestPat(_) => false,
|
ast::Pat::RestPat(_) => false,
|
||||||
ast::Pat::IdentPat(bp) => match bp.pat() {
|
ast::Pat::IdentPat(bp) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))),
|
||||||
Some(ast::Pat::RestPat(_)) => false,
|
|
||||||
_ => true,
|
|
||||||
},
|
|
||||||
ast::Pat::RefPat(rp) => match rp.pat() {
|
ast::Pat::RefPat(rp) => match rp.pat() {
|
||||||
Some(ast::Pat::RestPat(_)) => false,
|
Some(ast::Pat::RestPat(_)) => false,
|
||||||
Some(ast::Pat::IdentPat(bp)) => match bp.pat() {
|
Some(ast::Pat::IdentPat(bp)) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))),
|
||||||
Some(ast::Pat::RestPat(_)) => false,
|
|
||||||
_ => true,
|
|
||||||
},
|
|
||||||
_ => true,
|
_ => true,
|
||||||
},
|
},
|
||||||
_ => true,
|
_ => true,
|
||||||
|
|
|
@ -494,9 +494,8 @@ pub trait HasFormatSpecifier: AstToken {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
while let Some((_, Ok(next_char))) = chars.peek() {
|
while let Some((_, Ok(next_char))) = chars.peek() {
|
||||||
match next_char {
|
if next_char == &'{' {
|
||||||
'{' => break,
|
break;
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
chars.next();
|
chars.next();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl CheckReparse {
|
||||||
TextRange::at(delete_start.try_into().unwrap(), delete_len.try_into().unwrap());
|
TextRange::at(delete_start.try_into().unwrap(), delete_len.try_into().unwrap());
|
||||||
let edited_text =
|
let edited_text =
|
||||||
format!("{}{}{}", &text[..delete_start], &insert, &text[delete_start + delete_len..]);
|
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 })
|
Some(CheckReparse { text, edit, edited_text })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
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 all_supers(subpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -239,9 +239,8 @@ impl Subtree {
|
||||||
|
|
||||||
let mut res = String::new();
|
let mut res = String::new();
|
||||||
res.push_str(delim.0);
|
res.push_str(delim.0);
|
||||||
let mut iter = self.token_trees.iter();
|
|
||||||
let mut last = None;
|
let mut last = None;
|
||||||
while let Some(child) = iter.next() {
|
for child in &self.token_trees {
|
||||||
let s = match child {
|
let s = match child {
|
||||||
TokenTree::Leaf(it) => {
|
TokenTree::Leaf(it) => {
|
||||||
let s = match it {
|
let s = match it {
|
||||||
|
|
|
@ -707,7 +707,7 @@ fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str
|
||||||
let mut to_remove = Vec::new();
|
let mut to_remove = Vec::new();
|
||||||
for (i, field) in node.fields.iter().enumerate() {
|
for (i, field) in node.fields.iter().enumerate() {
|
||||||
let method_name = field.method_name().to_string();
|
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);
|
to_remove.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ fn main() -> Result<()> {
|
||||||
match flags.subcommand {
|
match flags.subcommand {
|
||||||
flags::XtaskCmd::Help(_) => {
|
flags::XtaskCmd::Help(_) => {
|
||||||
println!("{}", flags::Xtask::HELP);
|
println!("{}", flags::Xtask::HELP);
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
flags::XtaskCmd::Install(cmd) => cmd.run(),
|
flags::XtaskCmd::Install(cmd) => cmd.run(),
|
||||||
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(),
|
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(),
|
||||||
|
|
|
@ -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 = &[
|
let ignore = &[
|
||||||
// The documentation in string literals may contain anything for its own purposes
|
// The documentation in string literals may contain anything for its own purposes
|
||||||
"ide_completion/src/generated_lint_completions.rs",
|
"ide_completion/src/generated_lint_completions.rs",
|
||||||
|
|
Loading…
Reference in a new issue