Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade rustc-ap-* version to v642 #4022

Merged
merged 22 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
900c527
deps: bump rustc-ap to latest
calebcartwright Jan 14, 2020
dc44c57
refactor: symb/source_map/syntax_pos to rustc_span
calebcartwright Jan 14, 2020
1800d06
refactor: switch to new rustc_parse crate
calebcartwright Jan 15, 2020
050b0e1
refactor: update `token` mod paths
calebcartwright Jan 15, 2020
c73348a
refactor: consume errors/diag. from rustc_errors
calebcartwright Jan 15, 2020
297f7db
refactor: switch to AssocItem
calebcartwright Jan 15, 2020
4a71b53
refactor: ThinVec --> AttrVec
calebcartwright Jan 15, 2020
f87fe48
refactor: update ast::Mutabiltiy variants
calebcartwright Jan 15, 2020
73adbd3
refactor: use pprust explicitly
calebcartwright Jan 15, 2020
a34d9b1
refactor: update SymbolStr dereferencing
calebcartwright Jan 15, 2020
6064ab5
refactor: update some ExprKind variants
calebcartwright Jan 15, 2020
30ed45b
refactor: apply AST doc comment updates
calebcartwright Jan 15, 2020
a609afb
refactor: update unsuffixed float detection
calebcartwright Jan 15, 2020
4a00fa8
refactor: update ast::Mac tokenstream detection
calebcartwright Jan 15, 2020
580d6e9
refactor: apply more parser and a TyAlias change
calebcartwright Jan 15, 2020
f12d4eb
refactor: update Attribute path access
calebcartwright Jan 15, 2020
3567cd0
refactor: more visit::FnKind items
calebcartwright Jan 15, 2020
53cb6fb
refactor: few minor updates
calebcartwright Jan 15, 2020
e3e04af
refactor: update ABI/Extern handling
calebcartwright Jan 15, 2020
00f2a46
tests: fix some changes for rustc-ap update
calebcartwright Jan 15, 2020
fdbb158
deps: update to rustc-ap v641
calebcartwright Feb 8, 2020
2a497c7
deps: update to rustc-ap v642
calebcartwright Feb 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
284 changes: 196 additions & 88 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions rustfmt-core/rustfmt-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ serde_json = "1.0"
thiserror = "1.0"
toml = "0.5"

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

18 changes: 9 additions & 9 deletions rustfmt-core/rustfmt-config/src/file_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{ser, Deserialize, Deserializer, Serialize, Serializer};
use serde_json as json;
use thiserror::Error;

use syntax_pos::{self, SourceFile};
use rustc_span::{self, SourceFile};

/// A range of lines in a file, inclusive of both ends.
pub struct LineRange {
Expand All @@ -26,21 +26,21 @@ pub enum FileName {
Stdin,
}

impl From<syntax_pos::FileName> for FileName {
fn from(name: syntax_pos::FileName) -> FileName {
impl From<rustc_span::FileName> for FileName {
fn from(name: rustc_span::FileName) -> FileName {
match name {
syntax_pos::FileName::Real(p) => FileName::Real(p),
syntax_pos::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!(),
}
}
}

impl From<&FileName> for syntax_pos::FileName {
fn from(filename: &FileName) -> syntax_pos::FileName {
impl From<&FileName> for rustc_span::FileName {
fn from(filename: &FileName) -> rustc_span::FileName {
match filename {
FileName::Real(path) => syntax_pos::FileName::Real(path.to_owned()),
FileName::Stdin => syntax_pos::FileName::Custom("stdin".to_owned()),
FileName::Real(path) => rustc_span::FileName::Real(path.to_owned()),
FileName::Stdin => rustc_span::FileName::Custom("stdin".to_owned()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-config/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Default for Edition {
}
}

impl From<Edition> for syntax_pos::edition::Edition {
impl From<Edition> for rustc_span::edition::Edition {
fn from(edition: Edition) -> Self {
match edition {
Edition::Edition2015 => Self::Edition2015,
Expand Down
36 changes: 26 additions & 10 deletions rustfmt-core/rustfmt-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,35 @@ unicode-width = "0.1.5"
[dev-dependencies]
env_logger = "0.7"

[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"

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

13 changes: 6 additions & 7 deletions rustfmt-core/rustfmt-lib/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::{BytePos, DUMMY_SP, Span, symbol::sym};
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 rustfmt-core/rustfmt-lib/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 rustfmt-core/rustfmt-lib/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 @@ -184,7 +184,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 @@ -431,7 +431,7 @@ fn is_block_closure_forced_inner(expr: &ast::Expr) -> bool {
| ast::ExprKind::While(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::Loop(..) => 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 rustfmt-core/rustfmt-lib/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
33 changes: 19 additions & 14 deletions rustfmt-core/rustfmt-lib/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, Span};
use rustc_span::{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 @@ -1289,7 +1289,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 @@ -1335,8 +1335,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 @@ -1347,7 +1351,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 @@ -1359,7 +1363,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 @@ -2035,21 +2039,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
4 changes: 2 additions & 2 deletions rustfmt-core/rustfmt-lib/src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::collections::HashMap;
use std::io::{self, Write};
use std::time::{Duration, Instant};

use rustc_span::Span;
use syntax::ast;
use syntax::source_map::Span;

use self::newline_style::apply_newline_style;
use crate::comment::{CharClasses, FullCodeCharKind};
Expand Down Expand Up @@ -93,7 +93,7 @@ fn format_project<T: FormatHandler>(
let mut context = FormatContext::new(&krate, report, parse_session, config, handler);
let files = modules::ModResolver::new(
&context.parse_session,
directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaMod(true)),
directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaMod),
!input_is_stdin && config.recursive(),
)
.visit_crate(&krate)
Expand Down
7 changes: 3 additions & 4 deletions rustfmt-core/rustfmt-lib/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::borrow::Cow;
use std::cmp::Ordering;
use std::fmt;

use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol::sym};
use syntax::ast::{self, UseTreeKind};
use syntax::source_map::{self, BytePos, Span, DUMMY_SP};
use syntax::symbol::sym;

use crate::comment::combine_strs_with_missing_comments;
use crate::config::lists::*;
Expand Down Expand Up @@ -249,7 +248,7 @@ impl UseTree {

let allow_extend = if attrs.len() == 1 {
let line_len = attr_str.len() + 1 + use_str.len();
!attrs.first().unwrap().is_sugared_doc
!attrs.first().unwrap().is_doc_comment()
&& context.config.inline_attribute_width() >= line_len
} else {
false
Expand Down Expand Up @@ -854,7 +853,7 @@ impl Rewrite for UseTree {
#[cfg(test)]
mod test {
use super::*;
use syntax::source_map::DUMMY_SP;
use rustc_span::DUMMY_SP;

// Parse the path part of an import. This parser is not robust and is only
// suitable for use in a test harness.
Expand Down
Loading