Skip to content

Commit 5ca3d02

Browse files
authored
Merge pull request #4100 from calebcartwright/rustfmt1x-rustc-v650
bump rustfmt 1x to rustc-ap v651
2 parents 9f53665 + 9714a14 commit 5ca3d02

39 files changed

+1455
-1117
lines changed

Cargo.lock

+175-112
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+16-14
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,45 @@ ignore = "0.4.11"
5656
annotate-snippets = { version = "0.6", features = ["ansi_term"] }
5757
structopt = "0.3"
5858
rustfmt-config_proc_macro = { version = "0.2", path = "config_proc_macro" }
59+
lazy_static = "1.0.0"
5960

6061
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
6162
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
6263
# for more information.
6364
rustc-workspace-hack = "1.0.0"
6465

66+
[dependencies.rustc_ast]
67+
package = "rustc-ap-rustc_ast"
68+
version = "651.0.0"
69+
6570
[dependencies.rustc_ast_pretty]
6671
package = "rustc-ap-rustc_ast_pretty"
67-
version = "642.0.0"
72+
version = "651.0.0"
6873

6974
[dependencies.rustc_data_structures]
7075
package = "rustc-ap-rustc_data_structures"
71-
version = "642.0.0"
76+
version = "651.0.0"
7277

7378
[dependencies.rustc_errors]
7479
package = "rustc-ap-rustc_errors"
75-
version = "642.0.0"
80+
version = "651.0.0"
81+
82+
[dependencies.rustc_expand]
83+
package = "rustc-ap-rustc_expand"
84+
version = "651.0.0"
7685

7786
[dependencies.rustc_parse]
7887
package = "rustc-ap-rustc_parse"
79-
version = "642.0.0"
88+
version = "651.0.0"
8089

8190
[dependencies.rustc_session]
8291
package = "rustc-ap-rustc_session"
83-
version = "642.0.0"
92+
version = "651.0.0"
8493

8594
[dependencies.rustc_span]
8695
package = "rustc-ap-rustc_span"
87-
version = "642.0.0"
96+
version = "651.0.0"
8897

8998
[dependencies.rustc_target]
9099
package = "rustc-ap-rustc_target"
91-
version = "642.0.0"
92-
93-
[dependencies.syntax]
94-
package = "rustc-ap-syntax"
95-
version = "642.0.0"
96-
97-
[dev-dependencies]
98-
lazy_static = "1.0.0"
100+
version = "651.0.0"

src/attr.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Format attributes and meta items.
22
3+
use rustc_ast::ast;
4+
use rustc_ast::attr::HasAttrs;
35
use rustc_span::{symbol::sym, BytePos, Span, DUMMY_SP};
4-
use syntax::ast;
56

67
use self::doc_comment::DocCommentFormatter;
78
use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};
@@ -19,23 +20,19 @@ mod doc_comment;
1920

2021
/// Returns attributes on the given statement.
2122
pub(crate) fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
22-
match stmt.kind {
23-
ast::StmtKind::Local(ref local) => &local.attrs,
24-
ast::StmtKind::Item(ref item) => &item.attrs,
25-
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => &expr.attrs,
26-
ast::StmtKind::Mac(ref mac) => &mac.2,
27-
}
23+
stmt.attrs()
2824
}
2925

3026
pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
3127
match stmt.kind {
3228
ast::StmtKind::Local(ref local) => local.span,
3329
ast::StmtKind::Item(ref item) => item.span,
3430
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => expr.span,
35-
ast::StmtKind::Mac(ref mac) => {
31+
ast::StmtKind::MacCall(ref mac) => {
3632
let (ref mac, _, _) = **mac;
3733
mac.span()
3834
}
35+
ast::StmtKind::Empty => stmt.span,
3936
}
4037
}
4138

src/chains.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
use std::borrow::Cow;
5959
use std::cmp::min;
6060

61+
use rustc_ast::{ast, ptr};
6162
use rustc_span::{BytePos, Span};
62-
use syntax::{ast, ptr};
6363

