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

Rustfmt refuses to format this block of Rust. #6527

Closed
Qix- opened this issue Mar 30, 2025 · 1 comment
Closed

Rustfmt refuses to format this block of Rust. #6527

Qix- opened this issue Mar 30, 2025 · 1 comment

Comments

@Qix-
Copy link

Qix- commented Mar 30, 2025

For some reason, rustfmt won't touch this code.

fn basic_placeholder() {
    let eq =
        stmt.content_eq(
            :: oxc_quote :: private :: Vec ::
from_array_in([stmt.into(), :: oxc_quote :: private :: Statement ::
VariableDeclaration(:: oxc_quote :: private :: Box ::
new_in(:: oxc_quote :: private :: VariableDeclaration
{
    span : span, kind : :: oxc_quote :: private :: VariableDeclarationKind ::
    Var, declarations : :: oxc_quote :: private :: Vec ::
    from_array_in([:: oxc_quote :: private :: VariableDeclarator
    {
        span : span, kind : :: oxc_quote :: private :: VariableDeclarationKind
        :: Var, id : :: oxc_quote :: private :: BindingPattern
        {
            kind : :: oxc_quote :: private :: BindingPatternKind ::
            BindingIdentifier(:: oxc_quote :: private :: Box ::
            new_in(:: oxc_quote :: private :: BindingIdentifier
            {
                span : span, name : :: oxc_quote :: private :: Atom ::
                from("bar"), symbol_id : :: std :: cell :: Cell :: new(None),
            }, & a)), type_annotation : :: std :: option :: Option :: None,
            optional : false,
        }, init : :: std :: option :: Option ::
        Some(:: oxc_quote :: private :: Expression ::
        BinaryExpression(:: oxc_quote :: private :: Box ::
        new_in(:: oxc_quote :: private :: BinaryExpression
        {
            span : span, left : :: oxc_quote :: private :: Expression ::
            Identifier(:: oxc_quote :: private :: Box ::
            new_in(:: oxc_quote :: private :: IdentifierReference
            {
                span : span, name : :: oxc_quote :: private :: Atom ::
                from("foo"), reference_id : :: std :: cell :: Cell ::
                new(None),
            }, & a)), operator : :: oxc_quote :: private :: BinaryOperator ::
            Multiplication, right : :: oxc_quote :: private :: Expression ::
            NumericLiteral(:: oxc_quote :: private :: Box ::
            new_in(:: oxc_quote :: private :: NumericLiteral
            {
                span : span, value : 2f64, raw : :: std :: option :: Option ::
                Some(:: oxc_quote :: private :: Atom :: from("2")), base : ::
                oxc_quote :: private :: NumberBase :: Decimal,
            }, & a)),
        }, & a))), definite : false,
    },], & a), declare : false,
}, & a)),], & a))
    ;
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=14f6ff72d26385355b3f2277bf064107

I'm aware it's hairy (it's generated), but at least it should format it somewhat nicely.

First noticed via the CLI via cargo fmt --all and confirmed in the playground.

If I remove all of the :: oxc_quote :: private :: stuff, it formats fine.

@ytmimi
Copy link
Contributor

ytmimi commented Mar 30, 2025

This is a duplicate of #3863.

rustfmt typically doesn't handle generated code very well because it can be very nested. If you'd like rustfmt to try and format this you could try bumping the max_width to some sufficiently large value.

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

No branches or pull requests

2 participants