Skip to content

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Jun 13, 2025

Previously, a syntax tree node like this:

Expr::Binary {
    attrs: [
        Attribute {
            style: AttrStyle::Outer,
            meta: Meta::Path [
                PathSegment {
                    ident: "attr",
                    arguments: PathArguments::None,
                },
            ],
        },
    ],
    left: Expr::Lit {
        attrs: [],
        lit: Lit::Int { 1 },
    },
    op: BinOp::Add,
    right: Expr::Lit {
        attrs: [],
        lit: Lit::Int { 1 },
    },
}

would render as #[attr] 1 + 1. That is not correct, because that parses back with the attribute on the first Expr::Lit, instead of on the Expr::Binary. After this PR it will render as #[attr] (1 + 1) which is more correct, at least for things like lint level attributes.

@dtolnay dtolnay merged commit 6f7b0f3 into master Jun 13, 2025
30 checks passed
@dtolnay dtolnay deleted the binaryattr branch June 13, 2025 02:44
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

Successfully merging this pull request may close these issues.

1 participant