Skip to content

Commit

Permalink
Fix clippy::uninlined_format_args lint
Browse files Browse the repository at this point in the history
https://rust-lang.github.io/rust-clippy/master/#uninlined_format_args

This lint was promoted from "pedantic" in Rust 1.67.0.  It was
subsequently [demoted to "pedantic"
again](rust-lang/rust#107743) in 1.67.1, so one
solution would be to just use another version for now.

It does however seem likely that it will be reintroduced at some point,
so applying the fix.

rust-lang/rust-clippy#10265
  • Loading branch information
argerus authored and SebastianSchildt committed Feb 13, 2023
1 parent c91f80c commit 6b7cffc
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 95 deletions.
52 changes: 21 additions & 31 deletions databroker-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn connect(
}
Err(err) => {
set_disconnected_prompt(interface);
writeln!(interface, "{}", err).unwrap();
writeln!(interface, "{err}").unwrap();
None
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let addr = std::env::var("KUKSA_DATA_BROKER_ADDR").unwrap_or_else(|_| "127.0.0.1".to_owned());
let port = std::env::var("KUKSA_DATA_BROKER_PORT").unwrap_or_else(|_| "55555".to_owned());
let mut uri = match addr_to_uri(format!("{}:{}", addr, port)) {
let mut uri = match addr_to_uri(format!("{addr}:{port}")) {
Some(uri) => uri,
None => return Err(Box::new(ParseError {}).into()),
};
Expand All @@ -154,10 +154,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (cmd, args) = split_first_word(&line);
match cmd {
"help" => {
println!("{} commands:", APP_NAME);
println!("{APP_NAME} commands:");
println!();
for &(cmd, help) in CLI_COMMANDS {
println!(" {:15} - {}", cmd, help);
println!(" {cmd:15} - {help}");
}
println!();
}
Expand Down Expand Up @@ -270,15 +270,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
) {
Some(error) => {
println!(
"-> Error setting id {}: {:?}",
id, error
"-> Error setting id {id}: {error:?}"
)
}
None => {
println!(
"-> Error setting id {}",
id
)
println!("-> Error setting id {id}")
}
}
}
Expand Down Expand Up @@ -367,15 +363,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
) {
Some(error) => {
println!(
"-> Error setting id {}: {:?}",
id, error
"-> Error setting id {id}: {error:?}"
)
}
None => {
println!(
"-> Error setting id {}",
id
)
println!("-> Error setting id {id}")
}
}
}
Expand Down Expand Up @@ -417,8 +409,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic::Request::new(proto::v1::SubscribeRequest { query });
match client.subscribe(args).await {
Ok(response) => {
let sub_id =
format!("subscription{}", subscription_nbr);
let sub_id = format!("subscription{subscription_nbr}");
subscription_nbr += 1;
tokio::spawn(async move {
let mut stream = response.into_inner();
Expand All @@ -441,8 +432,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
writeln!(
iface,
"-> {}:\n{}",
sub_id, output
"-> {sub_id}:\n{output}"
)
.unwrap();
}
Expand Down Expand Up @@ -531,7 +521,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
break;
}
ReadResult::Signal(sig) => {
println!("received signal: {:?}", sig);
println!("received signal: {sig:?}");
}
}
}
Expand Down Expand Up @@ -778,9 +768,9 @@ where
let real_delimiter = ", ";
let mut delimiter = "";
for value in array {
write!(f, "{}", delimiter)?;
write!(f, "{delimiter}")?;
delimiter = real_delimiter;
write!(f, "{}", value)?;
write!(f, "{value}")?;
}
f.write_str("]")
}
Expand All @@ -790,32 +780,32 @@ impl fmt::Display for DisplayDatapoint {
match &self.0.value {
Some(value) => match value {
proto::v1::datapoint::Value::BoolValue(value) => {
f.write_fmt(format_args!("{}", value))
f.write_fmt(format_args!("{value}"))
}
proto::v1::datapoint::Value::FailureValue(failure) => f.write_fmt(format_args!(
"( {:?} )",
proto::v1::datapoint::Failure::from_i32(*failure).unwrap()
)),
proto::v1::datapoint::Value::Int32Value(value) => {
f.write_fmt(format_args!("{}", value))
f.write_fmt(format_args!("{value}"))
}
proto::v1::datapoint::Value::Int64Value(value) => {
f.write_fmt(format_args!("{}", value))
f.write_fmt(format_args!("{value}"))
}
proto::v1::datapoint::Value::Uint32Value(value) => {
f.write_fmt(format_args!("{}", value))
f.write_fmt(format_args!("{value}"))
}
proto::v1::datapoint::Value::Uint64Value(value) => {
f.write_fmt(format_args!("{}", value))
f.write_fmt(format_args!("{value}"))
}
proto::v1::datapoint::Value::FloatValue(value) => {
f.write_fmt(format_args!("{:.2}", value))
f.write_fmt(format_args!("{value:.2}"))
}
proto::v1::datapoint::Value::DoubleValue(value) => {
f.write_fmt(format_args!("{}", value))
f.write_fmt(format_args!("{value}"))
}
proto::v1::datapoint::Value::StringValue(value) => {
f.write_fmt(format_args!("'{}'", value))
f.write_fmt(format_args!("'{value}'"))
}
proto::v1::datapoint::Value::StringArray(array) => display_array(f, &array.values),
proto::v1::datapoint::Value::BoolArray(array) => display_array(f, &array.values),
Expand Down
16 changes: 8 additions & 8 deletions databroker-examples/examples/perf_setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn run_streaming_set_test(iterations: i32, n_th_message: i32) {
{
Ok(metadata) => metadata.into_inner().results["Vehicle.ADAS.ABS.Error"],
Err(err) => {
println!("Couldn't retrieve metadata: {:?}", err);
println!("Couldn't retrieve metadata: {err:?}");
-1
}
};
Expand Down Expand Up @@ -108,7 +108,7 @@ async fn run_streaming_set_test(iterations: i32, n_th_message: i32) {
Ok(_) => {
eprintln!("START");
}
Err(err) => eprint!("{}", err),
Err(err) => eprint!("{err}"),
};

let mut n: i32 = 0;
Expand All @@ -135,7 +135,7 @@ async fn run_streaming_set_test(iterations: i32, n_th_message: i32) {
}
n += 1;
}
Err(err) => eprint!("{}", err),
Err(err) => eprint!("{err}"),
};
}

Expand All @@ -144,7 +144,7 @@ async fn run_streaming_set_test(iterations: i32, n_th_message: i32) {
Ok(_) => {
eprintln!("\rEND ");
}
Err(err) => eprint!("{}", err),
Err(err) => eprint!("{err}"),
};

(n, n_id)
Expand All @@ -153,7 +153,7 @@ async fn run_streaming_set_test(iterations: i32, n_th_message: i32) {
let (n, n_id) = feeder.await.unwrap();
match sender.await {
Ok(_) => {}
Err(err) => eprint!("{}", err),
Err(err) => eprint!("{err}"),
};

let seconds = now.elapsed().as_secs_f64();
Expand All @@ -167,10 +167,10 @@ async fn run_streaming_set_test(iterations: i32, n_th_message: i32) {
n_id,
n_id as f64 / seconds
);
println!("Completed in {:.3} s", seconds);
println!("Completed in {seconds:.3} s");
}
Err(err) => {
println!("{}", err);
println!("{err}");
}
}
}
Expand All @@ -194,7 +194,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
None => DEFAULT_NTH_MESSAGE,
};

