Skip to content

Commit 2244f32

Browse files
authored
Cargo update (#3559)
Update `rustc-ap-*` crates to 486.0.0.
1 parent e6b60a4 commit 2244f32

20 files changed

+396
-298
lines changed

Cargo.lock

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

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ env_logger = "0.6"
4848
getopts = "0.2"
4949
derive-new = "0.5"
5050
cargo_metadata = "0.7"
51-
rustc-ap-rustc_target = "407.0.0"
52-
rustc-ap-syntax = "407.0.0"
53-
rustc-ap-syntax_pos = "407.0.0"
51+
rustc-ap-rustc_target = "486.0.0"
52+
rustc-ap-syntax = "486.0.0"
53+
rustc-ap-syntax_pos = "486.0.0"
5454
failure = "0.1.3"
5555
bytecount = "0.5"
5656
unicode-width = "0.1.5"

src/attr.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use syntax::ast;
44
use syntax::source_map::{BytePos, Span, DUMMY_SP};
5+
use syntax::symbol::sym;
56

67
use self::doc_comment::DocCommentFormatter;
78
use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};
@@ -52,15 +53,15 @@ pub(crate) fn filter_inline_attrs(
5253
}
5354

5455
fn is_derive(attr: &ast::Attribute) -> bool {
55-
attr.check_name("derive")
56+
attr.check_name(sym::derive)
5657
}
5758

5859
/// Returns the arguments of `#[derive(...)]`.
5960
fn get_derive_spans<'a>(attr: &'a ast::Attribute) -> Option<impl Iterator<Item = Span> + 'a> {
6061
attr.meta_item_list().map(|meta_item_list| {
6162
meta_item_list
6263
.into_iter()
63-
.map(|nested_meta_item| nested_meta_item.span)
64+
.map(|nested_meta_item| nested_meta_item.span())
6465
})
6566
}
6667

@@ -189,9 +190,9 @@ fn rewrite_initial_doc_comments(
189190

190191
impl Rewrite for ast::NestedMetaItem {
191192
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
192-
match self.node {
193-
ast::NestedMetaItemKind::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
194-
ast::NestedMetaItemKind::Literal(ref l) => rewrite_literal(context, l, shape),
193+
match self {
194+
ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
195+
ast::NestedMetaItem::Literal(ref l) => rewrite_literal(context, l, shape),
195196
}
196197
}
197198
}
@@ -219,10 +220,10 @@ impl Rewrite for ast::MetaItem {
219220
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
220221
Some(match self.node {
221222
ast::MetaItemKind::Word => {
222-
rewrite_path(context, PathContext::Type, None, &self.ident, shape)?
223+
rewrite_path(context, PathContext::Type, None, &self.path, shape)?
223224
}
224225
ast::MetaItemKind::List(ref list) => {
225-
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
226+
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
226227
let has_trailing_comma = crate::expr::span_ends_with_comma(context, self.span);
227228
overflow::rewrite_with_parens(
228229
context,
@@ -240,7 +241,7 @@ impl Rewrite for ast::MetaItem {
240241
)?
241242
}
242243
ast::MetaItemKind::NameValue(ref literal) => {
243-
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
244+
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
244245
// 3 = ` = `
245246
let lit_shape = shape.shrink_left(path.len() + 3)?;
246247
// `rewrite_literal` returns `None` when `literal` exceeds max
@@ -326,15 +327,16 @@ impl Rewrite for ast::Attribute {
326327

327328
if let Some(ref meta) = self.meta() {
328329
// This attribute is possibly a doc attribute needing normalization to a doc comment
329-
if context.config.normalize_doc_attributes() && meta.check_name("doc") {
330+
if context.config.normalize_doc_attributes() && meta.check_name(sym::doc) {
330331
if let Some(ref literal) = meta.value_str() {
331332
let comment_style = match self.style {
332333
ast::AttrStyle::Inner => CommentStyle::Doc,
333334
ast::AttrStyle::Outer => CommentStyle::TripleSlash,
334335
};
335336

337+
let literal_str = literal.as_str();
336338
let doc_comment_formatter =
337-
DocCommentFormatter::new(literal.as_str().get(), comment_style);
339+
DocCommentFormatter::new(literal_str.get(), comment_style);
338340
let doc_comment = format!("{}", doc_comment_formatter);
339341
return rewrite_doc_comment(
340342
&doc_comment,

src/chains.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ enum ChainItemKind {
118118
),
119119
StructField(ast::Ident),
120120
TupleField(ast::Ident, bool),
121+
Await,
121122
Comment(String, CommentPosition),
122123
}
123124

@@ -128,6 +129,7 @@ impl ChainItemKind {
128129
ChainItemKind::MethodCall(..)
129130
| ChainItemKind::StructField(..)
130131
| ChainItemKind::TupleField(..)
132+
| ChainItemKind::Await
131133
| ChainItemKind::Comment(..) => false,
132134
}
133135
}
@@ -166,6 +168,10 @@ impl ChainItemKind {
166168
let span = mk_sp(nested.span.hi(), field.span.hi());
167169
(kind, span)
168170
}
171+
ast::ExprKind::Await(_, ref nested) => {
172+
let span = mk_sp(nested.span.hi(), expr.span.hi());
173+
(ChainItemKind::Await, span)
174+
}
169175
_ => return (ChainItemKind::Parent(expr.clone()), expr.span),
170176
};
171177

@@ -189,6 +195,7 @@ impl Rewrite for ChainItem {
189195
if nested { " " } else { "" },
190196
rewrite_ident(context, ident)
191197
),
198+
ChainItemKind::Await => ".await".to_owned(),
192199
ChainItemKind::Comment(ref comment, _) => {
193200
rewrite_comment(comment, false, shape, context.config)?
194201
}
@@ -387,9 +394,9 @@ impl Chain {
387394
ast::ExprKind::MethodCall(_, ref expressions) => {
388395
Some(Self::convert_try(&expressions[0], context))
389396
}
390-
ast::ExprKind::Field(ref subexpr, _) | ast::ExprKind::Try(ref subexpr) => {
391-
Some(Self::convert_try(subexpr, context))
392-
}
397+
ast::ExprKind::Field(ref subexpr, _)
398+
| ast::ExprKind::Try(ref subexpr)
399+
| ast::ExprKind::Await(_, ref subexpr) => Some(Self::convert_try(subexpr, context)),
393400
_ => None,
394401
}
395402
}

src/closures.rs

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use syntax::parse::classify;
21
use syntax::source_map::Span;
32
use syntax::{ast, ptr};
43

@@ -25,7 +24,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
2524

2625
pub(crate) fn rewrite_closure(
2726
capture: ast::CaptureBy,
28-
asyncness: ast::IsAsync,
27+
is_async: &ast::IsAsync,
2928
movability: ast::Movability,
3029
fn_decl: &ast::FnDecl,
3130
body: &ast::Expr,
@@ -36,7 +35,7 @@ pub(crate) fn rewrite_closure(
3635
debug!("rewrite_closure {:?}", body);
3736

3837
let (prefix, extra_offset) = rewrite_closure_fn_decl(
39-
capture, asyncness, movability, fn_decl, body, span, context, shape,
38+
capture, is_async, movability, fn_decl, body, span, context, shape,
4039
)?;
4140
// 1 = space between `|...|` and body.
4241
let body_shape = shape.offset_left(extra_offset)?;
@@ -134,7 +133,7 @@ fn rewrite_closure_with_block(
134133
shape: Shape,
135134
) -> Option<String> {
136135
let left_most = left_most_sub_expr(body);
137-
let veto_block = veto_block(body) && !classify::expr_requires_semi_to_be_stmt(left_most);
136+
let veto_block = veto_block(body) && !expr_requires_semi_to_be_stmt(left_most);
138137
if veto_block {
139138
return None;
140139
}
@@ -207,7 +206,7 @@ fn rewrite_closure_block(
207206
// Return type is (prefix, extra_offset)
208207
fn rewrite_closure_fn_decl(
209208
capture: ast::CaptureBy,
210-
asyncness: ast::IsAsync,
209+
asyncness: &ast::IsAsync,
211210
movability: ast::Movability,
212211
fn_decl: &ast::FnDecl,
213212
body: &ast::Expr,
@@ -291,7 +290,7 @@ pub(crate) fn rewrite_last_closure(
291290
expr: &ast::Expr,
292291
shape: Shape,
293292
) -> Option<String> {
294-
if let ast::ExprKind::Closure(capture, asyncness, movability, ref fn_decl, ref body, _) =
293+
if let ast::ExprKind::Closure(capture, ref is_async, movability, ref fn_decl, ref body, _) =
295294
expr.node
296295
{
297296
let body = match body.node {
@@ -305,7 +304,7 @@ pub(crate) fn rewrite_last_closure(
305304
_ => body,
306305
};
307306
let (prefix, extra_offset) = rewrite_closure_fn_decl(
308-
capture, asyncness, movability, fn_decl, body, expr.span, context, shape,
307+
capture, is_async, movability, fn_decl, body, expr.span, context, shape,
309308
)?;
310309
// If the closure goes multi line before its body, do not overflow the closure.
311310
if prefix.contains('\n') {
@@ -387,3 +386,26 @@ fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool {
387386
_ => false,
388387
}
389388
}
389+
390+
/// Does this expression require a semicolon to be treated
391+
/// as a statement? The negation of this: 'can this expression
392+
/// be used as a statement without a semicolon' -- is used
393+
/// as an early-bail-out in the parser so that, for instance,
394+
/// if true {...} else {...}
395+
/// |x| 5
396+
/// isn't parsed as (if true {...} else {...} | x) | 5
397+
// From https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/classify.rs.
398+
fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
399+
match e.node {
400+
ast::ExprKind::If(..)
401+
| ast::ExprKind::IfLet(..)
402+
| ast::ExprKind::Match(..)
403+
| ast::ExprKind::Block(..)
404+
| ast::ExprKind::While(..)
405+
| ast::ExprKind::WhileLet(..)
406+
| ast::ExprKind::Loop(..)
407+
| ast::ExprKind::ForLoop(..)
408+
| ast::ExprKind::TryBlock(..) => false,
409+
_ => true,
410+
}
411+
}

src/expr.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::borrow::Cow;
22
use std::cmp::min;
3+
use std::iter;
34

45
use itertools::Itertools;
56
use syntax::parse::token::DelimToken;
@@ -183,9 +184,9 @@ pub(crate) fn format_expr(
183184
Some("yield".to_string())
184185
}
185186
}
186-
ast::ExprKind::Closure(capture, asyncness, movability, ref fn_decl, ref body, _) => {
187+
ast::ExprKind::Closure(capture, ref is_async, movability, ref fn_decl, ref body, _) => {
187188
closures::rewrite_closure(
188-
capture, asyncness, movability, fn_decl, body, expr.span, context, shape,
189+
capture, is_async, movability, fn_decl, body, expr.span, context, shape,
189190
)
190191
}
191192
ast::ExprKind::Try(..) | ast::ExprKind::Field(..) | ast::ExprKind::MethodCall(..) => {
@@ -335,10 +336,6 @@ pub(crate) fn format_expr(
335336
))
336337
}
337338
}
338-
ast::ExprKind::ObsoleteInPlace(ref lhs, ref rhs) => lhs
339-
.rewrite(context, shape)
340-
.map(|s| s + " <-")
341-
.and_then(|lhs| rewrite_assign_rhs(context, lhs, &**rhs, shape)),
342339
ast::ExprKind::Async(capture_by, _node_id, ref block) => {
343340
let mover = if capture_by == ast::CaptureBy::Value {
344341
"move "
@@ -371,6 +368,18 @@ pub(crate) fn format_expr(
371368
))
372369
}
373370
}
371+
ast::ExprKind::Await(ast::AwaitOrigin::FieldLike, _) => rewrite_chain(expr, context, shape),
372+
ast::ExprKind::Await(ast::AwaitOrigin::MacroLike, ref nested) => {
373+
overflow::rewrite_with_parens(
374+
context,
375+
"await!",
376+
iter::once(nested),
377+
shape,
378+
expr.span,
379+
context.config.max_width(),
380+
None,
381+
)
382+
}
374383
ast::ExprKind::Err => None,
375384
};
376385

src/formatting.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ impl<'b, T: Write + 'b> Session<'b, T> {
3333
return Err(ErrorKind::VersionMismatch);
3434
}
3535

36-
syntax::with_globals(|| {
37-
syntax_pos::hygiene::set_default_edition(
38-
self.config.edition().to_libsyntax_pos_edition(),
39-
);
40-
36+
syntax::with_globals(self.config.edition().to_libsyntax_pos_edition(), || {
4137
if self.config.disable_all_formatting() {
4238
// When the input is from stdin, echo back the input.
4339
if let Input::Text(ref buf) = input {
@@ -687,7 +683,7 @@ fn parse_crate(
687683
struct SilentEmitter;
688684

689685
impl Emitter for SilentEmitter {
690-
fn emit(&mut self, _db: &DiagnosticBuilder<'_>) {}
686+
fn emit_diagnostic(&mut self, _db: &DiagnosticBuilder<'_>) {}
691687
}
692688

693689
fn silent_emitter() -> Box<SilentEmitter> {

src/imports.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fmt;
44

55
use syntax::ast::{self, UseTreeKind};
66
use syntax::source_map::{self, BytePos, Span, DUMMY_SP};
7+
use syntax::symbol::sym;
78

89
use crate::comment::combine_strs_with_missing_comments;
910
use crate::config::lists::*;
@@ -249,7 +250,7 @@ impl UseTree {
249250
match self.attrs {
250251
Some(ref attrs) if !attrs.is_empty() => {
251252
let attr_str = attrs.rewrite(context, shape)?;
252-
let lo = attrs.last().as_ref()?.span().hi();
253+
let lo = attrs.last().as_ref()?.span.hi();
253254
let hi = self.span.lo();
254255
let span = mk_sp(lo, hi);
255256

@@ -395,7 +396,7 @@ impl UseTree {
395396
rewrite_ident(context, path_to_imported_ident(&a.prefix)).to_owned()
396397
};
397398
let alias = rename.and_then(|ident| {
398-
if ident.name == "_" {
399+
if ident.name == sym::underscore_imports {
399400
// for impl-only-use
400401
Some("_".to_owned())
401402
} else if ident == path_to_imported_ident(&a.prefix) {

0 commit comments

Comments
 (0)