Skip to content

Commit

Permalink
update macro rewrite functions to return RewriteResult
Browse files Browse the repository at this point in the history
  • Loading branch information
ding-young authored and ytmimi committed Aug 25, 2024
1 parent 4489061 commit 6f5e99b
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 110 deletions.
17 changes: 10 additions & 7 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,16 @@ pub(crate) fn format_expr(
| ast::ExprKind::MethodCall(..)
| ast::ExprKind::Await(_, _) => rewrite_chain(expr, context, shape).ok(),
ast::ExprKind::MacCall(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
wrap_str(
context.snippet(expr.span).to_owned(),
context.config.max_width(),
shape,
)
})
rewrite_macro(mac, None, context, shape, MacroPosition::Expression)
.or_else(|_| {
wrap_str(
context.snippet(expr.span).to_owned(),
context.config.max_width(),
shape,
)
.max_width_error(shape.width, expr.span)
})
.ok()
}
ast::ExprKind::Ret(None) => Some("return".to_owned()),
ast::ExprKind::Ret(Some(ref expr)) => {
Expand Down
2 changes: 1 addition & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3427,7 +3427,7 @@ impl Rewrite for ast::ForeignItem {
rewrite_type_alias(ty_alias, context, shape.indent, kind, span)
}
ast::ForeignItemKind::MacCall(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Item)
rewrite_macro(mac, None, context, shape, MacroPosition::Item).ok()
}
}?;

Expand Down
Loading

0 comments on commit 6f5e99b

Please sign in to comment.