mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Some clippy fixes
This commit is contained in:
parent
5806195bc1
commit
b441b4e8ef
17 changed files with 23 additions and 29 deletions
|
@ -50,7 +50,7 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Opt
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for early return and continue
|
// check for early return and continue
|
||||||
let first_in_then_block = then_block.syntax().first_child()?.clone();
|
let first_in_then_block = then_block.syntax().first_child()?;
|
||||||
if ast::ReturnExpr::can_cast(first_in_then_block.kind())
|
if ast::ReturnExpr::can_cast(first_in_then_block.kind())
|
||||||
|| ast::ContinueExpr::can_cast(first_in_then_block.kind())
|
|| ast::ContinueExpr::can_cast(first_in_then_block.kind())
|
||||||
|| first_in_then_block
|
|| first_in_then_block
|
||||||
|
|
|
@ -51,10 +51,8 @@ pub(crate) fn inline_local_varialbe(ctx: AssistCtx<impl HirDatabase>) -> Option<
|
||||||
let mut wrap_in_parens = vec![true; refs.len()];
|
let mut wrap_in_parens = vec![true; refs.len()];
|
||||||
|
|
||||||
for (i, desc) in refs.iter().enumerate() {
|
for (i, desc) in refs.iter().enumerate() {
|
||||||
let usage_node = ctx
|
let usage_node =
|
||||||
.covering_node_for_range(desc.range)
|
ctx.covering_node_for_range(desc.range).ancestors().find_map(ast::PathExpr::cast)?;
|
||||||
.ancestors()
|
|
||||||
.find_map(|node| ast::PathExpr::cast(node))?;
|
|
||||||
let usage_parent_option = usage_node.syntax().parent().and_then(ast::Expr::cast);
|
let usage_parent_option = usage_node.syntax().parent().and_then(ast::Expr::cast);
|
||||||
let usage_parent = match usage_parent_option {
|
let usage_parent = match usage_parent_option {
|
||||||
Some(u) => u,
|
Some(u) => u,
|
||||||
|
|
|
@ -131,7 +131,7 @@ pub(crate) fn remove_hash(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||||
ctx.add_assist(AssistId("remove_hash"), "remove hash from raw string", |edit| {
|
ctx.add_assist(AssistId("remove_hash"), "remove hash from raw string", |edit| {
|
||||||
edit.target(token.text_range());
|
edit.target(token.text_range());
|
||||||
let result = &text[2..text.len() - 1];
|
let result = &text[2..text.len() - 1];
|
||||||
let result = if result.starts_with("\"") {
|
let result = if result.starts_with('\"') {
|
||||||
// no more hash, escape
|
// no more hash, escape
|
||||||
let internal_str = &result[1..result.len() - 1];
|
let internal_str = &result[1..result.len() - 1];
|
||||||
format!("\"{}\"", internal_str.escape_default().to_string())
|
format!("\"{}\"", internal_str.escape_default().to_string())
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl FnCallNode {
|
||||||
Some(FnCallNode::CallExpr(expr))
|
Some(FnCallNode::CallExpr(expr))
|
||||||
} else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) {
|
} else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) {
|
||||||
Some(FnCallNode::MethodCallExpr(expr))
|
Some(FnCallNode::MethodCallExpr(expr))
|
||||||
} else if let Some(expr) = ast::MacroCall::cast(node.clone()) {
|
} else if let Some(expr) = ast::MacroCall::cast(node) {
|
||||||
Some(FnCallNode::MacroCallExpr(expr))
|
Some(FnCallNode::MacroCallExpr(expr))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl fmt::Debug for AnalysisChange {
|
||||||
if !self.libraries_added.is_empty() {
|
if !self.libraries_added.is_empty() {
|
||||||
d.field("libraries_added", &self.libraries_added.len());
|
d.field("libraries_added", &self.libraries_added.len());
|
||||||
}
|
}
|
||||||
if !self.crate_graph.is_some() {
|
if !self.crate_graph.is_none() {
|
||||||
d.field("crate_graph", &self.crate_graph);
|
d.field("crate_graph", &self.crate_graph);
|
||||||
}
|
}
|
||||||
d.finish()
|
d.finish()
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return,
|
_ => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ impl Completions {
|
||||||
for (idx, s) in docs.match_indices(¯o_name) {
|
for (idx, s) in docs.match_indices(¯o_name) {
|
||||||
let (before, after) = (&docs[..idx], &docs[idx + s.len()..]);
|
let (before, after) = (&docs[..idx], &docs[idx + s.len()..]);
|
||||||
// Ensure to match the full word
|
// Ensure to match the full word
|
||||||
if after.starts_with("!")
|
if after.starts_with('!')
|
||||||
&& before
|
&& before
|
||||||
.chars()
|
.chars()
|
||||||
.rev()
|
.rev()
|
||||||
|
@ -225,7 +225,7 @@ impl Completions {
|
||||||
} else {
|
} else {
|
||||||
(format!("{}($0)", data.name()), format!("{}(…)", name))
|
(format!("{}($0)", data.name()), format!("{}(…)", name))
|
||||||
};
|
};
|
||||||
builder = builder.lookup_by(name.clone()).label(label).insert_snippet(snippet);
|
builder = builder.lookup_by(name).label(label).insert_snippet(snippet);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.add(builder)
|
self.add(builder)
|
||||||
|
|
|
@ -111,8 +111,7 @@ impl NameDefinition {
|
||||||
if vis.as_str() != "" {
|
if vis.as_str() != "" {
|
||||||
let source_root_id = db.file_source_root(file_id);
|
let source_root_id = db.file_source_root(file_id);
|
||||||
let source_root = db.source_root(source_root_id);
|
let source_root = db.source_root(source_root_id);
|
||||||
let mut res =
|
let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>();
|
||||||
source_root.walk().map(|id| (id.into(), None)).collect::<FxHashMap<_, _>>();
|
|
||||||
|
|
||||||
// FIXME: add "pub(in path)"
|
// FIXME: add "pub(in path)"
|
||||||
|
|
||||||
|
@ -128,7 +127,7 @@ impl NameDefinition {
|
||||||
let root_file = crate_graph.crate_root(crate_id);
|
let root_file = crate_graph.crate_root(crate_id);
|
||||||
let source_root_id = db.file_source_root(root_file);
|
let source_root_id = db.file_source_root(root_file);
|
||||||
let source_root = db.source_root(source_root_id);
|
let source_root = db.source_root(source_root_id);
|
||||||
res.extend(source_root.walk().map(|id| (id.into(), None)));
|
res.extend(source_root.walk().map(|id| (id, None)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SearchScope::new(res);
|
return SearchScope::new(res);
|
||||||
|
|
|
@ -261,7 +261,7 @@ impl S {
|
||||||
|
|
||||||
fn type_char(char_typed: char, before: &str, after: &str) {
|
fn type_char(char_typed: char, before: &str, after: &str) {
|
||||||
let (actual, file_change) = do_type_char(char_typed, before)
|
let (actual, file_change) = do_type_char(char_typed, before)
|
||||||
.expect(&format!("typing `{}` did nothing", char_typed));
|
.unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed));
|
||||||
|
|
||||||
if after.contains("<|>") {
|
if after.contains("<|>") {
|
||||||
let (offset, after) = extract_offset(after);
|
let (offset, after) = extract_offset(after);
|
||||||
|
|
|
@ -196,7 +196,7 @@ pub fn main_loop(
|
||||||
task_receiver.into_iter().for_each(|task| {
|
task_receiver.into_iter().for_each(|task| {
|
||||||
on_task(task, &connection.sender, &mut loop_state.pending_requests, &mut world_state)
|
on_task(task, &connection.sender, &mut loop_state.pending_requests, &mut world_state)
|
||||||
});
|
});
|
||||||
libdata_receiver.into_iter().for_each(|lib| drop(lib));
|
libdata_receiver.into_iter().for_each(drop);
|
||||||
log::info!("...tasks have finished");
|
log::info!("...tasks have finished");
|
||||||
log::info!("joining threadpool...");
|
log::info!("joining threadpool...");
|
||||||
drop(pool);
|
drop(pool);
|
||||||
|
|
|
@ -123,7 +123,6 @@ fn match_subtree(
|
||||||
}
|
}
|
||||||
None => bindings.push_optional(name),
|
None => bindings.push_optional(name),
|
||||||
}
|
}
|
||||||
()
|
|
||||||
}
|
}
|
||||||
Op::Repeat { subtree, kind, separator } => {
|
Op::Repeat { subtree, kind, separator } => {
|
||||||
match_repeat(bindings, subtree, kind, separator, src)?
|
match_repeat(bindings, subtree, kind, separator, src)?
|
||||||
|
@ -159,7 +158,7 @@ impl<'a> TtIter<'a> {
|
||||||
pub(crate) fn expect_lifetime(&mut self) -> Result<&tt::Ident, ()> {
|
pub(crate) fn expect_lifetime(&mut self) -> Result<&tt::Ident, ()> {
|
||||||
let ident = self.expect_ident()?;
|
let ident = self.expect_ident()?;
|
||||||
// check if it start from "`"
|
// check if it start from "`"
|
||||||
if ident.text.chars().next() != Some('\'') {
|
if !ident.text.starts_with('\'') {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
Ok(ident)
|
Ok(ident)
|
||||||
|
|
|
@ -383,7 +383,7 @@ mod tests {
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
let expansion = expand(&rules, "literals!(foo);");
|
let expansion = expand(&rules, "literals!(foo);");
|
||||||
let tts = &[expansion.clone().into()];
|
let tts = &[expansion.into()];
|
||||||
let buffer = tt::buffer::TokenBuffer::new(tts);
|
let buffer = tt::buffer::TokenBuffer::new(tts);
|
||||||
let mut tt_src = SubtreeTokenSource::new(&buffer);
|
let mut tt_src = SubtreeTokenSource::new(&buffer);
|
||||||
let mut tokens = vec![];
|
let mut tokens = vec![];
|
||||||
|
|
|
@ -129,11 +129,11 @@ pub fn where_clause(preds: impl Iterator<Item = ast::WherePred>) -> ast::WhereCl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr {
|
pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr {
|
||||||
return ast_from_text(&format!(
|
ast_from_text(&format!(
|
||||||
"fn f() {{ if !{} {{\n {}\n}}\n}}",
|
"fn f() {{ if !{} {{\n {}\n}}\n}}",
|
||||||
condition.syntax().text(),
|
condition.syntax().text(),
|
||||||
statement
|
statement
|
||||||
));
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ast_from_text<N: AstNode>(text: &str) -> N {
|
fn ast_from_text<N: AstNode>(text: &str) -> N {
|
||||||
|
|
|
@ -53,7 +53,7 @@ fn collect_assists() -> Result<Vec<Assist>> {
|
||||||
|
|
||||||
let doc = take_until(lines.by_ref(), "```").trim().to_string();
|
let doc = take_until(lines.by_ref(), "```").trim().to_string();
|
||||||
assert!(
|
assert!(
|
||||||
doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with("."),
|
doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.'),
|
||||||
"\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n",
|
"\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n",
|
||||||
id, doc,
|
id, doc,
|
||||||
);
|
);
|
||||||
|
|
|
@ -102,12 +102,10 @@ fn tests_from_dir(dir: &Path) -> Result<Tests> {
|
||||||
for test in collect_tests(&text) {
|
for test in collect_tests(&text) {
|
||||||
if test.ok {
|
if test.ok {
|
||||||
if let Some(old_test) = res.ok.insert(test.name.clone(), test) {
|
if let Some(old_test) = res.ok.insert(test.name.clone(), test) {
|
||||||
Err(format!("Duplicate test: {}", old_test.name))?
|
return Err(format!("Duplicate test: {}", old_test.name).into());
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let Some(old_test) = res.err.insert(test.name.clone(), test) {
|
|
||||||
Err(format!("Duplicate test: {}", old_test.name))?
|
|
||||||
}
|
}
|
||||||
|
} else if let Some(old_test) = res.err.insert(test.name.clone(), test) {
|
||||||
|
return Err(format!("Duplicate test: {}", old_test.name).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -60,7 +60,7 @@ fn main() -> Result<()> {
|
||||||
matches.finish().or_else(handle_extra_flags)?;
|
matches.finish().or_else(handle_extra_flags)?;
|
||||||
let opts = InstallOpt {
|
let opts = InstallOpt {
|
||||||
client: if server { None } else { Some(ClientOpt::VsCode) },
|
client: if server { None } else { Some(ClientOpt::VsCode) },
|
||||||
server: if client_code { None } else { Some(ServerOpt { jemalloc: jemalloc }) },
|
server: if client_code { None } else { Some(ServerOpt { jemalloc }) },
|
||||||
};
|
};
|
||||||
install(opts)?
|
install(opts)?
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ fn is_exclude_file(d: &DirEntry) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_hidden(entry: &DirEntry) -> bool {
|
fn is_hidden(entry: &DirEntry) -> bool {
|
||||||
entry.file_name().to_str().map(|s| s.starts_with(".")).unwrap_or(false)
|
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue