Skip to content

Commit 5620790

Browse files
authored
style: Use variables directly in the format! string (#1361)
Prevent clippy warnings like: ``` error: variables can be used directly in the `format!` string --> prost-derive/src/lib.rs:438:9 | 438 | / bail!( 439 | | "invalid oneof {}: multiple variants have tag {}", 440 | | ident, 441 | | duplicate_tag 442 | | ); | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args ```
1 parent 8336e65 commit 5620790

File tree

8 files changed

+18
-26
lines changed

8 files changed

+18
-26
lines changed

prost-build/src/code_generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ impl<'b> CodeGenerator<'_, 'b> {
884884

885885
fn push_service(&mut self, service: ServiceDescriptorProto) {
886886
let name = service.name().to_owned();
887-
debug!(" service: {:?}", name);
887+
debug!(" service: {name:?}");
888888

889889
let comments = self
890890
.location()

prost-build/src/code_generator/c_escaping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub(super) fn unescape_c_escape_string(s: &str) -> Vec<u8> {
6969
let mut octal = 0;
7070
for _ in 0..3 {
7171
if p < len && src[p] >= b'0' && src[p] <= b'7' {
72-
debug!("\toctal: {}", octal);
72+
debug!("\toctal: {octal}");
7373
octal = octal * 8 + (src[p] - b'0');
7474
p += 1;
7575
} else {

prost-build/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ impl Config {
967967
cmd.arg(proto.as_ref());
968968
}
969969

970-
debug!("Running: {:?}", cmd);
970+
debug!("Running: {cmd:?}");
971971

972972
let output = match cmd.output() {
973973
Err(err) if ErrorKind::NotFound == err.kind() => return Err(Error::new(

prost-derive/src/field/map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Field {
8282
None => bail!("invalid map attribute: must have key and value types"),
8383
};
8484
if items.next().is_some() {
85-
bail!("invalid map attribute: {:?}", attr);
85+
bail!("invalid map attribute: {attr:?}");
8686
}
8787
(k, v)
8888
}
@@ -367,7 +367,7 @@ fn key_ty_from_str(s: &str) -> Result<scalar::Ty, Error> {
367367
| scalar::Ty::Sfixed64
368368
| scalar::Ty::Bool
369369
| scalar::Ty::String => Ok(ty),
370-
_ => bail!("invalid map key type: {}", s),
370+
_ => bail!("invalid map key type: {s}"),
371371
}
372372
}
373373

@@ -385,7 +385,7 @@ impl ValueTy {
385385
} else if s.trim() == "message" {
386386
Ok(ValueTy::Message)
387387
} else {
388-
bail!("invalid map value type: {}", s);
388+
bail!("invalid map value type: {s}");
389389
}
390390
}
391391

prost-derive/src/field/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ where
247247
T: fmt::Debug,
248248
{
249249
if let Some(ref existing) = *option {
250-
bail!("{}: {:?} and {:?}", message, existing, value);
250+
bail!("{message}: {existing:?} and {value:?}");
251251
}
252252
*option = Some(value);
253253
Ok(())
254254
}
255255

256256
pub fn set_bool(b: &mut bool, message: &str) -> Result<(), Error> {
257257
if *b {
258-
bail!("{}", message);
258+
bail!("{message}");
259259
} else {
260260
*b = true;
261261
Ok(())
@@ -291,7 +291,7 @@ fn bool_attr(key: &str, attr: &Meta) -> Result<Option<bool>, Error> {
291291
}),
292292
..
293293
}) => Ok(Some(value)),
294-
_ => bail!("invalid {} attribute", key),
294+
_ => bail!("invalid {key} attribute"),
295295
}
296296
}
297297

@@ -320,9 +320,9 @@ pub(super) fn tag_attr(attr: &Meta) -> Result<Option<u32>, Error> {
320320
.map_err(Error::from)
321321
.map(Option::Some),
322322
Lit::Int(ref lit) => Ok(Some(lit.base10_parse()?)),
323-
_ => bail!("invalid tag attribute: {:?}", attr),
323+
_ => bail!("invalid tag attribute: {attr:?}"),
324324
},
325-
_ => bail!("invalid tag attribute: {:?}", attr),
325+
_ => bail!("invalid tag attribute: {attr:?}"),
326326
}
327327
}
328328

@@ -351,6 +351,6 @@ fn tags_attr(attr: &Meta) -> Result<Option<Vec<u32>>, Error> {
351351
.map(|s| s.trim().parse::<u32>().map_err(Error::from))
352352
.collect::<Result<Vec<u32>, _>>()
353353
.map(Some),
354-
_ => bail!("invalid tag attribute: {:?}", attr),
354+
_ => bail!("invalid tag attribute: {attr:?}"),
355355
}
356356
}

prost-derive/src/field/oneof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Field {
2929
..
3030
}) => parse_str::<Path>(&lit.value())?,
3131
Meta::List(ref list) => list.parse_args::<Ident>()?.into(),
32-
_ => bail!("invalid oneof attribute: {:?}", attr),
32+
_ => bail!("invalid oneof attribute: {attr:?}"),
3333
};
3434
set_option(&mut ty, t, "duplicate oneof attribute")?;
3535
} else if let Some(t) = tags_attr(attr)? {

prost-derive/src/field/scalar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl BytesTy {
409409
match s {
410410
"vec" => Ok(BytesTy::Vec),
411411
"bytes" => Ok(BytesTy::Bytes),
412-
_ => bail!("Invalid bytes type: {}", s),
412+
_ => bail!("Invalid bytes type: {s}"),
413413
}
414414
}
415415

@@ -467,7 +467,7 @@ impl Ty {
467467

468468
pub fn from_str(s: &str) -> Result<Ty, Error> {
469469
let enumeration_len = "enumeration".len();
470-
let error = Err(anyhow!("invalid type: {}", s));
470+
let error = Err(anyhow!("invalid type: {s}"));
471471
let ty = match s.trim() {
472472
"float" => Ty::Float,
473473
"double" => Ty::Double,
@@ -622,7 +622,7 @@ impl DefaultValue {
622622
{
623623
Ok(Some(lit.clone()))
624624
} else {
625-
bail!("invalid default value attribute: {:?}", attr)
625+
bail!("invalid default value attribute: {attr:?}")
626626
}
627627
}
628628

prost-derive/src/lib.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ fn try_message(input: TokenStream) -> Result<TokenStream, Error> {
9797
.duplicates()
9898
.next()
9999
{
100-
bail!(
101-
"message {} has multiple fields with tag {}",
102-
ident,
103-
duplicate_tag
104-
)
100+
bail!("message {ident} has multiple fields with tag {duplicate_tag}",)
105101
};
106102

107103
let encoded_len = fields
@@ -435,11 +431,7 @@ fn try_oneof(input: TokenStream) -> Result<TokenStream, Error> {
435431
.duplicates()
436432
.next()
437433
{
438-
bail!(
439-
"invalid oneof {}: multiple variants have tag {}",
440-
ident,
441-
duplicate_tag
442-
);
434+
bail!("invalid oneof {ident}: multiple variants have tag {duplicate_tag}");
443435
}
444436

445437
let encode = fields.iter().map(|(variant_ident, field, deprecated)| {

0 commit comments

Comments
 (0)