Skip to content

Commit

Permalink
rustfmt 1.x bump rustc-ap to v642 (#4043)
Browse files Browse the repository at this point in the history
  • Loading branch information
topecongiro authored Feb 10, 2020
2 parents 1838235 + 760bb29 commit 9f53665
Show file tree
Hide file tree
Showing 34 changed files with 953 additions and 476 deletions.
359 changes: 244 additions & 115 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 28 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "rustfmt-nightly"
version = "1.4.11"
version = "1.4.12"
authors = ["Nicholas Cameron <[email protected]>", "The Rustfmt developers"]
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang/rustfmt"
Expand Down Expand Up @@ -52,7 +52,7 @@ bytecount = "0.6"
unicode-width = "0.1.5"
unicode_categories = "0.1.1"
dirs = "2.0.1"
ignore = "0.4.6"
ignore = "0.4.11"
annotate-snippets = { version = "0.6", features = ["ansi_term"] }
structopt = "0.3"
rustfmt-config_proc_macro = { version = "0.2", path = "config_proc_macro" }
Expand All @@ -62,17 +62,37 @@ rustfmt-config_proc_macro = { version = "0.2", path = "config_proc_macro" }
# for more information.
rustc-workspace-hack = "1.0.0"

[dependencies.rustc_ast_pretty]
package = "rustc-ap-rustc_ast_pretty"
version = "642.0.0"

[dependencies.rustc_data_structures]
package = "rustc-ap-rustc_data_structures"
version = "642.0.0"

[dependencies.rustc_errors]
package = "rustc-ap-rustc_errors"
version = "642.0.0"

[dependencies.rustc_parse]
package = "rustc-ap-rustc_parse"
version = "642.0.0"

[dependencies.rustc_session]
package = "rustc-ap-rustc_session"
version = "642.0.0"

[dependencies.rustc_span]
package = "rustc-ap-rustc_span"
version = "642.0.0"

[dependencies.rustc_target]
package = "rustc-ap-rustc_target"
version = "610.0.0"
version = "642.0.0"

[dependencies.syntax]
package = "rustc-ap-syntax"
version = "610.0.0"

[dependencies.syntax_pos]
package = "rustc-ap-syntax_pos"
version = "610.0.0"
version = "642.0.0"

[dev-dependencies]
lazy_static = "1.0.0"
13 changes: 6 additions & 7 deletions src/attr.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Format attributes and meta items.
use rustc_span::{symbol::sym, BytePos, Span, DUMMY_SP};
use syntax::ast;
use syntax::source_map::{BytePos, Span, DUMMY_SP};
use syntax::symbol::sym;

use self::doc_comment::DocCommentFormatter;
use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};
Expand Down Expand Up @@ -35,7 +34,7 @@ pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => expr.span,
ast::StmtKind::Mac(ref mac) => {
let (ref mac, _, _) = **mac;
mac.span
mac.span()
}
}
}
Expand Down Expand Up @@ -168,7 +167,7 @@ fn rewrite_initial_doc_comments(
return Some((0, None));
}
// Rewrite doc comments
let sugared_docs = take_while_with_pred(context, attrs, |a| a.is_sugared_doc);
let sugared_docs = take_while_with_pred(context, attrs, |a| a.is_doc_comment());
if !sugared_docs.is_empty() {
let snippet = sugared_docs
.iter()
Expand Down Expand Up @@ -316,7 +315,7 @@ where
impl Rewrite for ast::Attribute {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
let snippet = context.snippet(self.span);
if self.is_sugared_doc {
if self.is_doc_comment() {
rewrite_doc_comment(snippet, shape.comment(context.config), context.config)
} else {
let should_skip = self
Expand Down Expand Up @@ -438,7 +437,7 @@ impl<'a> Rewrite for [ast::Attribute] {
)?;
result.push_str(&comment);
if let Some(next) = attrs.get(derives.len()) {
if next.is_sugared_doc {
if next.is_doc_comment() {
let snippet = context.snippet(missing_span);
let (_, mlb) = has_newlines_before_after_comment(snippet);
result.push_str(&mlb);
Expand Down Expand Up @@ -471,7 +470,7 @@ impl<'a> Rewrite for [ast::Attribute] {
)?;
result.push_str(&comment);
if let Some(next) = attrs.get(1) {
if next.is_sugared_doc {
if next.is_doc_comment() {
let snippet = context.snippet(missing_span);
let (_, mlb) = has_newlines_before_after_comment(snippet);
result.push_str(&mlb);
Expand Down
2 changes: 1 addition & 1 deletion src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
use std::borrow::Cow;
use std::cmp::min;

use syntax::source_map::{BytePos, Span};
use rustc_span::{BytePos, Span};
use syntax::{ast, ptr};

use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar};
Expand Down
6 changes: 3 additions & 3 deletions src/closures.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use syntax::source_map::Span;
use rustc_span::Span;
use syntax::{ast, ptr};

use crate::attr::get_attrs_from_stmt;
Expand Down Expand Up @@ -176,7 +176,7 @@ fn rewrite_closure_expr(
| ast::ExprKind::Loop(..)
| ast::ExprKind::Struct(..) => true,

ast::ExprKind::AddrOf(_, ref expr)
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
Expand Down Expand Up @@ -382,7 +382,7 @@ fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool {
match expr.kind {
ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop(..) => true,
ast::ExprKind::Loop(..) if version == Version::Two => true,
ast::ExprKind::AddrOf(_, ref expr)
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
Expand Down
2 changes: 1 addition & 1 deletion src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{self, borrow::Cow, iter};

use itertools::{multipeek, MultiPeek};
use syntax::source_map::Span;
use rustc_span::Span;

use crate::config::Config;
use crate::rewrite::RewriteContext;
Expand Down
11 changes: 5 additions & 6 deletions src/config/file_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use std::path::PathBuf;
use std::rc::Rc;
use std::{cmp, fmt, iter, str};

use rustc_span::{self, SourceFile};
use serde::{ser, Deserialize, Deserializer, Serialize, Serializer};
use serde_json as json;

use syntax::source_map::{self, SourceFile};

/// A range of lines in a file, inclusive of both ends.
pub struct LineRange {
pub file: Rc<SourceFile>,
Expand All @@ -25,11 +24,11 @@ pub enum FileName {
Stdin,
}

impl From<source_map::FileName> for FileName {
fn from(name: source_map::FileName) -> FileName {
impl From<rustc_span::FileName> for FileName {
fn from(name: rustc_span::FileName) -> FileName {
match name {
source_map::FileName::Real(p) => FileName::Real(p),
source_map::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin,
rustc_span::FileName::Real(p) => FileName::Real(p),
rustc_span::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin,
_ => unreachable!(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ impl Default for Edition {
}

impl Edition {
pub(crate) fn to_libsyntax_pos_edition(self) -> syntax_pos::edition::Edition {
pub(crate) fn to_libsyntax_pos_edition(self) -> rustc_span::edition::Edition {
match self {
Edition::Edition2015 => syntax_pos::edition::Edition::Edition2015,
Edition::Edition2018 => syntax_pos::edition::Edition::Edition2018,
Edition::Edition2015 => rustc_span::edition::Edition::Edition2015,
Edition::Edition2018 => rustc_span::edition::Edition::Edition2018,
}
}
}
37 changes: 21 additions & 16 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::borrow::Cow;
use std::cmp::min;

use itertools::Itertools;
use syntax::parse::token::{DelimToken, LitKind};
use syntax::source_map::{BytePos, SourceMap, Span};
use rustc_span::{source_map::SourceMap, BytePos, Span};
use syntax::token::{DelimToken, LitKind};
use syntax::{ast, ptr};

use crate::chains::rewrite_chain;
Expand Down Expand Up @@ -159,7 +159,7 @@ pub(crate) fn format_expr(
ast::ExprKind::Path(ref qself, ref path) => {
rewrite_path(context, PathContext::Expr, qself.as_ref(), path, shape)
}
ast::ExprKind::Assign(ref lhs, ref rhs) => {
ast::ExprKind::Assign(ref lhs, ref rhs, _) => {
rewrite_assignment(context, lhs, rhs, None, shape)
}
ast::ExprKind::AssignOp(ref op, ref lhs, ref rhs) => {
Expand Down Expand Up @@ -213,8 +213,8 @@ pub(crate) fn format_expr(
rewrite_unary_prefix(context, "return ", &**expr, shape)
}
ast::ExprKind::Box(ref expr) => rewrite_unary_prefix(context, "box ", &**expr, shape),
ast::ExprKind::AddrOf(mutability, ref expr) => {
rewrite_expr_addrof(context, mutability, expr, shape)
ast::ExprKind::AddrOf(borrow_kind, mutability, ref expr) => {
rewrite_expr_addrof(context, borrow_kind, mutability, expr, shape)
}
ast::ExprKind::Cast(ref expr, ref ty) => rewrite_pair(
&**expr,
Expand Down Expand Up @@ -252,7 +252,7 @@ pub(crate) fn format_expr(
fn needs_space_before_range(context: &RewriteContext<'_>, lhs: &ast::Expr) -> bool {
match lhs.kind {
ast::ExprKind::Lit(ref lit) => match lit.kind {
ast::LitKind::FloatUnsuffixed(..) => {
ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => {
context.snippet(lit.span).ends_with('.')
}
_ => false,
Expand Down Expand Up @@ -1148,10 +1148,10 @@ pub(crate) fn is_simple_block(
attrs: Option<&[ast::Attribute]>,
source_map: &SourceMap,
) -> bool {
(block.stmts.len() == 1
block.stmts.len() == 1
&& stmt_is_expr(&block.stmts[0])
&& !block_contains_comment(block, source_map)
&& attrs.map_or(true, |a| a.is_empty()))
&& attrs.map_or(true, |a| a.is_empty())
}

/// Checks whether a block contains at most one statement or expression, and no
Expand Down Expand Up @@ -1268,7 +1268,7 @@ pub(crate) fn is_simple_expr(expr: &ast::Expr) -> bool {
match expr.kind {
ast::ExprKind::Lit(..) => true,
ast::ExprKind::Path(ref qself, ref path) => qself.is_none() && path.segments.len() <= 1,
ast::ExprKind::AddrOf(_, ref expr)
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Cast(ref expr, _)
| ast::ExprKind::Field(ref expr, _)
Expand Down Expand Up @@ -1314,8 +1314,12 @@ pub(crate) fn can_be_overflowed_expr(
|| (context.use_block_indent() && args_len == 1)
}
ast::ExprKind::Mac(ref mac) => {
match (mac.delim, context.config.overflow_delimited_expr()) {
(ast::MacDelimiter::Bracket, true) | (ast::MacDelimiter::Brace, true) => true,
match (
syntax::ast::MacDelimiter::from_token(mac.args.delim()),
context.config.overflow_delimited_expr(),
) {
(Some(ast::MacDelimiter::Bracket), true)
| (Some(ast::MacDelimiter::Brace), true) => true,
_ => context.use_block_indent() && args_len == 1,
}
}
Expand All @@ -1326,7 +1330,7 @@ pub(crate) fn can_be_overflowed_expr(
}

// Handle unary-like expressions
ast::ExprKind::AddrOf(_, ref expr)
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
Expand All @@ -1338,7 +1342,7 @@ pub(crate) fn can_be_overflowed_expr(
pub(crate) fn is_nested_call(expr: &ast::Expr) -> bool {
match expr.kind {
ast::ExprKind::Call(..) | ast::ExprKind::Mac(..) => true,
ast::ExprKind::AddrOf(_, ref expr)
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
Expand Down Expand Up @@ -1985,21 +1989,22 @@ pub(crate) fn prefer_next_line(

fn rewrite_expr_addrof(
context: &RewriteContext<'_>,
_borrow_kind: ast::BorrowKind,
mutability: ast::Mutability,
expr: &ast::Expr,
shape: Shape,
) -> Option<String> {
let operator_str = match mutability {
ast::Mutability::Immutable => "&",
ast::Mutability::Mutable => "&mut ",
ast::Mutability::Not => "&",
ast::Mutability::Mut => "&mut ",
};
rewrite_unary_prefix(context, operator_str, expr, shape)
}

pub(crate) fn is_method_call(expr: &ast::Expr) -> bool {
match expr.kind {
ast::ExprKind::MethodCall(..) => true,
ast::ExprKind::AddrOf(_, ref expr)
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Cast(ref expr, _)
| ast::ExprKind::Try(ref expr)
Expand Down
Loading

0 comments on commit 9f53665

Please sign in to comment.