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

Commit

Permalink
Auto merge of #1327 - Xanewok:clippy-fixes, r=Xanewok
Browse files Browse the repository at this point in the history
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()`).
  • Loading branch information
bors committed Feb 25, 2019
2 parents 17a4394 + 71a81a0 commit 609829a
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion rls/src/actions/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn rustfmt_args(config: &Config, config_path: &Path) -> Vec<String> {
args.push(lines);

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

args
}
8 changes: 4 additions & 4 deletions rls/src/actions/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn extract_docs(
break;
} else if line.starts_with("///") || line.starts_with("//!") {
let pos =
if line.chars().nth(3).map(|c| c.is_whitespace()).unwrap_or(false) { 4 } else { 3 };
if line.chars().nth(3).map(char::is_whitespace).unwrap_or(false) { 4 } else { 3 };
let doc_line = line[pos..].into();
if up {
docs.insert(0, doc_line);
Expand Down Expand Up @@ -632,9 +632,9 @@ fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def>
.or_else(|| skip_path_components(&contextstr_path, cargo_home, 3))
// Make the path relative to the root of the project, if possible.
.or_else(|| {
contextstr_path.strip_prefix(&ctx.current_project).ok().map(|x| x.to_owned())
contextstr_path.strip_prefix(&ctx.current_project).ok().map(ToOwned::to_owned)
})
.and_then(|path| path.to_str().map(|s| s.to_string()))
.and_then(|path| path.to_str().map(ToOwned::to_owned))
.unwrap_or_else(|| contextstr.to_string())
} else {
m.contextstr.trim_end_matches('{').trim().to_string()
Expand Down Expand Up @@ -695,7 +695,7 @@ fn racer_def(ctx: &InitActionContext, span: &Span<ZeroIndexed>) -> Option<Def> {
let name = vfs.load_line(file_path.as_path(), span.range.row_start).ok().and_then(|line| {
let col_start = span.range.col_start.0 as usize;
let col_end = span.range.col_end.0 as usize;
line.get(col_start..col_end).map(|line| line.to_string())
line.get(col_start..col_end).map(ToOwned::to_owned)
});

debug!("racer_def: name: {:?}", name);
Expand Down
2 changes: 1 addition & 1 deletion rls/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl FileWatch {
// Find any Cargo.tomls in the project
for entry in WalkDir::new(project_str)
.into_iter()
.filter_map(|e| e.ok())
.filter_map(Result::ok)
.filter(|e| e.file_name() == "Cargo.toml")
{
watchers.push(watcher(entry.path().display().to_string()));
Expand Down
2 changes: 1 addition & 1 deletion rls/src/actions/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ fn make_deglob_actions(

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

Expand Down
5 changes: 3 additions & 2 deletions rls/src/build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::sync::{Arc, Mutex};
use std::thread;

use cargo::core::compiler::{BuildConfig, CompileMode, Context, Executor, Unit};
use cargo::core::Package;
use cargo::core::resolver::ResolveError;
use cargo::core::{
enable_nightly_features, PackageId, Shell, Target, TargetKind, Verbosity, Workspace,
Expand Down Expand Up @@ -321,7 +322,7 @@ impl RlsExecutor {
progress_sender: Sender<ProgressUpdate>,
reached_primary: Arc<AtomicBool>,
) -> RlsExecutor {
let member_packages = ws.members().map(|x| x.package_id()).collect();
let member_packages = ws.members().map(Package::package_id).collect();

RlsExecutor {
compilation_cx,
Expand Down Expand Up @@ -521,7 +522,7 @@ impl Executor for RlsExecutor {
{
let mut compilation_cx = self.compilation_cx.lock().unwrap();
compilation_cx.needs_rebuild = false;
compilation_cx.cwd = cargo_cmd.get_cwd().map(|p| p.to_path_buf());
compilation_cx.cwd = cargo_cmd.get_cwd().map(ToOwned::to_owned);
}

let build_dir = {
Expand Down
4 changes: 2 additions & 2 deletions rls/src/build/cargo_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl CargoPlan {
})
.collect();

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

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

CargoPlan::topological_sort(self, &graph)
Expand Down
8 changes: 4 additions & 4 deletions rls/src/build/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(super) fn build_with_external_cmd<S: AsRef<str>>(

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

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

let mut stack = self.dirties(files);

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

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

let mut visited: HashSet<_> = HashSet::new();
let mut output = vec![];
Expand Down
2 changes: 1 addition & 1 deletion rls/src/build/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl JobQueue {

// Send a window/progress notification.
{
let crate_name = proc_argument_value(&job, "--crate-name").and_then(|x| x.to_str());
let crate_name = proc_argument_value(&job, "--crate-name").and_then(OsStr::to_str);
let update = match crate_name {
Some(name) => {
let cfg_test = job.get_args().iter().any(|arg| arg == "--test");
Expand Down
2 changes: 1 addition & 1 deletion rls/src/build/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub(crate) fn rustc(
clippy_args.push("clippy::all".to_owned());
}

args.iter().map(|s| s.to_owned()).chain(clippy_args).collect()
args.iter().map(ToOwned::to_owned).chain(clippy_args).collect()
} else {
args.to_owned()
};
Expand Down
2 changes: 1 addition & 1 deletion rls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![feature(rustc_private, drain_filter)]
#![warn(clippy::all, rust_2018_idioms)]
#![allow(clippy::cyclomatic_complexity, clippy::too_many_arguments)]
#![allow(clippy::cyclomatic_complexity, clippy::too_many_arguments, clippy::redundant_closure)]

pub use rls_analysis::{AnalysisHost, Target};
pub use rls_vfs::Vfs;
Expand Down
2 changes: 1 addition & 1 deletion rls/src/project_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl racer::ProjectModelProvider for RacerProjectModel {
}
let dep = pkg.deps(&self.0).iter().find(|dep| dep.crate_name == libname)?.pkg;

dep.lib_root(&self.0).map(|p| p.to_owned())
dep.lib_root(&self.0).map(ToOwned::to_owned)
}
}

Expand Down
2 changes: 1 addition & 1 deletion rls/src/server/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl RawMessage {
// (Null being unused value of param by the JSON-RPC 2.0 spec)
// in order to unify the type handling –- now the parameter type implements
// `Deserialize`.
let params = match ls_command.get("params").map(|p| p.to_owned()) {
let params = match ls_command.get("params").map(ToOwned::to_owned) {
Some(params @ serde_json::Value::Object(..))
| Some(params @ serde_json::Value::Array(..)) => params,
// Null as input value is not allowed by JSON-RPC 2.0,
Expand Down
1 change: 1 addition & 0 deletions tests/support/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl Project {

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

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

0 comments on commit 609829a

Please sign in to comment.