rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Automatic fix for nonstandard_macro_braces fails

Open djc opened this issue 2 months ago • 7 comments

Summary

For this issue:

warning: use of irregular braces for `format!` macro
   --> crates/resolver/src/hosts.rs:246:9
    |
246 |         format! {"{server_path}/crates/resolver/tests"}
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `format!("{server_path}/crates/resolver/tests");`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.99.0/index.html#nonstandard_macro_braces
    = note: `#[warn(clippy::nonstandard_macro_braces)]` on by default

--fix produced this diff:

diff --git a/crates/resolver/src/hosts.rs b/crates/resolver/src/hosts.rs
index b314f4665..92ce94c0d 100644
--- a/crates/resolver/src/hosts.rs
+++ b/crates/resolver/src/hosts.rs
@@ -243,7 +243,7 @@ mod tests {
 
     fn tests_dir() -> String {
         let server_path = env::var("TDNS_WORKSPACE_ROOT").unwrap_or_else(|_| "../..".to_owned());
-        format! {"{server_path}/crates/resolver/tests"}
+        format!("{server_path}/crates/resolver/tests");
     }
 

resulting in this compilation failure:

error[E0308]: mismatched types
   --> crates/resolver/src/hosts.rs:244:23
    |
244 |     fn tests_dir() -> String {
    |        ---------      ^^^^^^ expected `String`, found `()`
    |        |
    |        implicitly returns `()` as its body has no tail or `return` expression
245 |         let server_path = env::var("TDNS_WORKSPACE_R...
246 |         format!("{server_path}/crates/resolver/tests");
    |                                                       - help: remove this semicolon to return this value

Original code:

https://github.com/hickory-dns/hickory-dns/blob/ec87f21341219d6be18f1cf1fe90ec2f0e975653/crates/resolver/src/hosts.rs#L246

With stable clippy from Rust 1.99.

djc avatar Oct 01 '26 13:10 djc

I-suggestion-causes-bug is described as "suggestion compiles", but that's not the case here, FWIW.

djc avatar Oct 01 '26 13:10 djc

ah thanks ^^

CommanderStorm avatar Oct 01 '26 14:10 CommanderStorm

uhmmmm... I'm thinking of giving this a shot. Can I go ahead?

codediebere avatar Oct 01 '26 14:10 codediebere

sure, that is why I marked it as a good first issue ^^

FYI, to communicate this to other contributors, you can @rustbot claim

CommanderStorm avatar Oct 01 '26 15:10 CommanderStorm

Alright.. Thank you!

codediebere avatar Oct 01 '26 16:10 codediebere

@rustbot claim

codediebere avatar Oct 01 '26 16:10 codediebere

@rustbot claim

jny0444 avatar Oct 14 '26 02:10 jny0444