Inline all format arguments where possible

This makes code more readale and concise,
moving all format arguments like `format!("{}", foo)`
into the more compact `format!("{foo}")` form.

The change was automatically created with, so there are far less change
of an accidental typo.

```
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
This commit is contained in:
Yuri Astrakhan 2022-12-23 13:42:58 -05:00
parent 1927c2e1d8
commit e16c76e3c3
180 changed files with 487 additions and 501 deletions

View file

@ -877,7 +877,7 @@ impl Literal {
/// example if it is infinity or NaN this function will panic.
pub fn f32_unsuffixed(n: f32) -> Literal {
if !n.is_finite() {
panic!("Invalid float literal {}", n);
panic!("Invalid float literal {n}");
}
let mut repr = n.to_string();
if !repr.contains('.') {
@ -901,7 +901,7 @@ impl Literal {
/// example if it is infinity or NaN this function will panic.
pub fn f32_suffixed(n: f32) -> Literal {
if !n.is_finite() {
panic!("Invalid float literal {}", n);
panic!("Invalid float literal {n}");
}
Literal(bridge::client::Literal::f32(&n.to_string()))
}
@ -920,7 +920,7 @@ impl Literal {
/// example if it is infinity or NaN this function will panic.
pub fn f64_unsuffixed(n: f64) -> Literal {
if !n.is_finite() {
panic!("Invalid float literal {}", n);
panic!("Invalid float literal {n}");
}
let mut repr = n.to_string();
if !repr.contains('.') {
@ -944,7 +944,7 @@ impl Literal {
/// example if it is infinity or NaN this function will panic.
pub fn f64_suffixed(n: f64) -> Literal {
if !n.is_finite() {
panic!("Invalid float literal {}", n);
panic!("Invalid float literal {n}");
}
Literal(bridge::client::Literal::f64(&n.to_string()))
}

View file

@ -548,13 +548,13 @@ impl server::Literal for RustAnalyzer {
fn f32(&mut self, n: &str) -> Self::Literal {
let n: f32 = n.parse().unwrap();
let text = format!("{}f32", n);
let text = format!("{n}f32");
Literal { text: text.into(), id: tt::TokenId::unspecified() }
}
fn f64(&mut self, n: &str) -> Self::Literal {
let n: f64 = n.parse().unwrap();
let text = format!("{}f64", n);
let text = format!("{n}f64");
Literal { text: text.into(), id: tt::TokenId::unspecified() }
}
@ -563,11 +563,11 @@ impl server::Literal for RustAnalyzer {
for ch in string.chars() {
escaped.extend(ch.escape_debug());
}
Literal { text: format!("\"{}\"", escaped).into(), id: tt::TokenId::unspecified() }
Literal { text: format!("\"{escaped}\"").into(), id: tt::TokenId::unspecified() }
}
fn character(&mut self, ch: char) -> Self::Literal {
Literal { text: format!("'{}'", ch).into(), id: tt::TokenId::unspecified() }
Literal { text: format!("'{ch}'").into(), id: tt::TokenId::unspecified() }
}
fn byte_string(&mut self, bytes: &[u8]) -> Self::Literal {
@ -578,7 +578,7 @@ impl server::Literal for RustAnalyzer {
.map(Into::<char>::into)
.collect::<String>();
Literal { text: format!("b\"{}\"", string).into(), id: tt::TokenId::unspecified() }
Literal { text: format!("b\"{string}\"").into(), id: tt::TokenId::unspecified() }
}
fn span(&mut self, literal: &Self::Literal) -> Self::Span {

View file

@ -563,13 +563,13 @@ impl server::Literal for RustAnalyzer {
fn f32(&mut self, n: &str) -> Self::Literal {
let n: f32 = n.parse().unwrap();
let text = format!("{}f32", n);
let text = format!("{n}f32");
Literal { text: text.into(), id: tt::TokenId::unspecified() }
}
fn f64(&mut self, n: &str) -> Self::Literal {
let n: f64 = n.parse().unwrap();
let text = format!("{}f64", n);
let text = format!("{n}f64");
Literal { text: text.into(), id: tt::TokenId::unspecified() }
}
@ -578,11 +578,11 @@ impl server::Literal for RustAnalyzer {
for ch in string.chars() {
escaped.extend(ch.escape_debug());
}
Literal { text: format!("\"{}\"", escaped).into(), id: tt::TokenId::unspecified() }
Literal { text: format!("\"{escaped}\"").into(), id: tt::TokenId::unspecified() }
}
fn character(&mut self, ch: char) -> Self::Literal {
Literal { text: format!("'{}'", ch).into(), id: tt::TokenId::unspecified() }
Literal { text: format!("'{ch}'").into(), id: tt::TokenId::unspecified() }
}
fn byte_string(&mut self, bytes: &[u8]) -> Self::Literal {
@ -593,7 +593,7 @@ impl server::Literal for RustAnalyzer {
.map(Into::<char>::into)
.collect::<String>();
Literal { text: format!("b\"{}\"", string).into(), id: tt::TokenId::unspecified() }
Literal { text: format!("b\"{string}\"").into(), id: tt::TokenId::unspecified() }
}
fn span(&mut self, literal: &Self::Literal) -> Self::Span {

View file

@ -48,7 +48,7 @@ impl ProcMacroSrv {
pub fn expand(&mut self, task: ExpandMacro) -> Result<FlatTree, PanicMessage> {
let expander = self.expander(task.lib.as_ref()).map_err(|err| {
debug_assert!(false, "should list macros before asking to expand");
PanicMessage(format!("failed to load macro: {}", err))
PanicMessage(format!("failed to load macro: {err}"))
})?;
let prev_env = EnvSnapshot::new();
@ -59,7 +59,7 @@ impl ProcMacroSrv {
Some(dir) => {
let prev_working_dir = std::env::current_dir().ok();
if let Err(err) = std::env::set_current_dir(&dir) {
eprintln!("Failed to set the current working dir to {}. Error: {:?}", dir, err)
eprintln!("Failed to set the current working dir to {dir}. Error: {err:?}")
}
prev_working_dir
}
@ -112,14 +112,16 @@ impl ProcMacroSrv {
}
fn expander(&mut self, path: &Path) -> Result<&dylib::Expander, String> {
let time = fs::metadata(path).and_then(|it| it.modified()).map_err(|err| {
format!("Failed to get file metadata for {}: {}", path.display(), err)
})?;
let time = fs::metadata(path)
.and_then(|it| it.modified())
.map_err(|err| format!("Failed to get file metadata for {}: {err}", path.display()))?;
Ok(match self.expanders.entry((path.to_path_buf(), time)) {
Entry::Vacant(v) => v.insert(dylib::Expander::new(path).map_err(|err| {
format!("Cannot create expander for {}: {}", path.display(), err)
})?),
Entry::Vacant(v) => {
v.insert(dylib::Expander::new(path).map_err(|err| {
format!("Cannot create expander for {}: {err}", path.display())
})?)
}
Entry::Occupied(e) => e.into_mut(),
})
}