Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 609829a

Browse files
committed
Auto merge of #1327 - Xanewok:clippy-fixes, r=Xanewok
Apply Clippy fixes This is mostly due to `clippy::redundant_closure` which might make sense in most cases but in other we'd like to let type inference do the work for a concise and readable code (e.g. `toml::de::Error::line_col` instead of `|x| x.line_col()`).
2 parents 17a4394 + 71a81a0 commit 609829a

File tree

13 files changed

+22
-20
lines changed

13 files changed

+22
-20
lines changed

rls/src/actions/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn rustfmt_args(config: &Config, config_path: &Path) -> Vec<String> {
135135
args.push(lines);
136136

137137
args.push("--config-path".into());
138-
args.push(config_path.to_str().map(|x| x.to_string()).unwrap());
138+
args.push(config_path.to_str().map(ToOwned::to_owned).unwrap());
139139

140140
args
141141
}

rls/src/actions/hover.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn extract_docs(
161161
break;
162162
} else if line.starts_with("///") || line.starts_with("//!") {
163163
let pos =
164-
if line.chars().nth(3).map(|c| c.is_whitespace()).unwrap_or(false) { 4 } else { 3 };
164+
if line.chars().nth(3).map(char::is_whitespace).unwrap_or(false) { 4 } else { 3 };
165165
let doc_line = line[pos..].into();
166166
if up {
167167
docs.insert(0, doc_line);
@@ -632,9 +632,9 @@ fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def>
632632
.or_else(|| skip_path_components(&contextstr_path, cargo_home, 3))
633633
// Make the path relative to the root of the project, if possible.
634634
.or_else(|| {
635-
contextstr_path.strip_prefix(&ctx.current_project).ok().map(|x| x.to_owned())
635+
contextstr_path.strip_prefix(&ctx.current_project).ok().map(ToOwned::to_owned)
636636
})
637-
.and_then(|path| path.to_str().map(|s| s.to_string()))
637+
.and_then(|path| path.to_str().map(ToOwned::to_owned))
638638
.unwrap_or_else(|| contextstr.to_string())
639639
} else {
640640
m.contextstr.trim_end_matches('{').trim().to_string()
@@ -695,7 +695,7 @@ fn racer_def(ctx: &InitActionContext, span: &Span<ZeroIndexed>) -> Option<Def> {
695695
let name = vfs.load_line(file_path.as_path(), span.range.row_start).ok().and_then(|line| {
696696
let col_start = span.range.col_start.0 as usize;
697697
let col_end = span.range.col_end.0 as usize;
698-
line.get(col_start..col_end).map(|line| line.to_string())
698+
line.get(col_start..col_end).map(ToOwned::to_owned)
699699
});
700700

701701
debug!("racer_def: name: {:?}", name);

rls/src/actions/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl FileWatch {
512512
// Find any Cargo.tomls in the project
513513
for entry in WalkDir::new(project_str)
514514
.into_iter()
515-
.filter_map(|e| e.ok())
515+
.filter_map(Result::ok)
516516
.filter(|e| e.file_name() == "Cargo.toml")
517517
{
518518
watchers.push(watcher(entry.path().display().to_string()));

rls/src/actions/requests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ fn make_deglob_actions(
566566

567567
// Ideally we'd use Rustfmt for this, but reparsing is a bit of a pain.
568568
fn sort_deglob_str(s: &str) -> String {
569-
let mut substrings = s.split(',').map(|s| s.trim()).collect::<Vec<_>>();
569+
let mut substrings = s.split(',').map(str::trim).collect::<Vec<_>>();
570570
substrings.sort_by(|a, b| {
571571
use std::cmp::Ordering;
572572

rls/src/build/cargo.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::sync::{Arc, Mutex};
1010
use std::thread;
1111

1212
use cargo::core::compiler::{BuildConfig, CompileMode, Context, Executor, Unit};
13+
use cargo::core::Package;
1314
use cargo::core::resolver::ResolveError;
1415
use cargo::core::{
1516
enable_nightly_features, PackageId, Shell, Target, TargetKind, Verbosity, Workspace,
@@ -321,7 +322,7 @@ impl RlsExecutor {
321322
progress_sender: Sender<ProgressUpdate>,
322323
reached_primary: Arc<AtomicBool>,
323324
) -> RlsExecutor {
324-
let member_packages = ws.members().map(|x| x.package_id()).collect();
325+
let member_packages = ws.members().map(Package::package_id).collect();
325326

326327
RlsExecutor {
327328
compilation_cx,
@@ -521,7 +522,7 @@ impl Executor for RlsExecutor {
521522
{
522523
let mut compilation_cx = self.compilation_cx.lock().unwrap();
523524
compilation_cx.needs_rebuild = false;
524-
compilation_cx.cwd = cargo_cmd.get_cwd().map(|p| p.to_path_buf());
525+
compilation_cx.cwd = cargo_cmd.get_cwd().map(ToOwned::to_owned);
525526
}
526527

527528
let build_dir = {

rls/src/build/cargo_plan.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl CargoPlan {
210210
})
211211
.collect();
212212

213-
for modified in files.iter().map(|x| x.as_ref()) {
213+
for modified in files.iter().map(AsRef::as_ref) {
214214
if let Some(unit) = build_scripts.get(modified) {
215215
result.insert(unit.clone());
216216
} else {
@@ -553,7 +553,7 @@ impl BuildGraph for CargoPlan {
553553
}
554554

555555
fn topological_sort(&self, units: Vec<&Self::Unit>) -> Vec<&Self::Unit> {
556-
let keys = units.into_iter().map(|u| u.key()).collect();
556+
let keys = units.into_iter().map(BuildKey::key).collect();
557557
let graph = self.dirty_rev_dep_graph(&keys);
558558

559559
CargoPlan::topological_sort(self, &graph)

rls/src/build/external.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(super) fn build_with_external_cmd<S: AsRef<str>>(
7272

7373
let files = reader
7474
.lines()
75-
.filter_map(|res| res.ok())
75+
.filter_map(Result::ok)
7676
.map(PathBuf::from)
7777
// Relative paths are relative to build command, not RLS itself (CWD may be different).
7878
.map(|path| if !path.is_absolute() { build_dir.join(path) } else { path });
@@ -316,7 +316,7 @@ impl BuildGraph for ExternalPlan {
316316
fn dirties<T: AsRef<Path>>(&self, modified: &[T]) -> Vec<&Self::Unit> {
317317
let mut results = HashSet::<u64>::new();
318318

319-
for modified in modified.iter().map(|x| x.as_ref()) {
319+
for modified in modified.iter().map(AsRef::as_ref) {
320320
// We associate a dirty file with a
321321
// package by finding longest (most specified) path prefix.
322322
let matching_prefix_components = |a: &Path, b: &Path| -> usize {
@@ -365,7 +365,7 @@ impl BuildGraph for ExternalPlan {
365365

366366
let mut stack = self.dirties(files);
367367

368-
while let Some(key) = stack.pop().map(|u| u.key()) {
368+
while let Some(key) = stack.pop().map(BuildKey::key) {
369369
if results.insert(key) {
370370
if let Some(rdeps) = self.rev_deps.get(&key) {
371371
for rdep in rdeps {
@@ -379,7 +379,7 @@ impl BuildGraph for ExternalPlan {
379379
}
380380

381381
fn topological_sort(&self, units: Vec<&Self::Unit>) -> Vec<&Self::Unit> {
382-
let dirties: HashSet<_> = units.into_iter().map(|u| u.key()).collect();
382+
let dirties: HashSet<_> = units.into_iter().map(BuildKey::key).collect();
383383

384384
let mut visited: HashSet<_> = HashSet::new();
385385
let mut output = vec![];

rls/src/build/plan.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl JobQueue {
151151

152152
// Send a window/progress notification.
153153
{
154-
let crate_name = proc_argument_value(&job, "--crate-name").and_then(|x| x.to_str());
154+
let crate_name = proc_argument_value(&job, "--crate-name").and_then(OsStr::to_str);
155155
let update = match crate_name {
156156
Some(name) => {
157157
let cfg_test = job.get_args().iter().any(|arg| arg == "--test");

rls/src/build/rustc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub(crate) fn rustc(
9494
clippy_args.push("clippy::all".to_owned());
9595
}
9696

97-
args.iter().map(|s| s.to_owned()).chain(clippy_args).collect()
97+
args.iter().map(ToOwned::to_owned).chain(clippy_args).collect()
9898
} else {
9999
args.to_owned()
100100
};

rls/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
#![feature(rustc_private, drain_filter)]
99
#![warn(clippy::all, rust_2018_idioms)]
10-
#![allow(clippy::cyclomatic_complexity, clippy::too_many_arguments)]
10+
#![allow(clippy::cyclomatic_complexity, clippy::too_many_arguments, clippy::redundant_closure)]
1111

1212
pub use rls_analysis::{AnalysisHost, Target};
1313
pub use rls_vfs::Vfs;

rls/src/project_model.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl racer::ProjectModelProvider for RacerProjectModel {
182182
}
183183
let dep = pkg.deps(&self.0).iter().find(|dep| dep.crate_name == libname)?.pkg;
184184

185-
dep.lib_root(&self.0).map(|p| p.to_owned())
185+
dep.lib_root(&self.0).map(ToOwned::to_owned)
186186
}
187187
}
188188

rls/src/server/message.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl RawMessage {
338338
// (Null being unused value of param by the JSON-RPC 2.0 spec)
339339
// in order to unify the type handling –- now the parameter type implements
340340
// `Deserialize`.
341-
let params = match ls_command.get("params").map(|p| p.to_owned()) {
341+
let params = match ls_command.get("params").map(ToOwned::to_owned) {
342342
Some(params @ serde_json::Value::Object(..))
343343
| Some(params @ serde_json::Value::Array(..)) => params,
344344
// Null as input value is not allowed by JSON-RPC 2.0,

tests/support/client/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl Project {
8282

8383
let (sink, stream) = LspFramed::from_transport(transport).split();
8484

85+
#[allow(clippy::unit_arg)] // We're interested in the side-effects of `process_msg`.
8586
let reader = stream
8687
.timeout(rls_timeout())
8788
.map_err(|_| ())

0 commit comments

Comments
 (0)