Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3ca6a06

Browse files
committedMay 22, 2019
Cargo update
Update `rustc-ap-*` crates to 474.0.0.
1 parent 421ed94 commit 3ca6a06

16 files changed

+300
-209
lines changed
 

‎Cargo.lock

Lines changed: 169 additions & 139 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Lines changed: 3 additions & 3 deletions
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 = "474.0.0"
52+
rustc-ap-syntax = "474.0.0"
53+
rustc-ap-syntax_pos = "474.0.0"
5454
failure = "0.1.3"
5555
bytecount = "0.5"
5656
unicode-width = "0.1.5"

‎src/attr.rs

Lines changed: 10 additions & 9 deletions
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 crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};
78
use crate::config::lists::*;
@@ -49,15 +50,15 @@ pub(crate) fn filter_inline_attrs(
4950
}
5051

5152
fn is_derive(attr: &ast::Attribute) -> bool {
52-
attr.check_name("derive")
53+
attr.check_name(sym::derive)
5354
}
5455

5556
/// Returns the arguments of `#[derive(...)]`.
5657
fn get_derive_spans<'a>(attr: &'a ast::Attribute) -> Option<impl Iterator<Item = Span> + 'a> {
5758
attr.meta_item_list().map(|meta_item_list| {
5859
meta_item_list
5960
.into_iter()
60-
.map(|nested_meta_item| nested_meta_item.span)
61+
.map(|nested_meta_item| nested_meta_item.span())
6162
})
6263
}
6364

