Skip to content

use_small_heuristics = "Max" ignores max_width for macros #6538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
chrisduerr opened this issue Apr 13, 2025 · 0 comments
Open

use_small_heuristics = "Max" ignores max_width for macros #6538

chrisduerr opened this issue Apr 13, 2025 · 0 comments

Comments

@chrisduerr
Copy link
Contributor

Take the following Rust code:

fn main() {
    println!("Hello, world!");
}

macro_rules! trigger {
    (KeyBinding, $key:literal, $location:expr) => {{ BindingKey::Keycode { key: Key::Character($key.into()), location: $location } }};
    (KeyBinding, $key:literal,) => {{ BindingKey::Keycode { key: Key::Character($key.into()), location: KeyLocation::Any } }};
    (KeyBinding, $key:ident, $location:expr) => {{ BindingKey::Keycode { key: Key::Named(NamedKey::$key), location: $location } }};
    (KeyBinding, $key:ident,) => {{ BindingKey::Keycode { key: Key::Named(NamedKey::$key), location: KeyLocation::Any } }};
    (MouseBinding, $base:ident::$button:ident,) => {{ $base::$button }};
}

enum Key {
    Named(NamedKey),
    Character(char),
}

enum NamedKey {}

enum KeyLocation {
    Any,
}

When formatted with the default formatter, this works properly and fixes the overly long lines in the macro.

However when then switching to the following rustfmt.toml:

use_small_heuristics = "Max"
max_width = 100 # Optional, just for clarity

Suddenly the macro match arms are all reformatted to a single line, even though use_small_heuristics = "Max" is supposed to max out at max_width and not just allow infinitely long lines.

I've had this break one of my macros during the 2024 edition migration, so I believe there might be a regression somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant