fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
Some(match self.kind {
ast::MetaItemKind::Word => {
- rewrite_path(context, PathContext::Type, None, &self.path, shape)?
+ rewrite_path(context, PathContext::Type, &None, &self.path, shape)?
}
ast::MetaItemKind::List(ref list) => {
- let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
+ let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?;
let has_trailing_comma = crate::expr::span_ends_with_comma(context, self.span);
overflow::rewrite_with_parens(
context,
)?
}
ast::MetaItemKind::NameValue(ref literal) => {
- let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
+ let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?;
// 3 = ` = `
let lit_shape = shape.shrink_left(path.len() + 3)?;
// `rewrite_literal` returns `None` when `literal` exceeds max
fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) {
let (kind, span) = match expr.kind {
- ast::ExprKind::MethodCall(ref segment, ref receiver, ref expressions, _) => {
- let types = if let Some(ref generic_args) = segment.args {
+ ast::ExprKind::MethodCall(ref call) => {
+ let types = if let Some(ref generic_args) = call.seg.args {
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
data.args
.iter()
} else {
vec![]
};
- let span = mk_sp(receiver.span.hi(), expr.span.hi());
- let kind = ChainItemKind::MethodCall(segment.clone(), types, expressions.clone());
+ let span = mk_sp(call.receiver.span.hi(), expr.span.hi());
+ let kind = ChainItemKind::MethodCall(call.seg.clone(), types, call.args.clone());
(kind, span)
}
ast::ExprKind::Field(ref nested, field) => {
// is a try! macro, we'll convert it to shorthand when the option is set.
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
match expr.kind {
- ast::ExprKind::MethodCall(_, ref receiver, _, _) => {
- Some(Self::convert_try(&receiver, context))
- }
+ ast::ExprKind::MethodCall(ref call) => Some(Self::convert_try(&call.receiver, context)),
ast::ExprKind::Field(ref subexpr, _)
| ast::ExprKind::Try(ref subexpr)
| ast::ExprKind::Await(ref subexpr) => Some(Self::convert_try(subexpr, context)),
expr: &ast::Expr,
shape: Shape,
) -> Option<String> {
- if let ast::ExprKind::Closure(
- ref binder,
- capture,
- ref is_async,
- movability,
- ref fn_decl,
- ref body,
- _,
- ) = expr.kind
- {
+ if let ast::ExprKind::Closure(ref closure) = expr.kind {
+ let ast::Closure {
+ ref binder,
+ capture_clause,
+ ref asyncness,
+ movability,
+ ref fn_decl,
+ ref body,
+ fn_decl_span: _,
+ } = **closure;
let body = match body.kind {
ast::ExprKind::Block(ref block, _)
if !is_unsafe_block(block)
_ => body,
};
let (prefix, extra_offset) = rewrite_closure_fn_decl(
- binder, capture, is_async, movability, fn_decl, body, expr.span, context, shape,
+ binder,
+ capture_clause,
+ asyncness,
+ movability,
+ fn_decl,
+ body,
+ expr.span,
+ context,
+ shape,
)?;
// If the closure goes multi line before its body, do not overflow the closure.
if prefix.contains('\n') {
rewrite_struct_lit(
context,
path,
- qself.as_ref(),
+ qself,
fields,
rest,
&expr.attrs,
rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs)
}
ast::ExprKind::Path(ref qself, ref path) => {
- rewrite_path(context, PathContext::Expr, qself.as_ref(), path, shape)
+ rewrite_path(context, PathContext::Expr, qself, path, shape)
}
ast::ExprKind::Assign(ref lhs, ref rhs, _) => {
rewrite_assignment(context, lhs, rhs, None, shape)
Some("yield".to_string())
}
}
- ast::ExprKind::Closure(
- ref binder,
- capture,
- ref is_async,
- movability,
- ref fn_decl,
- ref body,
- _,
- ) => closures::rewrite_closure(
- binder, capture, is_async, movability, fn_decl, body, expr.span, context, shape,
+ ast::ExprKind::Closure(ref cl) => closures::rewrite_closure(
+ &cl.binder,
+ cl.capture_clause,
+ &cl.asyncness,
+ cl.movability,
+ &cl.fn_decl,
+ &cl.body,
+ expr.span,
+ context,
+ shape,
),
ast::ExprKind::Try(..)
| ast::ExprKind::Field(..)
fn rewrite_struct_lit<'a>(
context: &RewriteContext<'_>,
path: &ast::Path,
- qself: Option<&ast::QSelf>,
+ qself: &Option<ptr::P<ast::QSelf>>,
fields: &'a [ast::ExprField],
struct_rest: &ast::StructRest,
attrs: &[ast::Attribute],
}
PatKind::Tuple(ref items) => rewrite_tuple_pat(items, None, self.span, context, shape),
PatKind::Path(ref q_self, ref path) => {
- rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape)
+ rewrite_path(context, PathContext::Expr, q_self, path, shape)
}
PatKind::TupleStruct(ref q_self, ref path, ref pat_vec) => {
- let path_str =
- rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape)?;
+ let path_str = rewrite_path(context, PathContext::Expr, q_self, path, shape)?;
rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape)
}
PatKind::Lit(ref expr) => expr.rewrite(context, shape),
}
fn rewrite_struct_pat(
- qself: &Option<ast::QSelf>,
+ qself: &Option<ptr::P<ast::QSelf>>,
path: &ast::Path,
fields: &[ast::PatField],
ellipsis: bool,
) -> Option<String> {
// 2 = ` {`
let path_shape = shape.sub_width(2)?;
- let path_str = rewrite_path(context, PathContext::Expr, qself.as_ref(), path, path_shape)?;
+ let path_str = rewrite_path(context, PathContext::Expr, qself, path, path_shape)?;
if fields.is_empty() && !ellipsis {
return Some(format!("{} {{}}", path_str));
pub(crate) fn rewrite_path(
context: &RewriteContext<'_>,
path_context: PathContext,
- qself: Option<&ast::QSelf>,
+ qself: &Option<ptr::P<ast::QSelf>>,
path: &ast::Path,
shape: Shape,
) -> Option<String> {
- let skip_count = qself.map_or(0, |x| x.position);
+ let skip_count = qself.as_ref().map_or(0, |x| x.position);
let mut result = if path.is_global() && qself.is_none() && path_context != PathContext::Import {
"::".to_owned()
impl Rewrite for ast::TraitRef {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
- rewrite_path(context, PathContext::Type, None, &self.path, shape)
+ rewrite_path(context, PathContext::Type, &None, &self.path, shape)
}
}
rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1)
}
ast::TyKind::Path(ref q_self, ref path) => {
- rewrite_path(context, PathContext::Type, q_self.as_ref(), path, shape)
+ rewrite_path(context, PathContext::Type, q_self, path, shape)
}
ast::TyKind::Array(ref ty, ref repeats) => rewrite_pair(
&**ty,
| ast::ExprKind::Binary(_, _, ref expr)
| ast::ExprKind::Index(_, ref expr)
| ast::ExprKind::Unary(_, ref expr)
- | ast::ExprKind::Closure(_, _, _, _, _, ref expr, _)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Yield(Some(ref expr)) => is_block_expr(context, expr, repr),
+ ast::ExprKind::Closure(ref closure) => is_block_expr(context, &closure.body, repr),
// This can only be a string lit
ast::ExprKind::Lit(_) => {
repr.contains('\n') && trimmed_last_line_width(repr) <= context.config.tab_spaces()