Skip to content

Commit

Permalink
Enable expression fixups in 'derive' mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 8, 2024
1 parent 628e2f7 commit e21a494
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 174 deletions.
9 changes: 7 additions & 2 deletions src/classify.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#[cfg(feature = "full")]
use crate::expr::Expr;
use crate::generics::TypeParamBound;
use crate::path::{Path, PathArguments};
use crate::punctuated::Punctuated;
use crate::ty::{ReturnType, Type};
#[cfg(feature = "full")]
use proc_macro2::{Delimiter, TokenStream, TokenTree};
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 +61,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 +203,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 +256,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 e21a494

Please sign in to comment.