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

Commit ca0456b

Browse files
committed
Fix cargo clippy warnings
1 parent 6840dd6 commit ca0456b

File tree

5 files changed

+36
-37
lines changed

5 files changed

+36
-37
lines changed

rls-analysis/src/analysis.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl Analysis {
181181
self.per_crate
182182
.values()
183183
.filter(|c| c.path.is_some())
184-
.map(|c| (c.path.as_ref().unwrap().clone(), c.timestamp.clone()))
184+
.map(|c| (c.path.as_ref().unwrap().clone(), c.timestamp))
185185
.collect()
186186
}
187187

@@ -212,8 +212,7 @@ impl Analysis {
212212
// "error in for_each_crate, found {} results, expected 0 or 1",
213213
// result.len(),
214214
// );
215-
let temp = result.drain(..).next();
216-
temp // stupid NLL bug
215+
result.into_iter().nth(0)
217216
}
218217

219218
pub fn for_all_crates<F, T>(&self, f: F) -> Vec<T>
@@ -235,14 +234,14 @@ impl Analysis {
235234
}
236235

237236
pub fn ref_for_span(&self, span: &Span) -> Option<Ref> {
238-
self.for_each_crate(|c| c.def_id_for_span.get(span).map(|r| r.clone()))
237+
self.for_each_crate(|c| c.def_id_for_span.get(span).cloned())
239238
}
240239

