Skip to content

Cargo update #3559

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

Merged
merged 1 commit into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
335 changes: 187 additions & 148 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ env_logger = "0.6"
getopts = "0.2"
derive-new = "0.5"
cargo_metadata = "0.7"
rustc-ap-rustc_target = "407.0.0"
rustc-ap-syntax = "407.0.0"
rustc-ap-syntax_pos = "407.0.0"
rustc-ap-rustc_target = "486.0.0"
rustc-ap-syntax = "486.0.0"
rustc-ap-syntax_pos = "486.0.0"
failure = "0.1.3"
bytecount = "0.5"
unicode-width = "0.1.5"
Expand Down
22 changes: 12 additions & 10 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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 @@ -52,15 +53,15 @@ pub(crate) fn filter_inline_attrs(
}

fn is_derive(attr: &ast::Attribute) -> bool {
attr.check_name("derive")
attr.check_name(sym::derive)
}

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

Expand Down Expand Up @@ -189,9 +190,9 @@ fn rewrite_initial_doc_comments(

impl Rewrite for ast::NestedMetaItem {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match self.node {
ast::NestedMetaItemKind::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
ast::NestedMetaItemKind::Literal(ref l) => rewrite_literal(context, l, shape),
match self {
ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
ast::NestedMetaItem::Literal(ref l) => rewrite_literal(context, l, shape),
}
}
}
Expand Down Expand Up @@ -219,10 +220,10 @@ impl Rewrite for ast::MetaItem {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
Some(match self.node {
ast::MetaItemKind::Word => {
rewrite_path(context, PathContext::Type, None, &self.ident, shape)?
rewrite_path(context, PathContext::Type, None, &self.path, shape)?
}
ast::MetaItemKind::List(ref list) => {
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
let has_trailing_comma = crate::expr::span_ends_with_comma(context, self.span);
overflow::rewrite_with_parens(
context,
Expand All @@ -240,7 +241,7 @@ impl Rewrite for ast::MetaItem {
)?
}
ast::MetaItemKind::NameValue(ref literal) => {
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
// 3 = ` = `
let lit_shape = shape.shrink_left(path.len() + 3)?;
// `rewrite_literal` returns `None` when `literal` exceeds max
Expand Down Expand Up @@ -326,15 +327,16 @@ impl Rewrite for ast::Attribute {

if let Some(ref meta) = self.meta() {
// This attribute is possibly a doc attribute needing normalization to a doc comment
if context.config.normalize_doc_attributes() && meta.check_name("doc") {
if context.config.normalize_doc_attributes() && meta.check_name(sym::doc) {
if let Some(ref literal) = meta.value_str() {
let comment_style = match self.style {
ast::AttrStyle::Inner => CommentStyle::Doc,
ast::AttrStyle::Outer => CommentStyle::TripleSlash,
};

let literal_str = literal.as_str();
let doc_comment_formatter =
DocCommentFormatter::new(literal.as_str().get(), comment_style);
DocCommentFormatter::new(literal_str.get(), comment_style);
let doc_comment = format!("{}", doc_comment_formatter);
return rewrite_doc_comment(
&doc_comment,
Expand Down
13 changes: 10 additions & 3 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ enum ChainItemKind {
),
StructField(ast::Ident),
TupleField(ast::Ident, bool),
Await,
Comment(String, CommentPosition),
}

Expand All @@ -128,6 +129,7 @@ impl ChainItemKind {
ChainItemKind::MethodCall(..)
| ChainItemKind::StructField(..)
| ChainItemKind::TupleField(..)
| ChainItemKind::Await
| ChainItemKind::Comment(..) => false,
}
}
Expand Down Expand Up @@ -166,6 +168,10 @@ impl ChainItemKind {
let span = mk_sp(nested.span.hi(), field.span.hi());
(kind, span)
}
ast::ExprKind::Await(_, ref nested) => {
let span = mk_sp(nested.span.hi(), expr.span.hi());
(ChainItemKind::Await, span)
}
_ => return (ChainItemKind::Parent(expr.clone()), expr.span),
};

Expand All @@ -189,6 +195,7 @@ impl Rewrite for ChainItem {
if nested { " " } else { "" },
rewrite_ident(context, ident)
),
ChainItemKind::Await => ".await".to_owned(),
ChainItemKind::Comment(ref comment, _) => {
rewrite_comment(comment, false, shape, context.config)?
}
Expand Down Expand Up @@ -387,9 +394,9 @@ impl Chain {
ast::ExprKind::MethodCall(_, ref expressions) => {
Some(Self::convert_try(&expressions[0], context))
}
ast::ExprKind::Field(ref subexpr, _) | ast::ExprKind::Try(ref subexpr) => {
Some(Self::convert_try(subexpr, context))
}
ast::ExprKind::Field(ref subexpr, _)
| ast::ExprKind::Try(ref subexpr)
| ast::ExprKind::Await(_, ref subexpr) => Some(Self::convert_try(subexpr, context)),
_ => None,
}
}
Expand Down
36 changes: 29 additions & 7 deletions src/closures.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use syntax::parse::classify;
use syntax::source_map::Span;
use syntax::{ast, ptr};

Expand All @@ -25,7 +24,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};

pub(crate) fn rewrite_closure(
capture: ast::CaptureBy,
asyncness: ast::IsAsync,
is_async: &ast::IsAsync,
movability: ast::Movability,
fn_decl: &ast::FnDecl,
body: &ast::Expr,
Expand All @@ -36,7 +35,7 @@ pub(crate) fn rewrite_closure(
debug!("rewrite_closure {:?}", body);

let (prefix, extra_offset) = rewrite_closure_fn_decl(
capture, asyncness, movability, fn_decl, body, span, context, shape,
capture, is_async, movability, fn_decl, body, span, context, shape,
)?;
// 1 = space between `|...|` and body.
let body_shape = shape.offset_left(extra_offset)?;
Expand Down Expand Up @@ -134,7 +133,7 @@ fn rewrite_closure_with_block(
shape: Shape,
) -> Option<String> {
let left_most = left_most_sub_expr(body);
let veto_block = veto_block(body) && !classify::expr_requires_semi_to_be_stmt(left_most);
let veto_block = veto_block(body) && !expr_requires_semi_to_be_stmt(left_most);
if veto_block {
return None;
}
Expand Down Expand Up @@ -207,7 +206,7 @@ fn rewrite_closure_block(
// Return type is (prefix, extra_offset)
fn rewrite_closure_fn_decl(
capture: ast::CaptureBy,
asyncness: ast::IsAsync,
asyncness: &ast::IsAsync,
movability: ast::Movability,
fn_decl: &ast::FnDecl,
body: &ast::Expr,
Expand Down Expand Up @@ -291,7 +290,7 @@ pub(crate) fn rewrite_last_closure(
expr: &ast::Expr,
shape: Shape,
) -> Option<String> {
if let ast::ExprKind::Closure(capture, asyncness, movability, ref fn_decl, ref body, _) =
if let ast::ExprKind::Closure(capture, ref is_async, movability, ref fn_decl, ref body, _) =
expr.node
{
let body = match body.node {
Expand All @@ -305,7 +304,7 @@ pub(crate) fn rewrite_last_closure(
_ => body,
};
let (prefix, extra_offset) = rewrite_closure_fn_decl(
capture, asyncness, movability, fn_decl, body, expr.span, context, shape,
capture, is_async, movability, fn_decl, body, expr.span, context, shape,
)?;
// If the closure goes multi line before its body, do not overflow the closure.
if prefix.contains('\n') {
Expand Down Expand Up @@ -387,3 +386,26 @@ fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool {
_ => false,
}
}

/// Does this expression require a semicolon to be treated
/// as a statement? The negation of this: 'can this expression
/// be used as a statement without a semicolon' -- is used
/// as an early-bail-out in the parser so that, for instance,
/// if true {...} else {...}
/// |x| 5
/// isn't parsed as (if true {...} else {...} | x) | 5
// From https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/classify.rs.
fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
match e.node {
ast::ExprKind::If(..)
| ast::ExprKind::IfLet(..)
| ast::ExprKind::Match(..)
| ast::ExprKind::Block(..)
| ast::ExprKind::While(..)
| ast::ExprKind::WhileLet(..)
| ast::ExprKind::Loop(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::TryBlock(..) => false,
_ => true,
}
}
21 changes: 15 additions & 6 deletions src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;
use std::cmp::min;
use std::iter;

use itertools::Itertools;
use syntax::parse::token::DelimToken;
Expand Down Expand Up @@ -183,9 +184,9 @@ pub(crate) fn format_expr(
Some("yield".to_string())
}
}
ast::ExprKind::Closure(capture, asyncness, movability, ref fn_decl, ref body, _) => {
ast::ExprKind::Closure(capture, ref is_async, movability, ref fn_decl, ref body, _) => {
closures::rewrite_closure(
capture, asyncness, movability, fn_decl, body, expr.span, context, shape,
capture, is_async, movability, fn_decl, body, expr.span, context, shape,
)
}
ast::ExprKind::Try(..) | ast::ExprKind::Field(..) | ast::ExprKind::MethodCall(..) => {
Expand Down Expand Up @@ -335,10 +336,6 @@ pub(crate) fn format_expr(
))
}
}
ast::ExprKind::ObsoleteInPlace(ref lhs, ref rhs) => lhs
.rewrite(context, shape)
.map(|s| s + " <-")
.and_then(|lhs| rewrite_assign_rhs(context, lhs, &**rhs, shape)),
ast::ExprKind::Async(capture_by, _node_id, ref block) => {
let mover = if capture_by == ast::CaptureBy::Value {
"move "
Expand Down Expand Up @@ -371,6 +368,18 @@ pub(crate) fn format_expr(
))
}
}
ast::ExprKind::Await(ast::AwaitOrigin::FieldLike, _) => rewrite_chain(expr, context, shape),
ast::ExprKind::Await(ast::AwaitOrigin::MacroLike, ref nested) => {
overflow::rewrite_with_parens(
context,
"await!",
iter::once(nested),
shape,
expr.span,
context.config.max_width(),
None,
)
}
ast::ExprKind::Err => None,
};

Expand Down
8 changes: 2 additions & 6 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ impl<'b, T: Write + 'b> Session<'b, T> {
return Err(ErrorKind::VersionMismatch);
}

syntax::with_globals(|| {
syntax_pos::hygiene::set_default_edition(
self.config.edition().to_libsyntax_pos_edition(),
);

syntax::with_globals(self.config.edition().to_libsyntax_pos_edition(), || {
if self.config.disable_all_formatting() {
// When the input is from stdin, echo back the input.
if let Input::Text(ref buf) = input {
Expand Down Expand Up @@ -687,7 +683,7 @@ fn parse_crate(
struct SilentEmitter;

impl Emitter for SilentEmitter {
fn emit(&mut self, _db: &DiagnosticBuilder<'_>) {}
fn emit_diagnostic(&mut self, _db: &DiagnosticBuilder<'_>) {}
}

fn silent_emitter() -> Box<SilentEmitter> {
Expand Down
5 changes: 3 additions & 2 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt;

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 +250,7 @@ impl UseTree {
match self.attrs {
Some(ref attrs) if !attrs.is_empty() => {
let attr_str = attrs.rewrite(context, shape)?;
let lo = attrs.last().as_ref()?.span().hi();
let lo = attrs.last().as_ref()?.span.hi();
let hi = self.span.lo();
let span = mk_sp(lo, hi);

Expand Down Expand Up @@ -395,7 +396,7 @@ impl UseTree {
rewrite_ident(context, path_to_imported_ident(&a.prefix)).to_owned()
};
let alias = rename.and_then(|ident| {
if ident.name == "_" {
if ident.name == sym::underscore_imports {
// for impl-only-use
Some("_".to_owned())
} else if ident == path_to_imported_ident(&a.prefix) {
Expand Down
Loading