mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Some clippy lints
This commit is contained in:
parent
5621f90071
commit
a82c679c97
10 changed files with 45 additions and 46 deletions
|
@ -10,7 +10,7 @@ use ra_syntax::{
|
||||||
TextRange, TextUnit,
|
TextRange, TextUnit,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DERIVE_TRAIT: &'static str = "derive";
|
const DERIVE_TRAIT: &str = "derive";
|
||||||
|
|
||||||
// Assist: add_custom_impl
|
// Assist: add_custom_impl
|
||||||
//
|
//
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub enum Verbosity {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Verbosity {
|
impl Verbosity {
|
||||||
fn is_verbose(&self) -> bool {
|
fn is_verbose(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Verbosity::Verbose => true,
|
Verbosity::Verbose => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -121,7 +121,7 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio
|
||||||
Some(macro_def.to_nav(db))
|
Some(macro_def.to_nav(db))
|
||||||
}
|
}
|
||||||
} {
|
} {
|
||||||
Some((func_target.clone(), name_ref.value.text_range()))
|
Some((func_target, name_ref.value.text_range()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use hir::db::AstDatabase;
|
use hir::db::AstDatabase;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{self, ArgListOwner},
|
ast::{self, ArgListOwner},
|
||||||
match_ast, AstNode, SyntaxNode,
|
match_ast, AstNode, SyntaxNode,
|
||||||
};
|
};
|
||||||
|
use std::cmp::Ordering;
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -51,36 +51,39 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
|
||||||
// If we have a calling expression let's find which argument we are on
|
// If we have a calling expression let's find which argument we are on
|
||||||
let num_params = call_info.parameters().len();
|
let num_params = call_info.parameters().len();
|
||||||
|
|
||||||
if num_params == 1 {
|
match num_params.cmp(&1) {
|
||||||
if !has_self {
|
Ordering::Less => {}
|
||||||
call_info.active_parameter = Some(0);
|
Ordering::Equal => {
|
||||||
|
if !has_self {
|
||||||
|
call_info.active_parameter = Some(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if num_params > 1 {
|
Ordering::Greater => {
|
||||||
// Count how many parameters into the call we are.
|
if let Some(arg_list) = calling_node.arg_list() {
|
||||||
if let Some(arg_list) = calling_node.arg_list() {
|
// Number of arguments specified at the call site
|
||||||
// Number of arguments specified at the call site
|
let num_args_at_callsite = arg_list.args().count();
|
||||||
let num_args_at_callsite = arg_list.args().count();
|
|
||||||
|
|
||||||
let arg_list_range = arg_list.syntax().text_range();
|
let arg_list_range = arg_list.syntax().text_range();
|
||||||
if !arg_list_range.contains_inclusive(position.offset) {
|
if !arg_list_range.contains_inclusive(position.offset) {
|
||||||
tested_by!(call_info_bad_offset);
|
tested_by!(call_info_bad_offset);
|
||||||
return None;
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut param = std::cmp::min(
|
||||||
|
num_args_at_callsite,
|
||||||
|
arg_list
|
||||||
|
.args()
|
||||||
|
.take_while(|arg| arg.syntax().text_range().end() < position.offset)
|
||||||
|
.count(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// If we are in a method account for `self`
|
||||||
|
if has_self {
|
||||||
|
param += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
call_info.active_parameter = Some(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut param = std::cmp::min(
|
|
||||||
num_args_at_callsite,
|
|
||||||
arg_list
|
|
||||||
.args()
|
|
||||||
.take_while(|arg| arg.syntax().text_range().end() < position.offset)
|
|
||||||
.count(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// If we are in a method account for `self`
|
|
||||||
if has_self {
|
|
||||||
param += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
call_info.active_parameter = Some(param);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
}
|
}
|
||||||
if let ScopeDef::Unknown = def {
|
if let ScopeDef::Unknown = def {
|
||||||
if let Some(name_ref) = ctx.name_ref_syntax.as_ref() {
|
if let Some(name_ref) = ctx.name_ref_syntax.as_ref() {
|
||||||
if &name_ref.syntax().text() == name.to_string().as_str() {
|
if name_ref.syntax().text() == name.to_string().as_str() {
|
||||||
// for `use self::foo<|>`, don't suggest `foo` as a completion
|
// for `use self::foo<|>`, don't suggest `foo` as a completion
|
||||||
tested_by!(dont_complete_current_use);
|
tested_by!(dont_complete_current_use);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -339,7 +339,7 @@ mod tests {
|
||||||
let (cursor, before) = extract_offset(before);
|
let (cursor, before) = extract_offset(before);
|
||||||
let (analysis, file_id) = single_file(&before);
|
let (analysis, file_id) = single_file(&before);
|
||||||
let range = TextRange::offset_len(cursor, 0.into());
|
let range = TextRange::offset_len(cursor, 0.into());
|
||||||
let mut frange = FileRange { file_id: file_id, range };
|
let mut frange = FileRange { file_id, range };
|
||||||
|
|
||||||
for &after in afters {
|
for &after in afters {
|
||||||
frange.range = analysis.extend_selection(frange).unwrap();
|
frange.range = analysis.extend_selection(frange).unwrap();
|
||||||
|
|
|
@ -166,7 +166,7 @@ pub(crate) fn find_all_refs(
|
||||||
Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references }))
|
Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_name<'a>(
|
fn find_name(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
syntax: &SyntaxNode,
|
syntax: &SyntaxNode,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
|
@ -253,13 +253,10 @@ fn decl_access(
|
||||||
let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?;
|
let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?;
|
||||||
if let Some(_) = stmt.initializer() {
|
if let Some(_) = stmt.initializer() {
|
||||||
let pat = stmt.pat()?;
|
let pat = stmt.pat()?;
|
||||||
match pat {
|
if let ast::Pat::BindPat(it) = pat {
|
||||||
ast::Pat::BindPat(it) => {
|
if it.name()?.text().as_str() == name {
|
||||||
if it.name()?.text().as_str() == name {
|
return Some(ReferenceAccess::Write);
|
||||||
return Some(ReferenceAccess::Write);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +283,7 @@ fn reference_access(kind: &NameKind, name_ref: &ast::NameRef) -> Option<Referenc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Some(ReferenceAccess::Read);
|
Some(ReferenceAccess::Read)
|
||||||
},
|
},
|
||||||
_ => {None}
|
_ => {None}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,8 +82,7 @@ impl NameDefinition {
|
||||||
return SearchScope::new(res);
|
return SearchScope::new(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
let vis =
|
let vis = self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default();
|
||||||
self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or("".to_string());
|
|
||||||
|
|
||||||
if vis.as_str() == "pub(super)" {
|
if vis.as_str() == "pub(super)" {
|
||||||
if let Some(parent_module) = self.container.parent(db) {
|
if let Some(parent_module) = self.container.parent(db) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
|
||||||
|
|
||||||
fn opt_path_type_args(p: &mut Parser, mode: Mode) {
|
fn opt_path_type_args(p: &mut Parser, mode: Mode) {
|
||||||
match mode {
|
match mode {
|
||||||
Mode::Use => return,
|
Mode::Use => {}
|
||||||
Mode::Type => {
|
Mode::Type => {
|
||||||
// test path_fn_trait_args
|
// test path_fn_trait_args
|
||||||
// type F = Box<Fn(x: i32) -> ()>;
|
// type F = Box<Fn(x: i32) -> ()>;
|
||||||
|
|
|
@ -127,8 +127,8 @@ pub enum BinOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BinOp {
|
impl BinOp {
|
||||||
pub fn is_assignment(&self) -> bool {
|
pub fn is_assignment(self) -> bool {
|
||||||
match *self {
|
match self {
|
||||||
BinOp::Assignment
|
BinOp::Assignment
|
||||||
| BinOp::AddAssign
|
| BinOp::AddAssign
|
||||||
| BinOp::DivAssign
|
| BinOp::DivAssign
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue