use itertools::Itertools;
use rustc_ast::token::{Delimiter, LitKind};
-use rustc_ast::{ast, ptr};
+use rustc_ast::{ast, ptr, token};
use rustc_span::{BytePos, Span};
use crate::chains::rewrite_chain;
choose_separator_tactic(context, expr.span),
None,
),
- ast::ExprKind::Lit(ref l) => {
- if let Some(expr_rw) = rewrite_literal(context, l, shape) {
+ ast::ExprKind::Lit(token_lit) => {
+ if let Some(expr_rw) = rewrite_literal(context, token_lit, expr.span, shape) {
Some(expr_rw)
} else {
- if let LitKind::StrRaw(_) = l.token_lit.kind {
- Some(context.snippet(l.span).trim().into())
+ if let LitKind::StrRaw(_) = token_lit.kind {
+ Some(context.snippet(expr.span).trim().into())
} else {
None
}
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 needs_space_before_range(context: &RewriteContext<'_>, lhs: &ast::Expr) -> bool {
match lhs.kind {
- ast::ExprKind::Lit(ref lit) => match lit.kind {
- ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => {
- context.snippet(lit.span).ends_with('.')
+ ast::ExprKind::Lit(token_lit) => match token_lit.kind {
+ token::LitKind::Float if token_lit.suffix.is_none() => {
+ context.snippet(lhs.span).ends_with('.')
}
_ => false,
},
pub(crate) fn rewrite_literal(
context: &RewriteContext<'_>,
- l: &ast::Lit,
+ token_lit: token::Lit,
+ span: Span,
shape: Shape,
) -> Option<String> {
- match l.kind {
- ast::LitKind::Str(_, ast::StrStyle::Cooked) => rewrite_string_lit(context, l.span, shape),
- ast::LitKind::Int(..) => rewrite_int_lit(context, l, shape),
+ match token_lit.kind {
+ token::LitKind::Str => rewrite_string_lit(context, span, shape),
+ token::LitKind::Integer => rewrite_int_lit(context, token_lit, span, shape),
_ => wrap_str(
- context.snippet(l.span).to_owned(),
+ context.snippet(span).to_owned(),
context.config.max_width(),
shape,
),
)
}
-fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) -> Option<String> {
- let span = lit.span;
- let symbol = lit.token_lit.symbol.as_str();
+fn rewrite_int_lit(
+ context: &RewriteContext<'_>,
+ token_lit: token::Lit,
+ span: Span,
+ shape: Shape,
+) -> Option<String> {
+ let symbol = token_lit.symbol.as_str();
if let Some(symbol_stripped) = symbol.strip_prefix("0x") {
let hex_lit = match context.config.hex_literal_case() {
format!(
"0x{}{}",
hex_lit,
- lit.token_lit
- .suffix
- .map_or(String::new(), |s| s.to_string())
+ token_lit.suffix.map_or(String::new(), |s| s.to_string())
),
context.config.max_width(),
shape,
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],