println!("INPUT: Set {} times", iterations);
println!("INPUT: Set {iterations} times");

// run_set_test(iterations).await;
run_streaming_set_test(iterations, queue_size).await;
Expand Down
6 changes: 3 additions & 3 deletions databroker-examples/examples/perf_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
match value {
proto::v1::datapoint::Value::FailureValue(reason) => {
if started {
eprintln!("-> Failure: {:?}", reason);
eprintln!("-> Failure: {reason:?}");
}
}
proto::v1::datapoint::Value::StringValue(string_value) => {
Expand All @@ -66,7 +66,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
n,
n as f64 / seconds
);
eprintln!("Completed in {:.3} s", seconds);
eprintln!("Completed in {seconds:.3} s");
}
}
_ => {
Expand Down Expand Up @@ -105,7 +105,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
Err(err) => {
eprintln!("{}", err);
eprintln!("{err}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion databroker/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() -> Result<()> {
Ok(ok) => Ok(ok),
Err(e) => {
// Swallow the errors for now (enable with -vv)
eprintln!("vergen failed: {}", e);
eprintln!("vergen failed: {e}");
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion databroker/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ impl DataBroker {
let stream = ReceiverStream::new(receiver);
Ok(stream)
}
Err(e) => Err(QueryError::CompilationError(format!("{:?}", e))),
Err(e) => Err(QueryError::CompilationError(format!("{e:?}"))),
}
}

Expand Down
5 changes: 2 additions & 3 deletions databroker/src/grpc/kuksa_val_v1/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ impl proto::val_server::Val for broker::DataBroker {
},
None => {
return Err(tonic::Status::invalid_argument(format!(
"Invalid Field (id: {})",
id
"Invalid Field (id: {id})"
)))
}
};
Expand All @@ -212,7 +211,7 @@ impl proto::val_server::Val for broker::DataBroker {
}
Err(e) => Err(tonic::Status::new(
tonic::Code::InvalidArgument,
format!("{:?}", e),
format!("{e:?}"),
)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion databroker/src/grpc/sdv_databroker_v1/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl proto::broker_server::Broker for broker::DataBroker {
debug!("Subscribed to new query");
Ok(Response::new(Box::pin(stream)))
}
Err(e) => Err(Status::new(Code::InvalidArgument, format!("{:?}", e))),
Err(e) => Err(Status::new(Code::InvalidArgument, format!("{e:?}"))),
}
}

