Skip to content

Commit

Permalink
Do not parenthesize unnamed tuple struct fields in call
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 29, 2024
1 parent 48d0101 commit 1445ccf
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,16 @@ impl IdentFragment for Member {
}
}

#[cfg(any(feature = "parsing", feature = "printing"))]
impl Member {
pub(crate) fn is_named(&self) -> bool {
match self {
Member::Named(_) => true,
Member::Unnamed(_) => false,
}
}
}

ast_struct! {
/// The index of an unnamed tuple struct field.
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
Expand Down Expand Up @@ -3021,15 +3031,6 @@ pub(crate) mod parsing {
Ok(!trailing_dot)
}

impl Member {
pub(crate) fn is_named(&self) -> bool {
match self {
Member::Named(_) => true,
Member::Unnamed(_) => false,
}
}
}

#[cfg(feature = "full")]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for PointerMutability {
Expand Down Expand Up @@ -3410,8 +3411,8 @@ pub(crate) mod printing {
true,
false,
);
let needs_group = if let Expr::Field(_) = &*e.func {
true
let needs_group = if let Expr::Field(func) = &*e.func {
func.member.is_named()
} else {
func_fixup.leading_precedence(&e.func) < Precedence::Unambiguous
};
Expand Down

0 comments on commit 1445ccf

Please sign in to comment.