Format class definitions (#5289)

This commit is contained in:
Micha Reiser 2023-06-22 11:09:43 +02:00 committed by GitHub
parent 7d4f8e59da
commit f7e1cf4b51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 914 additions and 541 deletions

View file

@ -26,6 +26,8 @@ pub(super) fn default_expression_needs_parentheses(
#[allow(clippy::if_same_then_else)]
if parenthesize.is_always() {
Parentheses::Always
} else if parenthesize.is_never() {
Parentheses::Never
}
// `Optional` or `Preserve` and expression has parentheses in source code.
else if !parenthesize.is_if_breaks() && is_expression_parenthesized(node, source) {
@ -58,7 +60,11 @@ pub enum Parenthesize {
/// Parenthesizes the expression only if it doesn't fit on a line.
IfBreaks,
/// Always adds parentheses
Always,
/// Never adds parentheses. Parentheses are handled by the caller.
Never,
}
impl Parenthesize {
@ -66,6 +72,10 @@ impl Parenthesize {
matches!(self, Parenthesize::Always)
}
pub(crate) const fn is_never(self) -> bool {
matches!(self, Parenthesize::Never)
}
pub(crate) const fn is_if_breaks(self) -> bool {
matches!(self, Parenthesize::IfBreaks)
}