@@ -2,9 +2,9 @@ use std::borrow::Cow;
2
2
use std:: cmp:: min;
3
3
4
4
use itertools:: Itertools ;
5
- use rustc_span :: { source_map :: SourceMap , BytePos , Span } ;
6
- use syntax :: token :: { DelimToken , LitKind } ;
7
- use syntax :: { ast , ptr } ;
5
+ use rustc_ast :: token :: { DelimToken , LitKind } ;
6
+ use rustc_ast :: { ast , ptr } ;
7
+ use rustc_span :: { BytePos , Span } ;
8
8
9
9
use crate :: chains:: rewrite_chain;
10
10
use crate :: closures;
@@ -199,7 +199,7 @@ pub(crate) fn format_expr(
199
199
ast:: ExprKind :: Try ( ..) | ast:: ExprKind :: Field ( ..) | ast:: ExprKind :: MethodCall ( ..) => {
200
200
rewrite_chain ( expr, context, shape)
201
201
}
202
- ast:: ExprKind :: Mac ( ref mac) => {
202
+ ast:: ExprKind :: MacCall ( ref mac) => {
203
203
rewrite_macro ( mac, None , context, shape, MacroPosition :: Expression ) . or_else ( || {
204
204
wrap_str (
205
205
context. snippet ( expr. span ) . to_owned ( ) ,
@@ -322,7 +322,7 @@ pub(crate) fn format_expr(
322
322
}
323
323
// We do not format these expressions yet, but they should still
324
324
// satisfy our width restrictions.
325
- ast:: ExprKind :: InlineAsm ( ..) => Some ( context. snippet ( expr. span ) . to_owned ( ) ) ,
325
+ ast:: ExprKind :: LlvmInlineAsm ( ..) => Some ( context. snippet ( expr. span ) . to_owned ( ) ) ,
326
326
ast:: ExprKind :: TryBlock ( ref block) => {
327
327
if let rw @ Some ( _) =
328
328
rewrite_single_line_block ( context, "try " , block, Some ( & expr. attrs ) , None , shape)
@@ -430,7 +430,7 @@ fn rewrite_empty_block(
430
430
return None ;
431
431
}
432
432
433
- if !block_contains_comment ( block , context . source_map ) && shape. width >= 2 {
433
+ if !block_contains_comment ( context , block ) && shape. width >= 2 {
434
434
return Some ( format ! ( "{}{}{{}}" , prefix, label_str) ) ;
435
435
}
436
436
@@ -487,7 +487,7 @@ fn rewrite_single_line_block(
487
487
label : Option < ast:: Label > ,
488
488
shape : Shape ,
489
489
) -> Option < String > {
490
- if is_simple_block ( block , attrs , context . source_map ) {
490
+ if is_simple_block ( context , block , attrs ) {
491
491
let expr_shape = shape. offset_left ( last_line_width ( prefix) ) ?;
492
492
let expr_str = block. stmts [ 0 ] . rewrite ( context, expr_shape) ?;
493
493
let label_str = rewrite_label ( label) ;
@@ -750,8 +750,8 @@ impl<'a> ControlFlow<'a> {
750
750
let fixed_cost = self . keyword . len ( ) + " { } else { }" . len ( ) ;
751
751
752
752
if let ast:: ExprKind :: Block ( ref else_node, _) = else_block. kind {
753
- if !is_simple_block ( self . block , None , context . source_map )
754
- || !is_simple_block ( else_node , None , context . source_map )
753
+ if !is_simple_block ( context , self . block , None )
754
+ || !is_simple_block ( context , else_node , None )
755
755
|| pat_expr_str. contains ( '\n' )
756
756
{
757
757
return None ;
@@ -1134,47 +1134,46 @@ fn extract_comment(span: Span, context: &RewriteContext<'_>, shape: Shape) -> Op
1134
1134
}
1135
1135
}
1136
1136
1137
- pub ( crate ) fn block_contains_comment ( block : & ast:: Block , source_map : & SourceMap ) -> bool {
1138
- let snippet = source_map. span_to_snippet ( block. span ) . unwrap ( ) ;
1139
- contains_comment ( & snippet)
1137
+ pub ( crate ) fn block_contains_comment ( context : & RewriteContext < ' _ > , block : & ast:: Block ) -> bool {
1138
+ contains_comment ( context. snippet ( block. span ) )
1140
1139
}
1141
1140
1142
1141
// Checks that a block contains no statements, an expression and no comments or
1143
1142
// attributes.
1144
1143
// FIXME: incorrectly returns false when comment is contained completely within
1145
1144
// the expression.
1146
1145
pub ( crate ) fn is_simple_block (
1146
+ context : & RewriteContext < ' _ > ,
1147
1147
block : & ast:: Block ,
1148
1148
attrs : Option < & [ ast:: Attribute ] > ,
1149
- source_map : & SourceMap ,
1150
1149
) -> bool {
1151
1150
block. stmts . len ( ) == 1
1152
1151
&& stmt_is_expr ( & block. stmts [ 0 ] )
1153
- && !block_contains_comment ( block , source_map )
1152
+ && !block_contains_comment ( context , block )
1154
1153
&& attrs. map_or ( true , |a| a. is_empty ( ) )
1155
1154
}
1156
1155
1157
1156
/// Checks whether a block contains at most one statement or expression, and no
1158
1157
/// comments or attributes.
1159
1158
pub ( crate ) fn is_simple_block_stmt (
1159
+ context : & RewriteContext < ' _ > ,
1160
1160
block : & ast:: Block ,
1161
1161
attrs : Option < & [ ast:: Attribute ] > ,
1162
- source_map : & SourceMap ,
1163
1162
) -> bool {
1164
1163
block. stmts . len ( ) <= 1
1165
- && !block_contains_comment ( block , source_map )
1164
+ && !block_contains_comment ( context , block )
1166
1165
&& attrs. map_or ( true , |a| a. is_empty ( ) )
1167
1166
}
1168
1167
1169
1168
/// Checks whether a block contains no statements, expressions, comments, or
1170
1169
/// inner attributes.
1171
1170
pub ( crate ) fn is_empty_block (
1171
+ context : & RewriteContext < ' _ > ,
1172
1172
block : & ast:: Block ,
1173
1173
attrs : Option < & [ ast:: Attribute ] > ,
1174
- source_map : & SourceMap ,
1175
1174
) -> bool {
1176
1175
block. stmts . is_empty ( )
1177
- && !block_contains_comment ( block , source_map )
1176
+ && !block_contains_comment ( context , block )
1178
1177
&& attrs. map_or ( true , |a| inner_attributes ( a) . is_empty ( ) )
1179
1178
}
1180
1179
@@ -1313,9 +1312,9 @@ pub(crate) fn can_be_overflowed_expr(
1313
1312
context. config . overflow_delimited_expr ( )
1314
1313
|| ( context. use_block_indent ( ) && args_len == 1 )
1315
1314
}
1316
- ast:: ExprKind :: Mac ( ref mac) => {
1315
+ ast:: ExprKind :: MacCall ( ref mac) => {
1317
1316
match (
1318
- syntax :: ast:: MacDelimiter :: from_token ( mac. args . delim ( ) ) ,
1317
+ rustc_ast :: ast:: MacDelimiter :: from_token ( mac. args . delim ( ) ) ,
1319
1318
context. config . overflow_delimited_expr ( ) ,
1320
1319
) {
1321
1320
( Some ( ast:: MacDelimiter :: Bracket ) , true )
@@ -1341,7 +1340,7 @@ pub(crate) fn can_be_overflowed_expr(
1341
1340
1342
1341
pub ( crate ) fn is_nested_call ( expr : & ast:: Expr ) -> bool {
1343
1342
match expr. kind {
1344
- ast:: ExprKind :: Call ( ..) | ast:: ExprKind :: Mac ( ..) => true ,
1343
+ ast:: ExprKind :: Call ( ..) | ast:: ExprKind :: MacCall ( ..) => true ,
1345
1344
ast:: ExprKind :: AddrOf ( _, _, ref expr)
1346
1345
| ast:: ExprKind :: Box ( ref expr)
1347
1346
| ast:: ExprKind :: Try ( ref expr)
0 commit comments