Questions tagged [rustfmt]

rustfmt is a program used for formatting Rust programs.

22 questions
2
votes
0 answers

Is there a way to prevent formatting of else { trivial expression }

I often have code like if condition { // code that deserves to // be formatted as block } else { None } // or some other trivial expression Now, is there a way to prevent rustfmt from wasting two lines…
Ingo
  • 36,037
  • 5
  • 53
  • 100
1
vote
0 answers

Providing location to Cargo.toml for fmt pre-commit hook

I have repository that has both Python and Rust code inside. In the root of the repository I have .pre-commit-config.yaml with: - repo: https://github.com/doublify/pre-commit-rust rev: master hooks: - id: fmt …
dzieciou
  • 4,049
  • 8
  • 41
  • 85
0
votes
1 answer

How can one make rustfmt allow iterator adapaters on separate lines?

In the rust rust book, the section on improving with iterators demonstrates putting iterator adapaters on a separate line like so: pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> { contents .lines() …
Darkenor
  • 4,349
  • 8
  • 40
  • 67
0
votes
0 answers

Lightweight fustfmt installation in docker

I want to have a docker image with the rustfmt. But I don't want the whole rust tooling to have smaller image. I tried (the same approach worked for gofmt) COPY --from=rust:1.65 /usr/local/cargo/bin/rustfmt /usr/bin/rustfmt but that didn't work…
Nikifor
  • 211
  • 1
  • 4
0
votes
0 answers

rustfmt adds braces for lazy_static `pub static ref`, rustc "unnecessary braces around block return value"

tl;dr how do I instruct rustfmt (or cargo fmt) to not add braces around pub static ref declarations? I want fewer rustc warnings. I ran cargo fmt against my code base. The code base uses lazy_static to declare global variables and values. Before: fn…
JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
0
votes
1 answer

How to configure rustfmt in the bazel rule_rust?

I noticed bazel doesn't pick up rustfmt.toml from the project/target folder. What is the way to edit fmt parameters for bazel build?
0
votes
1 answer

Control macro usage formatting in Rustfmt

I want to write a simple call to assert! like this assert!(idents.len() == 1, "Multi-part table references not supported"); But this keeps getting formatted to: assert!( idents.len() == 1, "Multi-part table…
1
2