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

Commit

Permalink
Merge pull request #1395 from jabagawee/fix-clippy
Browse files Browse the repository at this point in the history
Fix cargo clippy warnings
  • Loading branch information
Xanewok authored Mar 17, 2019
2 parents e89a955 + 7ea0866 commit 90f7ab0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
9 changes: 4 additions & 5 deletions rls-analysis/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Analysis {
self.per_crate
.values()
.filter(|c| c.path.is_some())
.map(|c| (c.path.as_ref().unwrap().clone(), c.timestamp.clone()))
.map(|c| (c.path.as_ref().unwrap().clone(), c.timestamp))
.collect()
}

Expand Down Expand Up @@ -212,8 +212,7 @@ impl Analysis {
// "error in for_each_crate, found {} results, expected 0 or 1",
// result.len(),
// );
let temp = result.drain(..).next();
temp // stupid NLL bug
result.into_iter().nth(0)
}

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

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

// Like def_id_for_span, but will only return a def_id if it is in the same
// crate.
pub fn local_def_id_for_span(&self, span: &Span) -> Option<Id> {
self.for_each_crate(|c| {
c.def_id_for_span.get(span).map(|r| r.some_id()).and_then(|id| {
c.def_id_for_span.get(span).map(Ref::some_id).and_then(|id| {
if c.defs.contains_key(&id) {
Some(id)
} else {
Expand Down
19 changes: 11 additions & 8 deletions rls-analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Id {
fn from_crate_and_local(crate_id: u32, local_id: u32) -> Id {
// Use global crate number for high order bits,
// then index for least significant bits.
Id(((crate_id as u64) << 32) | (local_id as u64))
Id((u64::from(crate_id) << 32) | u64::from(local_id))
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
}

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

pub fn goto_def(&self, span: &Span) -> AResult<Span> {
Expand Down Expand Up @@ -335,7 +335,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
let time = t_start.elapsed();
info!(
"find_all_refs: {}s",
time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0
time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0
);
result
}
Expand Down Expand Up @@ -370,7 +370,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
let time = t_start.elapsed();
info!(
"query_defs: {}",
time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0
time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0
);

result
Expand All @@ -383,7 +383,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
let result = self.with_analysis(|a| {
Some(a.with_def_names(name, |defs| {
info!("defs: {:?}", defs);
defs.into_iter()
defs.iter()
.flat_map(|id| {
a.with_ref_spans(*id, |refs| {
Some(
Expand All @@ -402,7 +402,10 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
});

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

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

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

pub fn symbols(&self, file_name: &Path) -> AResult<Vec<SymbolResult>> {
Expand Down
8 changes: 3 additions & 5 deletions rls-analysis/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn extract_target_triple(sys_root_path: &Path) -> String {
}

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

fn sys_root_path() -> PathBuf {
env::var("SYSROOT")
.ok()
.map(PathBuf::from)
.or_else(|| {
Command::new(env::var("RUSTC").unwrap_or(String::from("rustc")))
Command::new(env::var("RUSTC").unwrap_or_else(|_| String::from("rustc")))
.arg("--print")
.arg("sysroot")
.output()
Expand Down
30 changes: 16 additions & 14 deletions rls-analysis/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
info!(
"Lowering {} in {:.2}s",
format!("{} ({:?})", id.name, id.disambiguator),
time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0
time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0
);
info!(" defs: {}", per_crate.defs.len());
info!(" refs: {}", per_crate.ref_spans.len());
Expand All @@ -69,7 +69,7 @@ where
let rss = util::get_resident().unwrap_or(0) as isize - rss as isize;
info!(
"Total lowering time: {:.2}s",
time.as_secs() as f64 + time.subsec_nanos() as f64 / 1_000_000_000.0
time.as_secs() as f64 + f64::from(time.subsec_nanos()) / 1_000_000_000.0
);
info!("Diff in rss: {:.2}KB", rss as f64 / 1000.0);

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

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

let id = self.id_from_compiler_id(&d.id);
let id = self.id_from_compiler_id(d.id);
if id != NULL && !analysis.defs.contains_key(&id) {
let file_name = span.file.clone();
analysis.defs_per_file.entry(file_name).or_insert_with(|| vec![]).push(id);
let decl_id = match d.decl_id {
Some(ref decl_id) => {
let def_id = self.id_from_compiler_id(decl_id);
let def_id = self.id_from_compiler_id(*decl_id);
analysis
.ref_spans
.entry(def_id)
Expand All @@ -355,15 +355,15 @@ impl<'a> CrateReader<'a> {
defs_to_index.push((d.name.to_lowercase(), id));
}

let parent = d.parent.map(|id| self.id_from_compiler_id(&id));
let parent = d.parent.map(|id| self.id_from_compiler_id(id));
if let Some(parent) = parent {
let children = analysis.children.entry(parent).or_insert_with(HashSet::new);
children.insert(id);
}
if !d.children.is_empty() {
let children_for_id = analysis.children.entry(id).or_insert_with(HashSet::new);
children_for_id
.extend(d.children.iter().map(|id| self.id_from_compiler_id(id)));
.extend(d.children.iter().map(|id| self.id_from_compiler_id(*id)));
}

let def = Def {
Expand Down Expand Up @@ -402,7 +402,9 @@ impl<'a> CrateReader<'a> {
// save-analysis often omits parent info.
for (parent, children) in &analysis.children {
for c in children {
analysis.defs.get_mut(c).map(|def| def.parent = Some(*parent));
if let Some(def) = analysis.defs.get_mut(c) {
def.parent = Some(*parent);
}
}
}
}
Expand All @@ -417,7 +419,7 @@ impl<'a> CrateReader<'a> {
if r.span.file_name.to_str().map(|s| s.ends_with('>')).unwrap_or(true) {
continue;
}
let def_id = self.id_from_compiler_id(&r.ref_id);
let def_id = self.id_from_compiler_id(r.ref_id);
let span = lower_span(&r.span, &self.base_dir, &self.path_rewrite);
self.record_ref(def_id, span, analysis, project_analysis);
}
Expand All @@ -434,8 +436,8 @@ impl<'a> CrateReader<'a> {
RelationKind::Impl { .. } => {}
_ => continue,
}
let self_id = self.id_from_compiler_id(&r.from);
let trait_id = self.id_from_compiler_id(&r.to);
let self_id = self.id_from_compiler_id(r.from);
let trait_id = self.id_from_compiler_id(r.to);
let span = lower_span(&r.span, &self.base_dir, &self.path_rewrite);
if self_id != NULL {
if let Some(self_id) = abs_ref_id(self_id, analysis, project_analysis) {
Expand Down Expand Up @@ -465,15 +467,15 @@ impl<'a> CrateReader<'a> {

// fn lower_sig_element(&self, raw_se: &raw::SigElement) -> SigElement {
// SigElement {
// id: self.id_from_compiler_id(&raw_se.id),
// id: self.id_from_compiler_id(raw_se.id),
// start: raw_se.start,
// end: raw_se.end,
// }
// }

/// Recreates resulting crate-local (`u32`, `u32`) id from compiler
/// to a global `u64` `Id`, mapping from a local to global crate id.
fn id_from_compiler_id(&self, id: &data::Id) -> Id {
fn id_from_compiler_id(&self, id: data::Id) -> Id {
if id.krate == u32::MAX || id.index == u32::MAX {
return NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions rls-analysis/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ pub fn read_analysis_from_files<L: AnalysisLoader>(
let path = dir.path.join(&l.name);
let is_fresh = crate_timestamps.get(&path).map_or(true, |t| time > t);
if is_fresh {
read_crate_data(&path).map(|analysis| {
if let Some(analysis) = read_crate_data(&path) {
result.push(Crate::new(
analysis,
*time,
Some(path),
dir.prefix_rewrite.clone(),
));
});
};
}
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ fn read_crate_data(path: &Path) -> Option<Analysis> {
if let json::JsonValue::Object(obj) = parsed {
let expected =
Some(json::JsonValue::from(Analysis::new(Config::default()).version));
let actual = obj.get("version").map(|v| v.clone());
let actual = obj.get("version").cloned();
if expected != actual {
warn!(
"Data file version mismatch; expected {:?} but got {:?}",
Expand Down

0 comments on commit 90f7ab0

Please sign in to comment.