241240
// Like def_id_for_span, but will only return a def_id if it is in the same
242241
// crate.
243242
pub fn local_def_id_for_span(&self, span: &Span) -> Option<Id> {
244243
self.for_each_crate(|c| {
245-
c.def_id_for_span.get(span).map(|r| r.some_id()).and_then(|id| {
244+
c.def_id_for_span.get(span).map(Ref::some_id).and_then(|id| {
246245
if c.defs.contains_key(&id) {
247246
Some(id)
248247
} else {

rls-analysis/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Id {
8787
fn from_crate_and_local(crate_id: u32, local_id: u32) -> Id {
8888
// Use global crate number for high order bits,
8989
// then index for least significant bits.
90-
Id(((crate_id as u64) << 32) | (local_id as u64))
90+
Id((u64::from(crate_id) << 32) | u64::from(local_id))
9191
}
9292
}
9393

@@ -239,7 +239,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
239239
}
240240

241241
pub fn get_def(&self, id: Id) -> AResult<Def> {
242-
self.with_analysis(|a| a.with_defs(id, |def| def.clone()))
242+
self.with_analysis(|a| a.with_defs(id, std::clone::Clone::clone))
243243
}
244244

245245
pub fn goto_def(&self, span: &Span) -> AResult<Span> {
@@ -335,7 +335,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
335335
let time = t_start.elapsed();
336336
info!(
337337
"find_all_refs: {}s",
338-
time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0
338+
time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0
339339
);
340340
result
341341
}
@@ -370,7 +370,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
370370
let time = t_start.elapsed();
371371
info!(
372372
"query_defs: {}",
373-
time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0
373+
time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0
374374
);
375375

376376
result
@@ -383,7 +383,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
383383
let result = self.with_analysis(|a| {
384384
Some(a.with_def_names(name, |defs| {
385385
info!("defs: {:?}", defs);
386-
defs.into_iter()
386+
defs.iter()
387387
.flat_map(|id| {
388388
a.with_ref_spans(*id, |refs| {
389389
Some(
@@ -402,7 +402,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
402402
});
403403

404404
let time = t_start.elapsed();
405-
info!("search: {}s", time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0);
405+
info!("search: {}s", time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0);
406406
result
407407
}
408408

@@ -420,7 +420,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
420420
let time = t_start.elapsed();
421421
info!(
422422
"find_all_refs_by_id: {}s",
423-
time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0
423+
time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0
424424
);
425425
result
426426
}
@@ -431,7 +431,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
431431

432432
/// Search for a symbol name, returning a list of def_ids for that name.
433433
pub fn search_for_id(&self, name: &str) -> AResult<Vec<Id>> {
434-
self.with_analysis(|a| Some(a.with_def_names(name, |defs| defs.clone())))
434+
self.with_analysis(|a| Some(a.with_def_names(name, std::clone::Clone::clone)))
435435
}
436436

437437
pub fn symbols(&self, file_name: &Path) -> AResult<Vec<SymbolResult>> {

rls-analysis/src/loader.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn extract_target_triple(sys_root_path: &Path) -> String {
100100
}
101101

102102
fn extract_rustc_host_triple() -> Option<String> {
103-
let rustc = env::var("RUSTC").unwrap_or(String::from("rustc"));
103+
let rustc = env::var("RUSTC").unwrap_or_else(|_| String::from("rustc"));
104104
let verbose_version = Command::new(rustc)
105105
.arg("--verbose")
106106
.arg("--version")
@@ -124,17 +124,15 @@ fn extract_rustup_target_triple(sys_root_path: &Path) -> String {
124124
let toolchain =
125125
sys_root_path.iter().last().and_then(OsStr::to_str).expect("extracting toolchain failed");
126126
// Extracts x86_64-pc-windows-msvc from nightly-x86_64-pc-windows-pc
127-
let triple =
128-
toolchain.splitn(2, '-').last().map(String::from).expect("extracting triple failed");
129-
triple
127+
toolchain.splitn(2, '-').last().map(String::from).expect("extracting triple failed")
130128
}
131129

132130
fn sys_root_path() -> PathBuf {
133131
env::var("SYSROOT")
134132
.ok()
135133
.map(PathBuf::from)
136134
.or_else(|| {
137-
Command::new(env::var("RUSTC").unwrap_or(String::from("rustc")))
135+
Command::new(env::var("RUSTC").unwrap_or_else(|_| String::from("rustc")))
138136
.arg("--print")
139137
.arg("sysroot")
140138
.output()

rls-analysis/src/lowering.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ where
5656
info!(
5757
"Lowering {} in {:.2}s",
5858
format!("{} ({:?})", id.name, id.disambiguator),
59-
time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0
59+
time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0
6060
);
6161
info!(" defs: {}", per_crate.defs.len());
6262
info!(" refs: {}", per_crate.ref_spans.len());
@@ -69,7 +69,7 @@ where
6969
let rss = util::get_resident().unwrap_or(0) as isize - rss as isize;
7070
info!(
7171
"Total lowering time: {:.2}s",
72-
time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0
72+
time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0
7373
);
7474
info!("Diff in rss: {:.2}KB", rss as f64 / 1000.0);
7575

@@ -80,7 +80,7 @@ fn lower_span(raw_span: &raw::SpanData, base_dir: &Path, path_rewrite: &Option<P
8080
let file_name = &raw_span.file_name;
8181

8282
// Go from relative to absolute paths.
83-
let file_name = if let &Some(ref prefix) = path_rewrite {
83+
let file_name = if let Some(ref prefix) = *path_rewrite {
8484
// Invariant: !file_name.is_absolute()
8585
// We don't assert this because better to have an incorrect span than to
8686
// panic.
@@ -221,7 +221,7 @@ impl<'a> CrateReader<'a> {
221221
}
222222
} else if let Some(ref ref_id) = i.ref_id {
223223
// Import where we know the referred def.
224-
let def_id = self.id_from_compiler_id(ref_id);
224+
let def_id = self.id_from_compiler_id(*ref_id);
225225
self.record_ref(def_id, span, analysis, project_analysis);
226226
if let Some(alias_span) = i.alias_span {
227227
let alias_span = lower_span(&alias_span, &self.base_dir, &self.path_rewrite);
@@ -322,13 +322,13 @@ impl<'a> CrateReader<'a> {
322322
continue;
323323
}
324324

325-
let id = self.id_from_compiler_id(&d.id);
325+
let id = self.id_from_compiler_id(d.id);
326326
if id != NULL && !analysis.defs.contains_key(&id) {
327327
let file_name = span.file.clone();
328328
analysis.defs_per_file.entry(file_name).or_insert_with(|| vec![]).push(id);
329329
let decl_id = match d.decl_id {
330330
Some(ref decl_id) => {
331-
let def_id = self.id_from_compiler_id(decl_id);
331+
let def_id = self.id_from_compiler_id(*decl_id);
332332
analysis
333333
.ref_spans
334334
.entry(def_id)
@@ -355,15 +355,15 @@ impl<'a> CrateReader<'a> {
355355
defs_to_index.push((d.name.to_lowercase(), id));
356356
}
357357

358-
let parent = d.parent.map(|id| self.id_from_compiler_id(&id));
358+
let parent = d.parent.map(|id| self.id_from_compiler_id(id));
359359
if let Some(parent) = parent {
360360
let children = analysis.children.entry(parent).or_insert_with(HashSet::new);
361361
children.insert(id);
362362
}
363363
if !d.children.is_empty() {
364364
let children_for_id = analysis.children.entry(id).or_insert_with(HashSet::new);
365365
children_for_id
366-
.extend(d.children.iter().map(|id| self.id_from_compiler_id(id)));
366+
.extend(d.children.iter().map(|id| self.id_from_compiler_id(*id)));
367367
}
368368

369369
let def = Def {
@@ -402,7 +402,9 @@ impl<'a> CrateReader<'a> {
402402
// save-analysis often omits parent info.
403403
for (parent, children) in &analysis.children {
404404
for c in children {
405-
analysis.defs.get_mut(c).map(|def| def.parent = Some(*parent));
405+
if let Some(def) = analysis.defs.get_mut(c) {
406+
def.parent = Some(*parent);
407+
}
406408
}
407409
}
408410
}
@@ -417,7 +419,7 @@ impl<'a> CrateReader<'a> {
417419
if r.span.file_name.to_str().map(|s| s.ends_with('>')).unwrap_or(true) {
418420
continue;
419421
}
420-
let def_id = self.id_from_compiler_id(&r.ref_id);
422+
let def_id = self.id_from_compiler_id(r.ref_id);
421423
let span = lower_span(&r.span, &self.base_dir, &self.path_rewrite);
422424
self.record_ref(def_id, span, analysis, project_analysis);
423425
}
@@ -434,8 +436,8 @@ impl<'a> CrateReader<'a> {
434436
RelationKind::Impl { .. } => {}
435437
_ => continue,
436438
}
437-
let self_id = self.id_from_compiler_id(&r.from);
438-
let trait_id = self.id_from_compiler_id(&r.to);
439+
let self_id = self.id_from_compiler_id(r.from);
440+
let trait_id = self.id_from_compiler_id(r.to);
439441
let span = lower_span(&r.span, &self.base_dir, &self.path_rewrite);
440442
if self_id != NULL {
441443
if let Some(self_id) = abs_ref_id(self_id, analysis, project_analysis) {
@@ -465,15 +467,15 @@ impl<'a> CrateReader<'a> {
465467

466468
// fn lower_sig_element(&self, raw_se: &raw::SigElement) -> SigElement {
467469
// SigElement {
468-
// id: self.id_from_compiler_id(&raw_se.id),
470+
// id: self.id_from_compiler_id(raw_se.id),
469471
// start: raw_se.start,
470472
// end: raw_se.end,
471473
// }
472474
// }
473475

474476
/// Recreates resulting crate-local (`u32`, `u32`) id from compiler
475477
/// to a global `u64` `Id`, mapping from a local to global crate id.
476-
fn id_from_compiler_id(&self, id: &data::Id) -> Id {
478+
fn id_from_compiler_id(&self, id: data::Id) -> Id {
477479
if id.krate == u32::MAX || id.index == u32::MAX {
478480
return NULL;
479481
}

rls-analysis/src/raw.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ impl Crate {
5050

5151
/// Reads raw analysis data for non-blacklisted crates from files in directories
5252
/// pointed by `loader`.
53-
pub fn read_analysis_from_files<L: AnalysisLoader>(
53+
pub fn read_analysis_from_files<L: AnalysisLoader, S: std::hash::BuildHasher>(
5454
loader: &L,
55-
crate_timestamps: HashMap<PathBuf, SystemTime>,
55+
crate_timestamps: HashMap<PathBuf, SystemTime, S>,
5656
crate_blacklist: Blacklist,
5757
) -> Vec<Crate> {
5858
let mut result = vec![];
@@ -75,14 +75,14 @@ pub fn read_analysis_from_files<L: AnalysisLoader>(
7575
let path = dir.path.join(&l.name);
7676
let is_fresh = crate_timestamps.get(&path).map_or(true, |t| time > t);
7777
if is_fresh {
78-
read_crate_data(&path).map(|analysis| {
78+
if let Some(analysis) = read_crate_data(&path) {
7979
result.push(Crate::new(
8080
analysis,
8181
*time,
8282
Some(path),
8383
dir.prefix_rewrite.clone(),
8484
));
85-
});
85+
};
8686
}
8787
}
8888
}
@@ -131,7 +131,7 @@ fn read_crate_data(path: &Path) -> Option<Analysis> {
131131
if let json::JsonValue::Object(obj) = parsed {
132132
let expected =
133133
Some(json::JsonValue::from(Analysis::new(Config::default()).version));
134-
let actual = obj.get("version").map(|v| v.clone());
134+
let actual = obj.get("version").cloned();
135135
if expected != actual {
136136
warn!(
137137
"Data file version mismatch; expected {:?} but got {:?}",

0 commit comments

Comments
 (0)