Skip to content

Commit cbebfb2

Browse files
tests: fix some changes for rustc-ap update
1 parent e3e04af commit cbebfb2

File tree

8 files changed

+71
-63
lines changed

8 files changed

+71
-63
lines changed

rustfmt-core/rustfmt-lib/src/items.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::cmp::{max, min, Ordering};
55

66
use regex::Regex;
77
use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol};
8-
use rustc_target::spec::abi;
98
use syntax::visit;
109
use syntax::{ast, ptr};
1110

rustfmt-core/rustfmt-lib/src/macros.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl Rewrite for MacroArg {
8181
MacroArg::Ty(ref ty) => ty.rewrite(context, shape),
8282
MacroArg::Pat(ref pat) => pat.rewrite(context, shape),
8383
MacroArg::Item(ref item) => item.rewrite(context, shape),
84-
MacroArg::Keyword(ident, _) => Some(ident.to_string()),
84+
MacroArg::Keyword(ident, _) => Some(ident.name.to_string()),
8585
}
8686
}
8787
}
@@ -264,8 +264,8 @@ fn rewrite_macro_inner(
264264

265265
let ts: TokenStream = match *mac.args {
266266
ast::MacArgs::Empty => TokenStream::default(),
267-
ast::MacArgs::Delimited(_, _, token_stream) => token_stream,
268-
ast::MacArgs::Eq(_, token_stream) => token_stream,
267+
ast::MacArgs::Delimited(_, _, ref token_stream) => token_stream.clone(),
268+
ast::MacArgs::Eq(_, ref token_stream) => token_stream.clone(),
269269
};
270270

271271
let has_comment = contains_comment(context.snippet(mac.span()));
@@ -493,8 +493,8 @@ pub(crate) fn rewrite_macro_def(
493493
}
494494
let ts: TokenStream = match *def.body {
495495
ast::MacArgs::Empty => TokenStream::default(),
496-
ast::MacArgs::Delimited(_, _, token_stream) => token_stream,
497-
ast::MacArgs::Eq(_, token_stream) => token_stream,
496+
ast::MacArgs::Delimited(_, _, ref token_stream) => token_stream.clone(),
497+
ast::MacArgs::Eq(_, ref token_stream) => token_stream.clone(),
498498
};
499499
let mut parser = MacroParser::new(ts.into_trees());
500500
let parsed_def = match parser.parse() {
@@ -1203,8 +1203,8 @@ pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> O
12031203
if path == "try" || path == "r#try" {
12041204
let ts: TokenStream = match *mac.args {
12051205
ast::MacArgs::Empty => TokenStream::default(),
1206-
ast::MacArgs::Delimited(_, _, token_stream) => token_stream,
1207-
ast::MacArgs::Eq(_, token_stream) => token_stream,
1206+
ast::MacArgs::Delimited(_, _, ref token_stream) => token_stream.clone(),
1207+
ast::MacArgs::Eq(_, ref token_stream) => token_stream.clone(),
12081208
};
12091209
let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect());
12101210

rustfmt-core/rustfmt-lib/src/patterns.rs

+23-18
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,29 @@ impl Rewrite for Pat {
180180
}
181181
}
182182
PatKind::Range(ref lhs, ref rhs, ref end_kind) => {
183-
let infix = match end_kind.node {
184-
RangeEnd::Included(RangeSyntax::DotDotDot) => "...",
185-
RangeEnd::Included(RangeSyntax::DotDotEq) => "..=",
186-
RangeEnd::Excluded => "..",
187-
};
188-
let infix = if context.config.spaces_around_ranges() {
189-
format!(" {} ", infix)
190-
} else {
191-
infix.to_owned()
192-
};
193-
rewrite_pair(
194-
&lhs.unwrap(),
195-
&rhs.unwrap(),
196-
PairParts::infix(&infix),
197-
context,
198-
shape,
199-
SeparatorPlace::Front,
200-
)
183+
match (lhs, rhs) {
184+
(Some(lhs), Some(rhs)) => {
185+
let infix = match end_kind.node {
186+
RangeEnd::Included(RangeSyntax::DotDotDot) => "...",
187+
RangeEnd::Included(RangeSyntax::DotDotEq) => "..=",
188+
RangeEnd::Excluded => "..",
189+
};
190+
let infix = if context.config.spaces_around_ranges() {
191+
format!(" {} ", infix)
192+
} else {
193+
infix.to_owned()
194+
};
195+
rewrite_pair(
196+
&**lhs,
197+
&**rhs,
198+
PairParts::infix(&infix),
199+
context,
200+
shape,
201+
SeparatorPlace::Front,
202+
)
203+
}
204+
(_, _) => unimplemented!(),
205+
}
201206
}
202207
PatKind::Ref(ref pat, mutability) => {
203208
let prefix = format!("&{}", format_mutability(mutability));

rustfmt-core/rustfmt-lib/src/skip.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ impl SkipContext {
2929
}
3030
}
3131
for attr in attrs {
32-
if is_skip_attr_with(&attr.get_normal_item().path.segments, |s| s == sym!(macros)) {
33-
get_skip_names(&mut self.macros, attr)
34-
} else if is_skip_attr_with(&attr.get_normal_item().path.segments, |s| s == sym::attributes) {
35-
get_skip_names(&mut self.attributes, attr)
32+
match &attr.kind {
33+
syntax::ast::AttrKind::Normal(ref attr_item) => {
34+
if is_skip_attr_with(&attr_item.path.segments, |s| s == sym!(macros)) {
35+
get_skip_names(&mut self.macros, attr)
36+
} else if is_skip_attr_with(&attr_item.path.segments, |s| s == sym::attributes) {
37+
get_skip_names(&mut self.attributes, attr)
38+
}
39+
}
40+
_ => (),
3641
}
3742
}
3843
}

rustfmt-core/rustfmt-lib/src/syntux/parser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ impl<'a> Parser<'a> {
285285
) -> Result<Vec<ast::Item>, &'static str> {
286286
let token_stream: syntax::tokenstream::TokenStream = match *mac.args {
287287
ast::MacArgs::Empty => syntax::tokenstream::TokenStream::default(),
288-
ast::MacArgs::Delimited(_, _, token_stream) => token_stream,
289-
ast::MacArgs::Eq(_, token_stream) => token_stream,
288+
ast::MacArgs::Delimited(_, _, ref token_stream) => token_stream.clone(),
289+
ast::MacArgs::Eq(_, ref token_stream) => token_stream.clone(),
290290
};
291291
let mut parser = rustc_parse::stream_to_parser_with_base_dir(
292292
sess.inner(),

rustfmt-core/rustfmt-lib/src/syntux/session.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,14 @@ mod tests {
271271
use crate::is_nightly_channel;
272272
use crate::utils::mk_sp;
273273
use std::path::PathBuf;
274-
use rustc_span::{MultiSpan, FileName as SourceMapFileName};
274+
use rustc_span::{DUMMY_SP, MultiSpan, FileName as SourceMapFileName};
275275

276276
struct TestEmitter {
277277
num_emitted_errors: Rc<RefCell<u32>>,
278278
}
279279

280280
impl Emitter for TestEmitter {
281+
fn source_map(&self) -> Option<&Lrc<SourceMap>> { None }
281282
fn emit_diagnostic(&mut self, _db: &Diagnostic) {
282283
*self.num_emitted_errors.borrow_mut() += 1;
283284
}
@@ -291,6 +292,7 @@ mod tests {
291292
children: vec![],
292293
suggestions: vec![],
293294
span: span.unwrap_or_else(MultiSpan::new),
295+
sort_span: DUMMY_SP,
294296
}
295297
}
296298

rustfmt-core/rustfmt-lib/src/utils.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,13 @@ pub(crate) fn format_mutability(mutability: ast::Mutability) -> &'static str {
134134

135135
#[inline]
136136
pub(crate) fn format_extern(ext: ast::Extern, explicit_abi: bool, is_mod: bool) -> Cow<'static, str> {
137-
match (ext, explicit_abi, is_mod) {
138-
(ast::Extern::None, _, false) => Cow::from(""),
139-
(ast::Extern::Implicit, false, _) => Cow::from("extern "),
140-
(ast::Extern::Explicit(abi), _, _) => Cow::from(format!("extern {} ", abi.symbol_unescaped.as_str())),
141-
(_, _, _) => unreachable!(),
142-
}
143-
}
137+
let abi = match ext {
138+
ast::Extern::
139+
None => abi::Abi::Rust,
140+
ast::Extern::Implicit => abi::Abi::C,
141+
ast::Extern::Explicit(abi) => abi::lookup(&abi.symbol_unescaped.as_str()).unwrap_or(abi::Abi::Rust),
142+
};
144143

145-
#[inline]
146-
pub(crate) fn format_abi(abi: abi::Abi, explicit_abi: bool, is_mod: bool) -> Cow<'static, str> {
147144
if abi == abi::Abi::Rust && !is_mod {
148145
Cow::from("")
149146
} else if abi == abi::Abi::C && !explicit_abi {

rustfmt-core/rustfmt-lib/src/visitor.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -513,17 +513,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
513513
Some(&inner_attrs),
514514
)
515515
}
516-
ast::ItemKind::TyAlias(ref ty, ref generics) => {
517-
let rewrite = rewrite_type_alias(
518-
&self.get_context(),
519-
self.block_indent,
520-
item.ident,
521-
ty,
522-
generics,
523-
&item.vis,
524-
);
525-
self.push_rewrite(item.span, rewrite);
526-
}
527516
ast::ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() {
528517
None => {
529518
let rewrite = rewrite_type_alias(
@@ -634,6 +623,12 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
634623
Some(&inner_attrs),
635624
);
636625
}
626+
ast::AssocItemKind::Fn(ref sig, None) => {
627+
let indent = self.block_indent;
628+
let rewrite =
629+
self.rewrite_required_fn(indent, ii.ident, sig, &ii.generics, ii.span);
630+
self.push_rewrite(ii.span, rewrite);
631+
}
637632
ast::AssocItemKind::Const(..) => self.visit_static(&StaticParts::from_impl_item(ii)),
638633
ast::AssocItemKind::TyAlias(ref generic_bounds, ref ty) => {
639634
let rewrite_associated = || {
@@ -782,16 +777,21 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
782777
ErrorKind::DeprecatedAttr,
783778
)],
784779
);
785-
} else if self.is_unknown_rustfmt_attr(&attr.get_normal_item().path.segments) {
786-
let file_name = self.parse_sess.span_to_filename(attr.span);
787-
self.report.append(
788-
file_name,
789-
vec![FormattingError::from_span(
790-
attr.span,
791-
self.parse_sess,
792-
ErrorKind::BadAttr,
793-
)],
794-
);
780+
} else {
781+
match &attr.kind {
782+
ast::AttrKind::Normal(ref attribute_item) if self.is_unknown_rustfmt_attr(&attribute_item.path.segments) => {
783+
let file_name = self.parse_sess.span_to_filename(attr.span);
784+
self.report.append(
785+
file_name,
786+
vec![FormattingError::from_span(
787+
attr.span,
788+
self.parse_sess,
789+
ErrorKind::BadAttr,
790+
)],
791+
);
792+
}
793+
_ => (),
794+
}
795795
}
796796
}
797797
if contains_skip(attrs) {

0 commit comments

Comments
 (0)