6464
use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar};
6565
use crate::config::IndentStyle;
@@ -148,7 +148,15 @@ impl ChainItemKind {
148148
ast::ExprKind::MethodCall(ref segment, ref expressions) => {
149149
let types = if let Some(ref generic_args) = segment.args {
150150
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
151-
data.args.clone()
151+
data.args
152+
.iter()
153+
.filter_map(|x| match x {
154+
ast::AngleBracketedArg::Arg(ref generic_arg) => {
155+
Some(generic_arg.clone())
156+
}
157+
_ => None,
158+
})
159+
.collect::<Vec<_>>()
152160
} else {
153161
vec![]
154162
}
@@ -403,7 +411,7 @@ impl Chain {
403411

404412
fn convert_try(expr: &ast::Expr, context: &RewriteContext<'_>) -> ast::Expr {
405413
match expr.kind {
406-
ast::ExprKind::Mac(ref mac) if context.config.use_try_shorthand() => {
414+
ast::ExprKind::MacCall(ref mac) if context.config.use_try_shorthand() => {
407415
if let Some(subexpr) = convert_try_mac(mac, context) {
408416
subexpr
409417
} else {

src/closures.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use rustc_ast::{ast, ptr};
12
use rustc_span::Span;
2-
use syntax::{ast, ptr};
33

44
use crate::attr::get_attrs_from_stmt;
55
use crate::config::lists::*;
@@ -25,7 +25,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
2525

2626
pub(crate) fn rewrite_closure(
2727
capture: ast::CaptureBy,
28-
is_async: &ast::IsAsync,
28+
is_async: &ast::Async,
2929
movability: ast::Movability,
3030
fn_decl: &ast::FnDecl,
3131
body: &ast::Expr,
@@ -43,14 +43,14 @@ pub(crate) fn rewrite_closure(
4343

4444
if let ast::ExprKind::Block(ref block, _) = body.kind {
4545
// The body of the closure is an empty block.
46-
if block.stmts.is_empty() && !block_contains_comment(block, context.source_map) {
46+
if block.stmts.is_empty() && !block_contains_comment(context, block) {
4747
return body
4848
.rewrite(context, shape)
4949
.map(|s| format!("{} {}", prefix, s));
5050
}
5151

5252
let result = match fn_decl.output {
53-
ast::FunctionRetTy::Default(_) if !context.inside_macro() => {
53+
ast::FnRetTy::Default(_) if !context.inside_macro() => {
5454
try_rewrite_without_block(body, &prefix, context, shape, body_shape)
5555
}
5656
_ => None,
@@ -112,7 +112,7 @@ fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext<'_>) -
112112
is_unsafe_block(block)
113113
|| block.stmts.len() > 1
114114
|| has_attributes
115-
|| block_contains_comment(block, context.source_map)
115+
|| block_contains_comment(context, block)
116116
|| prefix.contains('\n')
117117
}
118118

@@ -214,7 +214,7 @@ fn rewrite_closure_block(
214214
// Return type is (prefix, extra_offset)
215215
fn rewrite_closure_fn_decl(
216216
capture: ast::CaptureBy,
217-
asyncness: &ast::IsAsync,
217+
asyncness: &ast::Async,
218218
movability: ast::Movability,
219219
fn_decl: &ast::FnDecl,
220220
body: &ast::Expr,
@@ -305,7 +305,7 @@ pub(crate) fn rewrite_last_closure(
305305
ast::ExprKind::Block(ref block, _)
306306
if !is_unsafe_block(block)
307307
&& !context.inside_macro()
308-
&& is_simple_block(block, Some(&body.attrs), context.source_map) =>
308+
&& is_simple_block(context, block, Some(&body.attrs)) =>
309309
{
310310
stmt_expr(&block.stmts[0]).unwrap_or(body)
311311
}

src/comment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1556,10 +1556,10 @@ pub(crate) fn recover_comment_removed(
15561556
// We missed some comments. Warn and keep the original text.
15571557
if context.config.error_on_unformatted() {
15581558
context.report.append(
1559-
context.source_map.span_to_filename(span).into(),
1559+
context.parse_sess.span_to_filename(span),
15601560
vec![FormattingError::from_span(
15611561
span,
1562-
&context.source_map,
1562+
&context.parse_sess,
15631563
ErrorKind::LostComment,
15641564
)],
15651565
);

src/expr.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::borrow::Cow;
22
use std::cmp::min;
33

44
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};
88

99
use crate::chains::rewrite_chain;
1010
use crate::closures;
@@ -199,7 +199,7 @@ pub(crate) fn format_expr(
199199
ast::ExprKind::Try(..) | ast::ExprKind::Field(..) | ast::ExprKind::MethodCall(..) => {
200200
rewrite_chain(expr, context, shape)
201201
}
202-
ast::ExprKind::Mac(ref mac) => {
202+
ast::ExprKind::MacCall(ref mac) => {
203203
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
204204
wrap_str(
205205
context.snippet(expr.span).to_owned(),
@@ -322,7 +322,7 @@ pub(crate) fn format_expr(
322322
}
323323
// We do not format these expressions yet, but they should still
324324
// 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()),
326326
ast::ExprKind::TryBlock(ref block) => {
327327
if let rw @ Some(_) =
328328
rewrite_single_line_block(context, "try ", block, Some(&expr.attrs), None, shape)
@@ -430,7 +430,7 @@ fn rewrite_empty_block(
430430
return None;
431431
}
432432

433-
if !block_contains_comment(block, context.source_map) && shape.width >= 2 {
433+
if !block_contains_comment(context, block) && shape.width >= 2 {
434434
return Some(format!("{}{}{{}}", prefix, label_str));
435435
}
436436

@@ -487,7 +487,7 @@ fn rewrite_single_line_block(
487487
label: Option<ast::Label>,
488488
shape: Shape,
489489
) -> Option<String> {
490-
if is_simple_block(block, attrs, context.source_map) {
490+
if is_simple_block(context, block, attrs) {
491491
let expr_shape = shape.offset_left(last_line_width(prefix))?;
492492
let expr_str = block.stmts[0].rewrite(context, expr_shape)?;
493493
let label_str = rewrite_label(label);
@@ -750,8 +750,8 @@ impl<'a> ControlFlow<'a> {
750750
let fixed_cost = self.keyword.len() + " { } else { }".len();
751751

752752
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)
755755
|| pat_expr_str.contains('\n')
756756
{
757757
return None;
@@ -1134,47 +1134,46 @@ fn extract_comment(span: Span, context: &RewriteContext<'_>, shape: Shape) -> Op
11341134
}
11351135
}
11361136

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))
11401139
}
11411140

11421141
// Checks that a block contains no statements, an expression and no comments or
11431142
// attributes.
11441143
// FIXME: incorrectly returns false when comment is contained completely within
11451144
// the expression.
11461145
pub(crate) fn is_simple_block(
1146+
context: &RewriteContext<'_>,
11471147
block: &ast::Block,
11481148
attrs: Option<&[ast::Attribute]>,
1149-
source_map: &SourceMap,
11501149
) -> bool {
11511150
block.stmts.len() == 1
11521151
&& stmt_is_expr(&block.stmts[0])
1153-
&& !block_contains_comment(block, source_map)
1152+
&& !block_contains_comment(context, block)
11541153
&& attrs.map_or(true, |a| a.is_empty())
11551154
}
11561155

11571156
/// Checks whether a block contains at most one statement or expression, and no
11581157
/// comments or attributes.
11591158
pub(crate) fn is_simple_block_stmt(
1159+
context: &RewriteContext<'_>,
11601160
block: &ast::Block,
11611161
attrs: Option<&[ast::Attribute]>,
1162-
source_map: &SourceMap,
11631162
) -> bool {
11641163
block.stmts.len() <= 1
1165-
&& !block_contains_comment(block, source_map)
1164+
&& !block_contains_comment(context, block)
11661165
&& attrs.map_or(true, |a| a.is_empty())
11671166
}
11681167

11691168
/// Checks whether a block contains no statements, expressions, comments, or
11701169
/// inner attributes.
11711170
pub(crate) fn is_empty_block(
1171+
context: &RewriteContext<'_>,
11721172
block: &ast::Block,
11731173
attrs: Option<&[ast::Attribute]>,
1174-
source_map: &SourceMap,
11751174
) -> bool {
11761175
block.stmts.is_empty()
1177-
&& !block_contains_comment(block, source_map)
1176+
&& !block_contains_comment(context, block)
11781177
&& attrs.map_or(true, |a| inner_attributes(a).is_empty())
11791178
}
11801179

@@ -1313,9 +1312,9 @@ pub(crate) fn can_be_overflowed_expr(
13131312
context.config.overflow_delimited_expr()
13141313
|| (context.use_block_indent() && args_len == 1)
13151314
}
1316-
ast::ExprKind::Mac(ref mac) => {
1315+
ast::ExprKind::MacCall(ref mac) => {
13171316
match (
1318-
syntax::ast::MacDelimiter::from_token(mac.args.delim()),
1317+
rustc_ast::ast::MacDelimiter::from_token(mac.args.delim()),
13191318
context.config.overflow_delimited_expr(),
13201319
) {
13211320
(Some(ast::MacDelimiter::Bracket), true)
@@ -1341,7 +1340,7 @@ pub(crate) fn can_be_overflowed_expr(
13411340

13421341
pub(crate) fn is_nested_call(expr: &ast::Expr) -> bool {
13431342
match expr.kind {
1344-
ast::ExprKind::Call(..) | ast::ExprKind::Mac(..) => true,
1343+
ast::ExprKind::Call(..) | ast::ExprKind::MacCall(..) => true,
13451344
ast::ExprKind::AddrOf(_, _, ref expr)
13461345
| ast::ExprKind::Box(ref expr)
13471346
| ast::ExprKind::Try(ref expr)

0 commit comments

Comments
 (0)