rust-lang / rust-lang/rustfmt

[BUG] Rustfmt Produces Erroneous Code When Trying To Format Lazy_static Macro Call

Open
#6,013 2 comments 0 reactions 1 assignee View on GitHub

@rscprof is already working on this.

Since Jan 16, 2024.

A-macros C-bug P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Hi,

I found this bug with the lazy_static macro but it probably extends to all other macro calls with parenthesis.

here is the code before the format :

lazy_static!(
    static ref DYNAMODB_CLIENT: Option<aws_sdk_dynamodb::Client> = None;
    static ref CASCADE_IP: String = std::env::var("CASCADE_IP").unwrap_or("127.0.0.1".to_string());
    static ref CASCADE_PORT: String = std::env::var("CASCADE_PORT").unwrap_or("4000".to_string());
);

and after

lazy_static! {
    static ref DYNAMODB_CLIENT: Option<aws_sdk_dynamodb::Client> = None;
    static ref CASCADE_IP: String = std::env::var("CASCADE_IP").unwrap_or("127.0.0.1".to_string());
    static ref CASCADE_PORT: String = std::env::var("CASCADE_PORT").unwrap_or("4000".to_string());
}; // <-- this guy

The trailing semicolon is not removed which cause the code to fail to compile.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.