Search code examples
rustrustfmt

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 references not supported"
        );

But I don't really like this particular formatting behavior; I'd like it to stay on one line. I tried setting the fn_call_width in my rustfmt.toml file to a higher number, but that didn't help. Note that my max_width is still the default value (100).

Does anybody know if there is a config I can set in the rustfmt.toml that can get me the desired behavior?


Solution

  • Ahh, I just realized that changing the width settings, like fn_call_width won't change anything if use_small_heuristics is set to "Default" (which it is by default). I have to either do use_small_heuristics = "Off", or I have to increase my max_width (which rustfmt uses to compute settings like fn_call_width when use_small_heuristics = "Default").