@@ -186,9 +187,9 @@ fn rewrite_initial_doc_comments(
186187

187188
impl Rewrite for ast::NestedMetaItem {
188189
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
189-
match self.node {
190-
ast::NestedMetaItemKind::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
191-
ast::NestedMetaItemKind::Literal(ref l) => rewrite_literal(context, l, shape),
190+
match self {
191+
ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
192+
ast::NestedMetaItem::Literal(ref l) => rewrite_literal(context, l, shape),
192193
}
193194
}
194195
}
@@ -216,10 +217,10 @@ impl Rewrite for ast::MetaItem {
216217
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
217218
Some(match self.node {
218219
ast::MetaItemKind::Word => {
219-
rewrite_path(context, PathContext::Type, None, &self.ident, shape)?
220+
rewrite_path(context, PathContext::Type, None, &self.path, shape)?
220221
}
221222
ast::MetaItemKind::List(ref list) => {
222-
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
223+
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
223224
let has_trailing_comma = crate::expr::span_ends_with_comma(context, self.span);
224225
overflow::rewrite_with_parens(
225226
context,
@@ -237,7 +238,7 @@ impl Rewrite for ast::MetaItem {
237238
)?
238239
}
239240
ast::MetaItemKind::NameValue(ref literal) => {
240-
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
241+
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
241242
// 3 = ` = `
242243
let lit_shape = shape.shrink_left(path.len() + 3)?;
243244
// `rewrite_literal` returns `None` when `literal` exceeds max
@@ -323,7 +324,7 @@ impl Rewrite for ast::Attribute {
323324

324325
if let Some(ref meta) = self.meta() {
325326
// This attribute is possibly a doc attribute needing normalization to a doc comment
326-
if context.config.normalize_doc_attributes() && meta.check_name("doc") {
327+
if context.config.normalize_doc_attributes() && meta.check_name(sym::doc) {
327328
if let Some(ref literal) = meta.value_str() {
328329
let comment_style = match self.style {
329330
ast::AttrStyle::Inner => CommentStyle::Doc,

‎src/chains.rs

Lines changed: 10 additions & 3 deletions
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

Lines changed: 29 additions & 7 deletions
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

Lines changed: 15 additions & 2 deletions
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;
@@ -182,9 +183,9 @@ pub(crate) fn format_expr(
182183
Some("yield".to_string())
183184
}
184185
}
185-
ast::ExprKind::Closure(capture, asyncness, movability, ref fn_decl, ref body, _) => {
186+
ast::ExprKind::Closure(capture, ref is_async, movability, ref fn_decl, ref body, _) => {
186187
closures::rewrite_closure(
187-
capture, asyncness, movability, fn_decl, body, expr.span, context, shape,
188+
capture, is_async, movability, fn_decl, body, expr.span, context, shape,
188189
)
189190
}
190191
ast::ExprKind::Try(..) | ast::ExprKind::Field(..) | ast::ExprKind::MethodCall(..) => {
@@ -370,6 +371,18 @@ pub(crate) fn format_expr(
370371
))
371372
}
372373
}
374+
ast::ExprKind::Await(ast::AwaitOrigin::FieldLike, _) => rewrite_chain(expr, context, shape),
375+
ast::ExprKind::Await(ast::AwaitOrigin::MacroLike, ref nested) => {
376+
overflow::rewrite_with_parens(
377+
context,
378+
"await!",
379+
iter::once(nested),
380+
shape,
381+
expr.span,
382+
context.config.max_width(),
383+
None,
384+
)
385+
}
373386
ast::ExprKind::Err => None,
374387
};
375388

‎src/formatting.rs

Lines changed: 2 additions & 6 deletions
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

Lines changed: 3 additions & 2 deletions
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) {

‎src/items.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub(crate) struct FnSig<'a> {
161161
decl: &'a ast::FnDecl,
162162
generics: &'a ast::Generics,
163163
abi: abi::Abi,
164-
is_async: ast::IsAsync,
164+
is_async: Cow<'a, ast::IsAsync>,
165165
constness: ast::Constness,
166166
defaultness: ast::Defaultness,
167167
unsafety: ast::Unsafety,
@@ -178,7 +178,7 @@ impl<'a> FnSig<'a> {
178178
decl,
179179
generics,
180180
abi: abi::Abi::Rust,
181-
is_async: ast::IsAsync::NotAsync,
181+
is_async: Cow::Owned(ast::IsAsync::NotAsync),
182182
constness: ast::Constness::NotConst,
183183
defaultness: ast::Defaultness::Final,
184184
unsafety: ast::Unsafety::Normal,
@@ -192,7 +192,7 @@ impl<'a> FnSig<'a> {
192192
) -> FnSig<'a> {
193193
FnSig {
194194
unsafety: method_sig.header.unsafety,
195-
is_async: method_sig.header.asyncness.node,
195+
is_async: Cow::Borrowed(&method_sig.header.asyncness.node),
196196
constness: method_sig.header.constness.node,
197197
defaultness: ast::Defaultness::Final,
198198
abi: method_sig.header.abi,
@@ -214,7 +214,7 @@ impl<'a> FnSig<'a> {
214214
generics,
215215
abi: fn_header.abi,
216216
constness: fn_header.constness.node,
217-
is_async: fn_header.asyncness.node,
217+
is_async: Cow::Borrowed(&fn_header.asyncness.node),
218218
defaultness,
219219
unsafety: fn_header.unsafety,
220220
visibility: visibility.clone(),
@@ -238,7 +238,7 @@ impl<'a> FnSig<'a> {
238238
result.push_str(format_defaultness(self.defaultness));
239239
result.push_str(format_constness(self.constness));
240240
result.push_str(format_unsafety(self.unsafety));
241-
result.push_str(format_async(self.is_async));
241+
result.push_str(format_async(&self.is_async));
242242
result.push_str(&format_abi(
243243
self.abi,
244244
context.config.force_explicit_abi(),
@@ -422,7 +422,10 @@ impl<'a> FmtVisitor<'a> {
422422
}
423423

424424
pub(crate) fn visit_struct(&mut self, struct_parts: &StructParts<'_>) {
425-
let is_tuple = struct_parts.def.is_tuple();
425+
let is_tuple = match struct_parts.def {
426+
ast::VariantData::Tuple(..) => true,
427+
_ => false,
428+
};
426429
let rewrite = format_struct(&self.get_context(), struct_parts, self.block_indent, None)
427430
.map(|s| if is_tuple { s + ";" } else { s });
428431
self.push_rewrite(struct_parts.span, rewrite);
@@ -2819,11 +2822,11 @@ impl Rewrite for ast::ForeignItem {
28192822
false,
28202823
)
28212824
.map(|(s, _)| format!("{};", s)),
2822-
ast::ForeignItemKind::Static(ref ty, is_mutable) => {
2825+
ast::ForeignItemKind::Static(ref ty, mutability) => {
28232826
// FIXME(#21): we're dropping potential comments in between the
28242827
// function keywords here.
28252828
let vis = format_visibility(context, &self.vis);
2826-
let mut_str = if is_mutable { "mut " } else { "" };
2829+
let mut_str = format_mutability(mutability);
28272830
let prefix = format!(
28282831
"{}static {}{}:",
28292832
vis,

‎src/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub(crate) fn rewrite_match(
111111
.snippet_provider
112112
.span_after(mk_sp(cond.span.hi(), hi), "{")
113113
} else {
114-
inner_attrs[inner_attrs.len() - 1].span().hi()
114+
inner_attrs[inner_attrs.len() - 1].span.hi()
115115
};
116116

117117
if arms.is_empty() {

‎src/modules.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use std::path::{Path, PathBuf};
44
use syntax::ast;
55
use syntax::parse::{parser, DirectoryOwnership};
66
use syntax::source_map;
7+
use syntax::symbol::sym;
78
use syntax_pos::symbol::Symbol;
89

910
use crate::config::FileName;
1011
use crate::items::is_mod_decl;
1112
use crate::utils::contains_skip;
1213

13-
type FileModMap<'a> = BTreeMap<FileName, (&'a ast::Mod, &'a str)>;
14+
type FileModMap<'a> = BTreeMap<FileName, (&'a ast::Mod, String)>;
1415

1516
/// Maps each module to the corresponding file.
1617
pub(crate) struct ModResolver<'a, 'b> {
@@ -61,7 +62,7 @@ impl<'a, 'b> ModResolver<'a, 'b> {
6162
}
6263

6364
self.file_map
64-
.insert(root_filename.into(), (&krate.module, ""));
65+
.insert(root_filename.into(), (&krate.module, String::new()));
6566
Ok(self.file_map)
6667
}
6768

@@ -80,7 +81,7 @@ impl<'a, 'b> ModResolver<'a, 'b> {
8081
self.find_external_module(item.ident, &item.attrs)?;
8182
self.file_map.insert(
8283
FileName::Real(mod_path.clone()),
83-
(sub_mod, item.ident.name.as_str().get()),
84+
(sub_mod, item.ident.as_str().get().to_owned()),
8485
);
8586
self.directory = Directory {
8687
path: mod_path.parent().unwrap().to_path_buf(),
@@ -161,7 +162,7 @@ impl<'a, 'b> ModResolver<'a, 'b> {
161162
}
162163

163164
fn path_value(attr: &ast::Attribute) -> Option<Symbol> {
164-
if attr.name() == "path" {
165+
if attr.check_name(sym::path) {
165166
attr.value_str()
166167
} else {
167168
None

‎src/overflow.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ impl<'a> OverflowableItem<'a> {
123123
match self {
124124
OverflowableItem::Expr(expr) => is_simple_expr(expr),
125125
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr),
126-
OverflowableItem::NestedMetaItem(nested_meta_item) => match nested_meta_item.node {
127-
ast::NestedMetaItemKind::Literal(..) => true,
128-
ast::NestedMetaItemKind::MetaItem(ref meta_item) => match meta_item.node {
126+
OverflowableItem::NestedMetaItem(nested_meta_item) => match nested_meta_item {
127+
ast::NestedMetaItem::Literal(..) => true,
128+
ast::NestedMetaItem::MetaItem(ref meta_item) => match meta_item.node {
129129
ast::MetaItemKind::Word => true,
130130
_ => false,
131131
},
@@ -172,9 +172,9 @@ impl<'a> OverflowableItem<'a> {
172172
MacroArg::Keyword(..) => false,
173173
},
174174
OverflowableItem::NestedMetaItem(nested_meta_item) if len == 1 => {
175-
match nested_meta_item.node {
176-
ast::NestedMetaItemKind::Literal(..) => false,
177-
ast::NestedMetaItemKind::MetaItem(..) => true,
175+
match nested_meta_item {
176+
ast::NestedMetaItem::Literal(..) => false,
177+
ast::NestedMetaItem::MetaItem(..) => true,
178178
}
179179
}
180180
OverflowableItem::SegmentParam(seg) => match seg {

‎src/reorder.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use std::cmp::{Ord, Ordering};
1010

11-
use syntax::{ast, attr, source_map::Span};
11+
use syntax::{ast, attr, source_map::Span, symbol::sym};
1212

1313
use crate::attr::filter_inline_attrs;
1414
use crate::comment::combine_strs_with_missing_comments;
@@ -176,7 +176,10 @@ fn rewrite_reorderable_items(
176176
}
177177

178178
fn contains_macro_use_attr(item: &ast::Item) -> bool {
179-
attr::contains_name(&filter_inline_attrs(&item.attrs, item.span()), "macro_use")
179+
attr::contains_name(
180+
&filter_inline_attrs(&item.attrs, item.span()),
181+
sym::macro_use,
182+
)
180183
}
181184

182185
/// A simplified version of `ast::ItemKind`.

‎src/spanned.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,9 @@ impl Spanned for MacroArg {
193193
}
194194
}
195195
}
196+
197+
impl Spanned for ast::NestedMetaItem {
198+
fn span(&self) -> Span {
199+
self.span()
200+
}
201+
}

‎src/utils.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use bytecount;
44

55
use rustc_target::spec::abi;
66
use syntax::ast::{
7-
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind,
8-
NodeId, Path, Visibility, VisibilityKind,
7+
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
8+
VisibilityKind,
99
};
1010
use syntax::ptr;
1111
use syntax::source_map::{BytePos, Span, NO_EXPANSION};
12+
use syntax::symbol::{sym, Symbol};
1213
use syntax_pos::Mark;
1314
use unicode_width::UnicodeWidthStr;
1415

@@ -17,8 +18,15 @@ use crate::config::{Config, Version};
1718
use crate::rewrite::RewriteContext;
1819
use crate::shape::{Indent, Shape};
1920

20-
pub(crate) const DEPR_SKIP_ANNOTATION: &str = "rustfmt_skip";
21-
pub(crate) const SKIP_ANNOTATION: &str = "rustfmt::skip";
21+
#[inline]
22+
pub(crate) fn depr_skip_annotation() -> Symbol {
23+
Symbol::intern("rustfmt_skip")
24+
}
25+
26+
#[inline]
27+
pub(crate) fn skip_annotation() -> Symbol {
28+
Symbol::intern("rustfmt::skip")
29+
}
2230

2331
pub(crate) fn rewrite_ident<'a>(context: &'a RewriteContext<'_>, ident: ast::Ident) -> &'a str {
2432
context.snippet(ident.span)
@@ -81,7 +89,7 @@ pub(crate) fn format_visibility(
8189
}
8290

8391
#[inline]
84-
pub(crate) fn format_async(is_async: ast::IsAsync) -> &'static str {
92+
pub(crate) fn format_async(is_async: &ast::IsAsync) -> &'static str {
8593
match is_async {
8694
ast::IsAsync::Async { .. } => "async ",
8795
ast::IsAsync::NotAsync => "",
@@ -237,21 +245,21 @@ pub(crate) fn last_line_extendable(s: &str) -> bool {
237245
fn is_skip(meta_item: &MetaItem) -> bool {
238246
match meta_item.node {
239247
MetaItemKind::Word => {
240-
let path_str = meta_item.ident.to_string();
241-
path_str == SKIP_ANNOTATION || path_str == DEPR_SKIP_ANNOTATION
248+
let path_str = meta_item.path.to_string();
249+
path_str == skip_annotation().as_str() || path_str == depr_skip_annotation().as_str()
242250
}
243251
MetaItemKind::List(ref l) => {
244-
meta_item.name() == "cfg_attr" && l.len() == 2 && is_skip_nested(&l[1])
252+
meta_item.check_name(sym::cfg_attr) && l.len() == 2 && is_skip_nested(&l[1])
245253
}
246254
_ => false,
247255
}
248256
}
249257

250258
#[inline]
251259
fn is_skip_nested(meta_item: &NestedMetaItem) -> bool {
252-
match meta_item.node {
253-
NestedMetaItemKind::MetaItem(ref mi) => is_skip(mi),
254-
NestedMetaItemKind::Literal(_) => false,
260+
match meta_item {
261+
NestedMetaItem::MetaItem(ref mi) => is_skip(mi),
262+
NestedMetaItem::Literal(_) => false,
255263
}
256264
}
257265

@@ -625,8 +633,8 @@ pub(crate) fn get_skip_macro_names(attrs: &[ast::Attribute]) -> Vec<String> {
625633
}
626634

627635
if let Some(list) = attr.meta_item_list() {
628-
for spanned in list {
629-
if let Some(name) = spanned.name() {
636+
for nested_meta_item in list {
637+
if let Some(name) = nested_meta_item.ident() {
630638
skip_macro_names.push(name.to_string());
631639
}
632640
}

‎src/visitor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::shape::{Indent, Shape};
2121
use crate::source_map::{LineRangeUtils, SpanUtils};
2222
use crate::spanned::Spanned;
2323
use crate::utils::{
24-
self, contains_skip, count_newlines, get_skip_macro_names, inner_attributes, mk_sp,
25-
ptr_vec_to_ref_vec, rewrite_ident, stmt_expr, DEPR_SKIP_ANNOTATION,
24+
self, contains_skip, count_newlines, depr_skip_annotation, get_skip_macro_names,
25+
inner_attributes, mk_sp, ptr_vec_to_ref_vec, rewrite_ident, stmt_expr,
2626
};
2727
use crate::{ErrorKind, FormatReport, FormattingError};
2828

@@ -593,7 +593,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
593593
// do not take into account the lines with attributes as part of the skipped range
594594
let attrs_end = attrs
595595
.iter()
596-
.map(|attr| self.source_map.lookup_char_pos(attr.span().hi()).line)
596+
.map(|attr| self.source_map.lookup_char_pos(attr.span.hi()).line)
597597
.max()
598598
.unwrap_or(1);
599599
let first_line = self.source_map.lookup_char_pos(main_span.lo()).line;
@@ -656,7 +656,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
656656
// Returns true if we should skip the following item.
657657
pub(crate) fn visit_attrs(&mut self, attrs: &[ast::Attribute], style: ast::AttrStyle) -> bool {
658658
for attr in attrs {
659-
if attr.name() == DEPR_SKIP_ANNOTATION {
659+
if attr.check_name(depr_skip_annotation()) {
660660
let file_name = self.source_map.span_to_filename(attr.span).into();
661661
self.report.append(
662662
file_name,

0 commit comments

Comments
 (0)
Please sign in to comment.