Expand Down
4 changes: 2 additions & 2 deletions databroker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const DATAPOINTS: &[(
fn init_logging() {
let mut output = String::from("Init logging from RUST_LOG");
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|err| {
output.write_fmt(format_args!(" ({})", err)).unwrap();
output.write_fmt(format_args!(" ({err})")).unwrap();
// If no environment variable set, this is the default
EnvFilter::new("info")
});
Expand Down Expand Up @@ -306,7 +306,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await
{
Ok(_) => {}
Err(e) => println!("{:?}", e),
Err(e) => println!("{e:?}"),
}
}
}
Expand Down
27 changes: 10 additions & 17 deletions databroker/src/query/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,15 @@ pub fn compile_expr(
Ok(left_expr) => (Box::new(left_expr), Box::new(right_expr)),
Err(_) => {
return Err(CompilationError::TypeError(format!(
"left side is incompatible with right side in expression \"{}\"",
expr
"left side is incompatible with right side in expression \"{expr}\""
)))
}
},
(Ok(left_type), Err(literal)) => match resolve_literal(literal, left_type) {
Ok(right_expr) => (Box::new(left_expr), Box::new(right_expr)),
Err(_) => {
return Err(CompilationError::TypeError(format!(
"right side is incompatible with left side in expression \"{}\"",
expr
"right side is incompatible with left side in expression \"{expr}\""
)))
}
},
Expand Down Expand Up @@ -222,8 +220,7 @@ pub fn compile_expr(
}),
),
_ => return Err(CompilationError::TypeError(format!(
"right side is incompatible with left side in expression \"{}\"",
expr
"right side is incompatible with left side in expression \"{expr}\""
)))
},
}
Expand All @@ -232,8 +229,7 @@ pub fn compile_expr(
}
_ => {
return Err(CompilationError::TypeError(format!(
"right side is incompatible with left side in expression \"{}\"",
expr
"right side is incompatible with left side in expression \"{expr}\""
)))
}
}
Expand Down Expand Up @@ -295,10 +291,9 @@ pub fn compile_expr(
"OR requires boolean expressions on both sides".to_string(),
)),
},
operator => Err(CompilationError::UnsupportedOperator(format!(
"{}",
operator,
))),
operator => Err(CompilationError::UnsupportedOperator(
format!("{operator}",),
)),
}
}
ast::Expr::Nested(e) => compile_expr(e, input, output),
Expand All @@ -309,8 +304,7 @@ pub fn compile_expr(
operator: UnaryOperator::Not,
}),
operator => Err(CompilationError::UnsupportedOperator(format!(
"Unsupported unary operator \"{}\"",
operator
"Unsupported unary operator \"{operator}\""
))),
},

Expand All @@ -326,8 +320,7 @@ pub fn compile_expr(
high: Box::new(compile_expr(high, input, output)?),
}),
operator => Err(CompilationError::UnsupportedOperator(format!(
"Unsupported operator \"{}\"",
operator
"Unsupported operator \"{operator}\""
))),
}
}
Expand Down Expand Up @@ -476,6 +469,6 @@ pub fn compile(
))
}
}
Err(e) => Err(CompilationError::ParseError(format!("{}", e))),
Err(e) => Err(CompilationError::ParseError(format!("{e}"))),
}
}
Loading

0 comments on commit 6b7cffc

Please sign in to comment.