Skip to content

Commit

Permalink
tests: fix some changes for rustc-ap update
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Jan 16, 2020
1 parent e3e04af commit cbebfb2
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 63 deletions.
1 change: 0 additions & 1 deletion rustfmt-core/rustfmt-lib/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::cmp::{max, min, Ordering};

use regex::Regex;
use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol};
use rustc_target::spec::abi;
use syntax::visit;
use syntax::{ast, ptr};

Expand Down
14 changes: 7 additions & 7 deletions rustfmt-core/rustfmt-lib/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Rewrite for MacroArg {
MacroArg::Ty(ref ty) => ty.rewrite(context, shape),
MacroArg::Pat(ref pat) => pat.rewrite(context, shape),
MacroArg::Item(ref item) => item.rewrite(context, shape),
MacroArg::Keyword(ident, _) => Some(ident.to_string()),
MacroArg::Keyword(ident, _) => Some(ident.name.to_string()),
}
}
}
Expand Down Expand Up @@ -264,8 +264,8 @@ fn rewrite_macro_inner(

let ts: TokenStream = match *mac.args {
ast::MacArgs::Empty => TokenStream::default(),
ast::MacArgs::Delimited(_, _, token_stream) => token_stream,
ast::MacArgs::Eq(_, token_stream) => token_stream,
ast::MacArgs::Delimited(_, _, ref token_stream) => token_stream.clone(),
ast::MacArgs::Eq(_, ref token_stream) => token_stream.clone(),
};

let has_comment = contains_comment(context.snippet(mac.span()));
Expand Down Expand Up @@ -493,8 +493,8 @@ pub(crate) fn rewrite_macro_def(
}
let ts: TokenStream = match *def.body {
ast::MacArgs::Empty => TokenStream::default(),
ast::MacArgs::Delimited(_, _, token_stream) => token_stream,
ast::MacArgs::Eq(_, token_stream) => token_stream,
ast::MacArgs::Delimited(_, _, ref token_stream) => token_stream.clone(),
ast::MacArgs::Eq(_, ref token_stream) => token_stream.clone(),
};
let mut parser = MacroParser::new(ts.into_trees());
let parsed_def = match parser.parse() {
Expand Down Expand Up @@ -1203,8 +1203,8 @@ pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> O
if path == "try" || path == "r#try" {
let ts: TokenStream = match *mac.args {
ast::MacArgs::Empty => TokenStream::default(),
ast::MacArgs::Delimited(_, _, token_stream) => token_stream,
ast::MacArgs::Eq(_, token_stream) => token_stream,
ast::MacArgs::Delimited(_, _, ref token_stream) => token_stream.clone(),
ast::MacArgs::Eq(_, ref token_stream) => token_stream.clone(),
};
let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect());

Expand Down
41 changes: 23 additions & 18 deletions rustfmt-core/rustfmt-lib/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,29 @@ impl Rewrite for Pat {
}
}
PatKind::Range(ref lhs, ref rhs, ref end_kind) => {
let infix = match end_kind.node {
RangeEnd::Included(RangeSyntax::DotDotDot) => "...",
RangeEnd::Included(RangeSyntax::DotDotEq) => "..=",
RangeEnd::Excluded => "..",
};
let infix = if context.config.spaces_around_ranges() {
format!(" {} ", infix)
} else {
infix.to_owned()
};
rewrite_pair(
&lhs.unwrap(),
&rhs.unwrap(),
PairParts::infix(&infix),
context,
shape,
SeparatorPlace::Front,
)
match (lhs, rhs) {
(Some(lhs), Some(rhs)) => {
let infix = match end_kind.node {
RangeEnd::Included(RangeSyntax::DotDotDot) => "...",
RangeEnd::Included(RangeSyntax::DotDotEq) => "..=",
RangeEnd::Excluded => "..",
};
let infix = if context.config.spaces_around_ranges() {
format!(" {} ", infix)
} else {
infix.to_owned()
};
rewrite_pair(
&**lhs,
&**rhs,
PairParts::infix(&infix),
context,
shape,
SeparatorPlace::Front,
)
}
(_, _) => unimplemented!(),
}
}
PatKind::Ref(ref pat, mutability) => {
let prefix = format!("&{}", format_mutability(mutability));
Expand Down
13 changes: 9 additions & 4 deletions rustfmt-core/rustfmt-lib/src/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ impl SkipContext {
}
}
for attr in attrs {
if is_skip_attr_with(&attr.get_normal_item().path.segments, |s| s == sym!(macros)) {
get_skip_names(&mut self.macros, attr)
} else if is_skip_attr_with(&attr.get_normal_item().path.segments, |s| s == sym::attributes) {
get_skip_names(&mut self.attributes, attr)
match &attr.kind {
syntax::ast::AttrKind::Normal(ref attr_item) => {
if is_skip_attr_with(&attr_item.path.segments, |s| s == sym!(macros)) {
get_skip_names(&mut self.macros, attr)
} else if is_skip_attr_with(&attr_item.path.segments, |s| s == sym::attributes) {
get_skip_names(&mut self.attributes, attr)
}
}
_ => (),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions rustfmt-core/rustfmt-lib/src/syntux/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ impl<'a> Parser<'a> {
) -> Result<Vec<ast::Item>, &'static str> {
let token_stream: syntax::tokenstream::TokenStream = match *mac.args {
ast::MacArgs::Empty => syntax::tokenstream::TokenStream::default(),
ast::MacArgs::Delimited(_, _, token_stream) => token_stream,
ast::MacArgs::Eq(_, token_stream) => token_stream,
ast::MacArgs::Delimited(_, _, ref token_stream) => token_stream.clone(),
ast::MacArgs::Eq(_, ref token_stream) => token_stream.clone(),
};
let mut parser = rustc_parse::stream_to_parser_with_base_dir(
sess.inner(),
Expand Down
4 changes: 3 additions & 1 deletion rustfmt-core/rustfmt-lib/src/syntux/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,14 @@ mod tests {
use crate::is_nightly_channel;
use crate::utils::mk_sp;
use std::path::PathBuf;
use rustc_span::{MultiSpan, FileName as SourceMapFileName};
use rustc_span::{DUMMY_SP, MultiSpan, FileName as SourceMapFileName};

struct TestEmitter {
num_emitted_errors: Rc<RefCell<u32>>,
}

impl Emitter for TestEmitter {
fn source_map(&self) -> Option<&Lrc<SourceMap>> { None }
fn emit_diagnostic(&mut self, _db: &Diagnostic) {
*self.num_emitted_errors.borrow_mut() += 1;
}
Expand All @@ -291,6 +292,7 @@ mod tests {
children: vec![],
suggestions: vec![],
span: span.unwrap_or_else(MultiSpan::new),
sort_span: DUMMY_SP,
}
}

Expand Down
15 changes: 6 additions & 9 deletions rustfmt-core/rustfmt-lib/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,13 @@ pub(crate) fn format_mutability(mutability: ast::Mutability) -> &'static str {

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

#[inline]
pub(crate) fn format_abi(abi: abi::Abi, explicit_abi: bool, is_mod: bool) -> Cow<'static, str> {
if abi == abi::Abi::Rust && !is_mod {
Cow::from("")
} else if abi == abi::Abi::C && !explicit_abi {
Expand Down
42 changes: 21 additions & 21 deletions rustfmt-core/rustfmt-lib/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,17 +513,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
Some(&inner_attrs),
)
}
ast::ItemKind::TyAlias(ref ty, ref generics) => {
let rewrite = rewrite_type_alias(
&self.get_context(),
self.block_indent,
item.ident,
ty,
generics,
&item.vis,
);
self.push_rewrite(item.span, rewrite);
}
ast::ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() {
None => {
let rewrite = rewrite_type_alias(
Expand Down Expand Up @@ -634,6 +623,12 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
Some(&inner_attrs),
);
}
ast::AssocItemKind::Fn(ref sig, None) => {
let indent = self.block_indent;
let rewrite =
self.rewrite_required_fn(indent, ii.ident, sig, &ii.generics, ii.span);
self.push_rewrite(ii.span, rewrite);
}
ast::AssocItemKind::Const(..) => self.visit_static(&StaticParts::from_impl_item(ii)),
ast::AssocItemKind::TyAlias(ref generic_bounds, ref ty) => {
let rewrite_associated = || {
Expand Down Expand Up @@ -782,16 +777,21 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
ErrorKind::DeprecatedAttr,
)],
);
} else if self.is_unknown_rustfmt_attr(&attr.get_normal_item().path.segments) {
let file_name = self.parse_sess.span_to_filename(attr.span);
self.report.append(
file_name,
vec![FormattingError::from_span(
attr.span,
self.parse_sess,
ErrorKind::BadAttr,
)],
);
} else {
match &attr.kind {
ast::AttrKind::Normal(ref attribute_item) if self.is_unknown_rustfmt_attr(&attribute_item.path.segments) => {
let file_name = self.parse_sess.span_to_filename(attr.span);
self.report.append(
file_name,
vec![FormattingError::from_span(
attr.span,
self.parse_sess,
ErrorKind::BadAttr,
)],
);
}
_ => (),
}
}
}
if contains_skip(attrs) {
Expand Down

0 comments on commit cbebfb2

Please sign in to comment.