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

PatTuple does not add comma for 1-tuple #1553

Closed
jongiddy opened this issue Dec 24, 2023 · 1 comment · Fixed by #1559
Closed

PatTuple does not add comma for 1-tuple #1553

jongiddy opened this issue Dec 24, 2023 · 1 comment · Fixed by #1559
Labels

Comments

@jongiddy
Copy link

ExprTuple adds a comma to a 1-tuple.PatTuple should also do this to avoid being the same as a PatParen.

The last assert in this test should contain a comma:

#[test]
fn test_one_tuple() {
    let expr_path = ExprPath {
        attrs: Vec::new(),
        qself: None,
        path: Path {
            leading_colon: None,
            segments: [PathSegment {
                ident: Ident::new("a", Span::call_site()),
                arguments: PathArguments::None,
            }].into_iter().collect(),
        },
    };

    let mut expr = ExprTuple {
        attrs: Vec::new(),
        paren_token: token::Paren::default(),
        elems: Punctuated::new(),
    };
    expr.elems.push(Expr::Path(expr_path.clone()));
    assert_eq!(expr.to_token_stream().to_string(), "(a ,)");

    let mut pat = PatTuple {
        attrs: Vec::new(),
        paren_token: token::Paren::default(),
        elems: Punctuated::new(),
    };
    pat.elems.push(Pat::Path(expr_path));
    assert_eq!(pat.to_token_stream().to_string(), "(a)");
}
@jongiddy jongiddy changed the title PatTuple doe not add comma for 1-tuple PatTuple does not add comma for 1-tuple Dec 24, 2023
@dtolnay dtolnay added the bug label Dec 25, 2023
@dtolnay
Copy link
Owner

dtolnay commented Dec 25, 2023

Good catch! I have published a fix in syn 2.0.43.

jongiddy added a commit to jongiddy/typle that referenced this issue Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants