Skip to content

Commit

Permalink
Merge pull request #1704 from dtolnay/fixup
Browse files Browse the repository at this point in the history
Enable expression fixups in "derive" mode
  • Loading branch information
dtolnay authored Jul 8, 2024
2 parents 678dbc2 + f1daf23 commit e664375
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 174 deletions.
14 changes: 12 additions & 2 deletions src/classify.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
#[cfg(feature = "full")]
use crate::expr::Expr;
#[cfg(any(feature = "printing", feature = "full"))]
use crate::generics::TypeParamBound;
#[cfg(any(feature = "printing", feature = "full"))]
use crate::path::{Path, PathArguments};
#[cfg(any(feature = "printing", feature = "full"))]
use crate::punctuated::Punctuated;
#[cfg(any(feature = "printing", feature = "full"))]
use crate::ty::{ReturnType, Type};
#[cfg(feature = "full")]
use proc_macro2::{Delimiter, TokenStream, TokenTree};
#[cfg(any(feature = "printing", feature = "full"))]
use std::ops::ControlFlow;

#[cfg(feature = "full")]
pub(crate) fn requires_semi_to_be_stmt(expr: &Expr) -> bool {
match expr {
Expr::Macro(expr) => !expr.mac.delimiter.is_brace(),
_ => requires_comma_to_be_match_arm(expr),
}
}

#[cfg(feature = "full")]
pub(crate) fn requires_comma_to_be_match_arm(expr: &Expr) -> bool {
match expr {
Expr::If(_)
Expand Down Expand Up @@ -57,7 +66,7 @@ pub(crate) fn requires_comma_to_be_match_arm(expr: &Expr) -> bool {
}
}

#[cfg(feature = "printing")]
#[cfg(all(feature = "printing", feature = "full"))]
pub(crate) fn confusable_with_adjacent_block(mut expr: &Expr) -> bool {
let mut stack = Vec::new();

Expand Down Expand Up @@ -199,7 +208,7 @@ pub(crate) fn trailing_unparameterized_path(mut ty: &Type) -> bool {
}

/// Whether the expression's first token is the label of a loop/block.
#[cfg(feature = "printing")]
#[cfg(all(feature = "printing", feature = "full"))]
pub(crate) fn expr_leading_label(mut expr: &Expr) -> bool {
loop {
match expr {
Expand Down Expand Up @@ -252,6 +261,7 @@ pub(crate) fn expr_leading_label(mut expr: &Expr) -> bool {
}

/// Whether the expression's last token is `}`.
#[cfg(feature = "full")]
pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
loop {
match expr {
Expand Down
Loading

0 comments on commit e664375

Please sign in to comment.