Skip to content

Errantly formatting multiline macro #6233

Open
@fpdotmonkey

Description

@fpdotmonkey

I have this macro call here that is formatted by rustfmt as so.

$ rustfmt --check godot-macros/src/class/data_models/field_export.rs
Diff in /home/fp/3rd/gdext/godot-macros/src/class/data_models/field_export.rs at line 402:
                 }?;
                 let deprecation_warning = if *radians {
                     quote! {
-			#export_func;
-			::godot::__deprecated::emit_deprecated_warning!(export_range_radians);
-                    }
+                    #export_func;
+                    ::godot::__deprecated::emit_deprecated_warning!(export_range_radians);
+                            }
                 } else {
                     quote! { #export_func }
                 };
$ rustfmt --version
rustfmt 1.7.0-stable (129f3b9 2024-06-10)

You can see here that rustfmt wants to un-indent the macro contents and double indent the end bracket for some reason.

Here's aa MCVE for this issue. The important details are that the innermost expressions are within a curly bracket-delimited macro, which itself is within 3 levels of scope.

// correct formatting
fn bar() {
    {
        {
            foo! {
		export_func;
                warning;
            }
        }
    }
}
// rustfmt output
fn bar() {
    {
        {
            foo! {
            export_func;
                    warning;
                }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions