mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #11041
11041: minor: Fix some clippy lints r=lnicola a=lnicola bors r+ Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
6674756c07
12 changed files with 37 additions and 60 deletions
|
@ -148,7 +148,7 @@ impl ItemTree {
|
||||||
let loc = db.lookup_intern_block(block);
|
let loc = db.lookup_intern_block(block);
|
||||||
let block = loc.ast_id.to_node(db.upcast());
|
let block = loc.ast_id.to_node(db.upcast());
|
||||||
let hygiene = Hygiene::new(db.upcast(), loc.ast_id.file_id);
|
let hygiene = Hygiene::new(db.upcast(), loc.ast_id.file_id);
|
||||||
let ctx = lower::Ctx::new(db, hygiene.clone(), loc.ast_id.file_id);
|
let ctx = lower::Ctx::new(db, hygiene, loc.ast_id.file_id);
|
||||||
Arc::new(ctx.lower_block(&block))
|
Arc::new(ctx.lower_block(&block))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ fn highlight_references(
|
||||||
token: SyntaxToken,
|
token: SyntaxToken,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
) -> Option<Vec<HighlightedRange>> {
|
) -> Option<Vec<HighlightedRange>> {
|
||||||
let defs = find_defs(sema, token.clone());
|
let defs = find_defs(sema, token);
|
||||||
let usages = defs
|
let usages = defs
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&d| {
|
.filter_map(|&d| {
|
||||||
|
|
|
@ -96,8 +96,7 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
|
||||||
let block_prefix =
|
let block_prefix =
|
||||||
CommentKind { shape: CommentShape::Block, ..comment.kind() }.prefix();
|
CommentKind { shape: CommentShape::Block, ..comment.kind() }.prefix();
|
||||||
|
|
||||||
let output =
|
let output = format!("{}\n{}\n{}*/", block_prefix, block_comment_body, indentation);
|
||||||
format!("{}\n{}\n{}*/", block_prefix, block_comment_body, indentation.to_string());
|
|
||||||
|
|
||||||
edit.replace(target, output)
|
edit.replace(target, output)
|
||||||
},
|
},
|
||||||
|
|
|
@ -91,10 +91,7 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext) -> Op
|
||||||
builder.replace(src_type.syntax().text_range(), dest_type.to_string());
|
builder.replace(src_type.syntax().text_range(), dest_type.to_string());
|
||||||
builder.replace(ast_trait.syntax().text_range(), format!("From<{}>", src_type));
|
builder.replace(ast_trait.syntax().text_range(), format!("From<{}>", src_type));
|
||||||
builder.replace(into_fn_return.syntax().text_range(), "-> Self");
|
builder.replace(into_fn_return.syntax().text_range(), "-> Self");
|
||||||
builder.replace(
|
builder.replace(into_fn_params.syntax().text_range(), format!("(val: {})", src_type));
|
||||||
into_fn_params.syntax().text_range(),
|
|
||||||
format!("(val: {})", src_type.to_string()),
|
|
||||||
);
|
|
||||||
builder.replace(into_fn_name.syntax().text_range(), "from");
|
builder.replace(into_fn_name.syntax().text_range(), "from");
|
||||||
|
|
||||||
for s in selfs {
|
for s in selfs {
|
||||||
|
|
|
@ -174,7 +174,7 @@ fn edit_tuple_assignment(
|
||||||
|
|
||||||
// with sub_pattern: keep original tuple and add subpattern: `tup @ (_0, _1)`
|
// with sub_pattern: keep original tuple and add subpattern: `tup @ (_0, _1)`
|
||||||
if in_sub_pattern {
|
if in_sub_pattern {
|
||||||
let text = format!(" @ {}", tuple_pat.to_string());
|
let text = format!(" @ {}", tuple_pat);
|
||||||
match ctx.config.snippet_cap {
|
match ctx.config.snippet_cap {
|
||||||
Some(cap) => {
|
Some(cap) => {
|
||||||
let snip = add_cursor(&text);
|
let snip = add_cursor(&text);
|
||||||
|
|
|
@ -151,7 +151,7 @@ fn extract_target(node: &SyntaxNode, selection_range: TextRange) -> Option<Modul
|
||||||
let mut body_items: Vec<ast::Item> = node
|
let mut body_items: Vec<ast::Item> = node
|
||||||
.children()
|
.children()
|
||||||
.filter_map(|child| {
|
.filter_map(|child| {
|
||||||
if let Some(item) = ast::Item::cast(child.clone()) {
|
if let Some(item) = ast::Item::cast(child) {
|
||||||
if selection_range.contains_range(item.syntax().text_range()) {
|
if selection_range.contains_range(item.syntax().text_range()) {
|
||||||
return Some(item);
|
return Some(item);
|
||||||
}
|
}
|
||||||
|
@ -298,7 +298,7 @@ impl Module {
|
||||||
if let Some(name_ref) = ast::NameRef::cast(desc) {
|
if let Some(name_ref) = ast::NameRef::cast(desc) {
|
||||||
return Some((
|
return Some((
|
||||||
name_ref.syntax().text_range(),
|
name_ref.syntax().text_range(),
|
||||||
format!("{}::{}", self.name, name_ref.to_string()),
|
format!("{}::{}", self.name, name_ref),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,20 +312,20 @@ impl Module {
|
||||||
get_replacements_for_visibilty_change(self.body_items.clone(), false);
|
get_replacements_for_visibilty_change(self.body_items.clone(), false);
|
||||||
|
|
||||||
let impl_items = impls.into_iter().fold(Vec::new(), |mut impl_items, x| {
|
let impl_items = impls.into_iter().fold(Vec::new(), |mut impl_items, x| {
|
||||||
let this_impl_items =
|
let mut this_impl_items =
|
||||||
x.syntax().descendants().fold(Vec::new(), |mut this_impl_items, x| {
|
x.syntax().descendants().fold(Vec::new(), |mut this_impl_items, x| {
|
||||||
if let Some(item) = ast::Item::cast(x.clone()) {
|
if let Some(item) = ast::Item::cast(x) {
|
||||||
this_impl_items.push(item);
|
this_impl_items.push(item);
|
||||||
}
|
}
|
||||||
return this_impl_items;
|
return this_impl_items;
|
||||||
});
|
});
|
||||||
|
|
||||||
impl_items.append(&mut this_impl_items.clone());
|
impl_items.append(&mut this_impl_items);
|
||||||
return impl_items;
|
return impl_items;
|
||||||
});
|
});
|
||||||
|
|
||||||
let (_, mut impl_item_replacements, _, _) =
|
let (_, mut impl_item_replacements, _, _) =
|
||||||
get_replacements_for_visibilty_change(impl_items.clone(), true);
|
get_replacements_for_visibilty_change(impl_items, true);
|
||||||
|
|
||||||
replacements.append(&mut impl_item_replacements);
|
replacements.append(&mut impl_item_replacements);
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ impl Module {
|
||||||
.find(|x| x.to_string() == desc.to_string())
|
.find(|x| x.to_string() == desc.to_string())
|
||||||
.is_some();
|
.is_some();
|
||||||
if is_record_field_present {
|
if is_record_field_present {
|
||||||
replacements.push((desc.visibility().clone(), desc.syntax().clone()));
|
replacements.push((desc.visibility(), desc.syntax().clone()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -472,7 +472,7 @@ impl Module {
|
||||||
(&x.1).into_iter().for_each(|x| {
|
(&x.1).into_iter().for_each(|x| {
|
||||||
let node_opt: Option<ast::Use> = find_node_at_range(file.syntax(), x.range);
|
let node_opt: Option<ast::Use> = find_node_at_range(file.syntax(), x.range);
|
||||||
if let Some(node) = node_opt {
|
if let Some(node) = node_opt {
|
||||||
use_opt = Some(node.clone());
|
use_opt = Some(node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -529,7 +529,7 @@ impl Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(use_tree_str) = use_tree_str_opt {
|
if let Some(use_tree_str) = use_tree_str_opt {
|
||||||
let mut use_tree_str = use_tree_str.clone();
|
let mut use_tree_str = use_tree_str;
|
||||||
use_tree_str.reverse();
|
use_tree_str.reverse();
|
||||||
if use_tree_str[0].to_string().contains("super") {
|
if use_tree_str[0].to_string().contains("super") {
|
||||||
let super_path = make::ext::ident_path("super");
|
let super_path = make::ext::ident_path("super");
|
||||||
|
@ -776,42 +776,24 @@ fn get_replacements_for_visibilty_change(
|
||||||
body_items.push(item.clone());
|
body_items.push(item.clone());
|
||||||
//Use stmts are ignored
|
//Use stmts are ignored
|
||||||
match item {
|
match item {
|
||||||
ast::Item::Const(it) => {
|
ast::Item::Const(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()))
|
ast::Item::Enum(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
}
|
ast::Item::ExternCrate(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
ast::Item::Enum(it) => {
|
ast::Item::Fn(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()))
|
|
||||||
}
|
|
||||||
ast::Item::ExternCrate(it) => {
|
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()))
|
|
||||||
}
|
|
||||||
ast::Item::Fn(it) => replacements.push((it.visibility().clone(), it.syntax().clone())),
|
|
||||||
ast::Item::Impl(it) => impls.push(it),
|
ast::Item::Impl(it) => impls.push(it),
|
||||||
ast::Item::MacroRules(it) => {
|
ast::Item::MacroRules(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()))
|
ast::Item::MacroDef(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
}
|
ast::Item::Module(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
ast::Item::MacroDef(it) => {
|
ast::Item::Static(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()))
|
|
||||||
}
|
|
||||||
ast::Item::Module(it) => {
|
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()))
|
|
||||||
}
|
|
||||||
ast::Item::Static(it) => {
|
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()))
|
|
||||||
}
|
|
||||||
ast::Item::Struct(it) => {
|
ast::Item::Struct(it) => {
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()));
|
replacements.push((it.visibility(), it.syntax().clone()));
|
||||||
record_field_parents.push((it.visibility().clone(), it.syntax().clone()));
|
record_field_parents.push((it.visibility(), it.syntax().clone()));
|
||||||
}
|
|
||||||
ast::Item::Trait(it) => {
|
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()))
|
|
||||||
}
|
|
||||||
ast::Item::TypeAlias(it) => {
|
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()))
|
|
||||||
}
|
}
|
||||||
|
ast::Item::Trait(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
|
ast::Item::TypeAlias(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
ast::Item::Union(it) => {
|
ast::Item::Union(it) => {
|
||||||
replacements.push((it.visibility().clone(), it.syntax().clone()));
|
replacements.push((it.visibility(), it.syntax().clone()));
|
||||||
record_field_parents.push((it.visibility().clone(), it.syntax().clone()));
|
record_field_parents.push((it.visibility(), it.syntax().clone()));
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
@ -825,7 +807,7 @@ fn get_use_tree_paths_from_path(
|
||||||
use_tree_str: &mut Vec<ast::Path>,
|
use_tree_str: &mut Vec<ast::Path>,
|
||||||
) -> Option<&mut Vec<ast::Path>> {
|
) -> Option<&mut Vec<ast::Path>> {
|
||||||
path.syntax().ancestors().filter(|x| x.to_string() != path.to_string()).find_map(|x| {
|
path.syntax().ancestors().filter(|x| x.to_string() != path.to_string()).find_map(|x| {
|
||||||
if let Some(use_tree) = ast::UseTree::cast(x.clone()) {
|
if let Some(use_tree) = ast::UseTree::cast(x) {
|
||||||
if let Some(upper_tree_path) = use_tree.path() {
|
if let Some(upper_tree_path) = use_tree.path() {
|
||||||
if upper_tree_path.to_string() != path.to_string() {
|
if upper_tree_path.to_string() != path.to_string() {
|
||||||
use_tree_str.push(upper_tree_path.clone());
|
use_tree_str.push(upper_tree_path.clone());
|
||||||
|
|
|
@ -59,9 +59,8 @@ pub(crate) fn generate_documentation_template(
|
||||||
"Generate a documentation template",
|
"Generate a documentation template",
|
||||||
text_range,
|
text_range,
|
||||||
|builder| {
|
|builder| {
|
||||||
let mut doc_lines = Vec::new();
|
|
||||||
// Introduction / short function description before the sections
|
// Introduction / short function description before the sections
|
||||||
doc_lines.push(introduction_builder(&ast_func, ctx));
|
let mut doc_lines = vec![introduction_builder(&ast_func, ctx)];
|
||||||
// Then come the sections
|
// Then come the sections
|
||||||
if let Some(mut lines) = examples_builder(&ast_func, ctx) {
|
if let Some(mut lines) = examples_builder(&ast_func, ctx) {
|
||||||
doc_lines.push("".into());
|
doc_lines.push("".into());
|
||||||
|
@ -303,7 +302,7 @@ fn arguments_from_params(param_list: &ast::ParamList) -> String {
|
||||||
// instance `TuplePat`) could be managed later.
|
// instance `TuplePat`) could be managed later.
|
||||||
Some(ast::Pat::IdentPat(ident_pat)) => match ident_pat.name() {
|
Some(ast::Pat::IdentPat(ident_pat)) => match ident_pat.name() {
|
||||||
Some(name) => match is_a_ref_mut_param(¶m) {
|
Some(name) => match is_a_ref_mut_param(¶m) {
|
||||||
true => format!("&mut {}", name.to_string()),
|
true => format!("&mut {}", name),
|
||||||
false => name.to_string(),
|
false => name.to_string(),
|
||||||
},
|
},
|
||||||
None => "_".to_string(),
|
None => "_".to_string(),
|
||||||
|
|
|
@ -121,7 +121,7 @@ impl QualifyCandidate<'_> {
|
||||||
}
|
}
|
||||||
QualifyCandidate::UnqualifiedName(generics) => {
|
QualifyCandidate::UnqualifiedName(generics) => {
|
||||||
let generics = generics.as_ref().map_or_else(String::new, ToString::to_string);
|
let generics = generics.as_ref().map_or_else(String::new, ToString::to_string);
|
||||||
replacer(format!("{}{}", import.to_string(), generics));
|
replacer(format!("{}{}", import, generics));
|
||||||
}
|
}
|
||||||
QualifyCandidate::TraitAssocItem(qualifier, segment) => {
|
QualifyCandidate::TraitAssocItem(qualifier, segment) => {
|
||||||
replacer(format!("<{} as {}>::{}", qualifier, import, segment));
|
replacer(format!("<{} as {}>::{}", qualifier, import, segment));
|
||||||
|
|
|
@ -431,7 +431,7 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str
|
||||||
buf.push_str("\n\n");
|
buf.push_str("\n\n");
|
||||||
adt.attrs()
|
adt.attrs()
|
||||||
.filter(|attr| attr.as_simple_call().map(|(name, _arg)| name == "cfg").unwrap_or(false))
|
.filter(|attr| attr.as_simple_call().map(|(name, _arg)| name == "cfg").unwrap_or(false))
|
||||||
.for_each(|attr| buf.push_str(format!("{}\n", attr.to_string()).as_str()));
|
.for_each(|attr| buf.push_str(format!("{}\n", attr).as_str()));
|
||||||
buf.push_str("impl");
|
buf.push_str("impl");
|
||||||
if let Some(generic_params) = &generic_params {
|
if let Some(generic_params) = &generic_params {
|
||||||
let lifetimes = generic_params.lifetime_params().map(|lt| format!("{}", lt.syntax()));
|
let lifetimes = generic_params.lifetime_params().map(|lt| format!("{}", lt.syntax()));
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! This module uses a bit of static metadata to provide completions
|
//! This module uses a bit of static metadata to provide completions
|
||||||
//! for built-in attributes.
|
//! for built-in attributes.
|
||||||
//! Non-builtin attribute(excluding derives attributes) completions are done in [`super::unqualified_path`].
|
//! Non-built-in attribute (excluding derives attributes) completions are done in [`super::unqualified_path`].
|
||||||
|
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
helpers::{
|
helpers::{
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl Fixture {
|
||||||
if line.starts_with("// ")
|
if line.starts_with("// ")
|
||||||
&& line.contains(':')
|
&& line.contains(':')
|
||||||
&& !line.contains("::")
|
&& !line.contains("::")
|
||||||
&& !line.contains(".")
|
&& !line.contains('.')
|
||||||
&& line.chars().all(|it| !it.is_uppercase())
|
&& line.chars().all(|it| !it.is_uppercase())
|
||||||
{
|
{
|
||||||
panic!("looks like invalid metadata line: {:?}", line);
|
panic!("looks like invalid metadata line: {:?}", line);
|
||||||
|
|
|
@ -445,7 +445,7 @@ If the date is more than a week ago, it's better to update rust-analyzer version
|
||||||
|
|
||||||
The next thing to check would be panic messages in rust-analyzer's log.
|
The next thing to check would be panic messages in rust-analyzer's log.
|
||||||
Log messages are printed to stderr, in VS Code you can see then in the `Output > Rust Analyzer Language Server` tab of the panel.
|
Log messages are printed to stderr, in VS Code you can see then in the `Output > Rust Analyzer Language Server` tab of the panel.
|
||||||
To see more logs, set `RA_LOG=info` environmental variable.
|
To see more logs, set the `RA_LOG=info` environment variable.
|
||||||
|
|
||||||
To fully capture LSP messages between the editor and the server, set `"rust-analyzer.trace.server": "verbose"` config and check
|
To fully capture LSP messages between the editor and the server, set `"rust-analyzer.trace.server": "verbose"` config and check
|
||||||
`Output > Rust Analyzer Language Server Trace`.
|
`Output > Rust Analyzer Language Server Trace`.
|
||||||
|
@ -624,7 +624,7 @@ Relative paths are interpreted relative to `rust-project.json` file location or
|
||||||
|
|
||||||
See https://github.com/rust-analyzer/rust-project.json-example for a small example.
|
See https://github.com/rust-analyzer/rust-project.json-example for a small example.
|
||||||
|
|
||||||
You can set `RA_LOG` environmental variable to `rust_analyzer=info` to inspect how rust-analyzer handles config and project loading.
|
You can set the `RA_LOG` environment variable to `rust_analyzer=info` to inspect how rust-analyzer handles config and project loading.
|
||||||
|
|
||||||
Note that calls to `cargo check` are disabled when using `rust-project.json` by default, so compilation errors and warnings will no longer be sent to your LSP client. To enable these compilation errors you will need to specify explicitly what command rust-analyzer should run to perform the checks using the `checkOnSave.overrideCommand` configuration. As an example, the following configuration explicitly sets `cargo check` as the `checkOnSave` command.
|
Note that calls to `cargo check` are disabled when using `rust-project.json` by default, so compilation errors and warnings will no longer be sent to your LSP client. To enable these compilation errors you will need to specify explicitly what command rust-analyzer should run to perform the checks using the `checkOnSave.overrideCommand` configuration. As an example, the following configuration explicitly sets `cargo check` as the `checkOnSave` command.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue