Skip to content

Commit

Permalink
use inline format specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
wfraser committed Nov 16, 2022
1 parent 0b5424e commit 0845421
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ impl Analysis {
.current_dir(workspace_path)
.status()
.map_err(|e|
format!("failed to run 'cargo build': {}", e)
format!("failed to run 'cargo build': {e}")
)?;

if cargo_status.success() {
Ok(())
} else if let Some(code) = cargo_status.code() {
Err(format!("'cargo build' failed with exit code {}", code))
Err(format!("'cargo build' failed with exit code {code}"))
} else {
Err("'cargo build' killed by signal".to_owned())
}
Expand Down Expand Up @@ -281,7 +281,7 @@ impl std::str::FromStr for CrateType {
"cdylib" => Self::CDylib,
"dylib" => Self::Dylib,
_ => {
return Err(format!("unknown crate type {:?}", s));
return Err(format!("unknown crate type {s:?}"));
}
})
}
Expand All @@ -303,7 +303,7 @@ impl AnalysisLoader for Loader {
}

fn set_path_prefix(&mut self, prefix: &Path) {
unimplemented!("prefix: {:?}", prefix);
unimplemented!("prefix: {prefix:?}");
}

fn abs_path_prefix(&self) -> Option<PathBuf> {
Expand Down Expand Up @@ -343,15 +343,15 @@ fn get_stdlib_analysis_path() -> Option<PathBuf> {
.arg("target-libdir")
.output()
.map_err(|e| {
eprintln!("Error running 'rustc --print target-libdir': {}", e);
eprintln!("Error running 'rustc --print target-libdir': {e}");
e
})
.ok()
.and_then(|out| {
if out.status.success() {
let path = String::from_utf8(out.stdout)
.map_err(|e| {
eprintln!("'rustc --print target-libdir' returned invalid utf8: {}", e);
eprintln!("'rustc --print target-libdir' returned invalid utf8: {e}");
e
})
.ok()?;
Expand Down
18 changes: 9 additions & 9 deletions src/browser_rls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Browser for RlsBrowser {
}
None => "Self".to_owned(),
};
(format!("impl {}", trait_name), Item::Impl(impl_details))
(format!("impl {trait_name}"), Item::Impl(impl_details))
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -182,18 +182,18 @@ impl Browser for RlsBrowser {
}
}
Item::Root => {
write!(txt, "crate root of {:?}", crate_id).unwrap();
write!(txt, "crate root of {crate_id:?}").unwrap();
}
}
txt
}

fn get_debug_info(&self, crate_id: &CrateId, item: &Item) -> String {
let mut txt = format!("{:#?}", item);
let mut txt = format!("{item:#?}");
let add_children = |txt: &mut String, crate_id, children: &[rls_data::Id]| {
for child_id in children {
if let Some(child) = self.analysis.get_def(crate_id, *child_id) {
write!(txt, "\nchild {:?} = {:#?}", child_id, child).unwrap();
write!(txt, "\nchild {child_id:?} = {child:#?}").unwrap();
}
}
};
Expand All @@ -207,7 +207,7 @@ impl Browser for RlsBrowser {
}
Item::Impl(impl_details) => {
let imp = self.analysis.get_impl(crate_id, impl_details.impl_id).unwrap();
write!(txt, "\nimpl: {:#?}", imp).unwrap();
write!(txt, "\nimpl: {imp:#?}").unwrap();
add_children(&mut txt, crate_id, &imp.children);
}
Item::Root => (),
Expand All @@ -223,7 +223,7 @@ impl Browser for RlsBrowser {
}
Item::Impl(imp) => {
let id = imp.trait_id.unwrap_or(imp.impl_on);
(format!("source listing unimplemented for impls. impl ID = {:?}", id), None)
(format!("source listing unimplemented for impls. impl ID = {id:?}"), None)
}
Item::Root => (String::new(), None),
}
Expand All @@ -241,7 +241,7 @@ fn get_source_for_def(def: &rls_data::Def) -> (String, usize) {
.enumerate()
{
write!(txt, "{}: ", i + 1).unwrap();
txt += &line.unwrap_or_else(|e| format!("<Read Error: {}>", e));
txt += &line.unwrap_or_else(|e| format!("<Read Error: {e}>"));
txt.push('\n');
}
let mut line = def.span.line_start.0 - 1;
Expand All @@ -253,7 +253,7 @@ fn get_source_for_def(def: &rls_data::Def) -> (String, usize) {
(txt, line as usize)
}
Err(e) => {
(format!("Error opening source: {}", e), 0)
(format!("Error opening source: {e}"), 0)
}
}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ fn def_label(def: &Def) -> String {
DefKind::Field => return format!("{}: {}", def.name, def.value),
DefKind::Local => "local", // or should we return None?
};
format!("{} {}", prefix, def.name)
format!("{prefix} {}", def.name)
}

#[allow(clippy::large_enum_variant)]
Expand Down

0 comments on commit 0845421

Please sign in to comment.