Skip to content
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

Indentation increases after every format #6259

Closed
tritoke opened this issue Jul 30, 2024 · 6 comments
Closed

Indentation increases after every format #6259

tritoke opened this issue Jul 30, 2024 · 6 comments
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@tritoke
Copy link

tritoke commented Jul 30, 2024

macro_rules! impl_sponge_constructor {
    ($func_name:ident, $xof:ident, $sponge:ident, $example_hash:literal) => {
        #[doc=concat!(
            "Construct a ", stringify!($sponge), " directly from `data`\n",
            "\n",
            "Example:\n",
            "\n",
            ".. code-block:: python\n",
            "\n",
            "   >>> from xoflib import shake128\n",
            "   >>> xof = shake128(b\"bytes to absorb\")\n",
            "   >>> xof.read(16).hex()\n",
            "   '250ef380a0f0c92e9506af9893f640fa'\n",
        )]
        #[pyfunction]
        fn $func_name(data: &Bound<'_, PyAny>) -> PyResult<$sponge> {
            Ok($xof::new(Some(data))?.finalize())
        }
    };
}

Whenever I try to format this code rustfmt indents the strings further and further, after three formats it becomes:

macro_rules! impl_sponge_constructor {
    ($func_name:ident, $xof:ident, $sponge:ident, $example_hash:literal) => {
        #[doc=concat!(
                                    "Construct a ", stringify!($sponge), " directly from `data`\n",
                                    "\n",
                                    "Example:\n",
                                    "\n",
                                    ".. code-block:: python\n",
                                    "\n",
                                    "   >>> from xoflib import shake128\n",
                                    "   >>> xof = shake128(b\"bytes to absorb\")\n",
                                    "   >>> xof.read(16).hex()\n",
                                    "   '250ef380a0f0c92e9506af9893f640fa'\n",
                                )]
        #[pyfunction]
        fn $func_name(data: &Bound<'_, PyAny>) -> PyResult<$sponge> {
            Ok($xof::new(Some(data))?.finalize())
        }
    };
}

Rustfmt version:
rustfmt 1.7.0-stable (0514789 2024-07-21)
installed via rustup
OS: Arch Linux

@tritoke
Copy link
Author

tritoke commented Jul 30, 2024

@kinnison has confirmed that he can reproduce it

@kinnison
Copy link

@kinnison has confirmed that he can reproduce it

For reference, I had rustfmt 1.7.0-stable (9b00956 2024-04-29) on the system I tried on.

@tritoke
Copy link
Author

tritoke commented Jul 30, 2024

Also of note cargo fmt --check claims the code is formatted, but cargo fmt still reformats the code.

@RobinJadoul
Copy link

Can also reproduce on the rust playground (tools -> rustfmt, both stable and nightly)

@calebcartwright calebcartwright added the bug Panic, non-idempotency, invalid code, etc. label Jul 30, 2024
@calebcartwright
Copy link
Member

believe it's a duplicate of #5974

@tritoke
Copy link
Author

tritoke commented Jul 31, 2024

Yeah that looks identical, I'll close this.

@tritoke tritoke closed this as completed Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

4 participants