Skip to content

Update rustc-ap-* #2854

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 2 commits into from
Jul 20, 2018
Merged
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
141 changes: 72 additions & 69 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
@@ -47,9 +47,9 @@ env_logger = "0.5"
getopts = "0.2"
derive-new = "0.5"
cargo_metadata = "0.6"
rustc-ap-rustc_target = "196.0.0"
rustc-ap-syntax = "196.0.0"
rustc-ap-syntax_pos = "196.0.0"
rustc-ap-rustc_target = "201.0.0"
rustc-ap-syntax = "201.0.0"
rustc-ap-syntax_pos = "201.0.0"
failure = "0.1.1"

[dev-dependencies]
18 changes: 17 additions & 1 deletion src/closures.rs
Original file line number Diff line number Diff line change
@@ -118,6 +118,22 @@ fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext) -> bo
|| prefix.contains('\n')
}

fn veto_block(e: &ast::Expr) -> bool {
match e.node {
ast::ExprKind::Call(..)
| ast::ExprKind::Binary(..)
| ast::ExprKind::Cast(..)
| ast::ExprKind::Type(..)
| ast::ExprKind::Assign(..)
| ast::ExprKind::AssignOp(..)
| ast::ExprKind::Field(..)
| ast::ExprKind::Index(..)
| ast::ExprKind::Range(..)
| ast::ExprKind::Try(..) => true,
_ => false,
}
}

// Rewrite closure with a single expression wrapping its body with block.
fn rewrite_closure_with_block(
body: &ast::Expr,
@@ -126,7 +142,7 @@ fn rewrite_closure_with_block(
shape: Shape,
) -> Option<String> {
let left_most = left_most_sub_expr(body);
let veto_block = left_most != body && !classify::expr_requires_semi_to_be_stmt(left_most);
let veto_block = veto_block(body) && !classify::expr_requires_semi_to_be_stmt(left_most);
if veto_block {
return None;
}
7 changes: 2 additions & 5 deletions src/imports.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListIte
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use spanned::Spanned;
use utils::{mk_sp, rewrite_ident};
use utils::{is_same_visibility, mk_sp, rewrite_ident};
use visitor::FmtVisitor;

use std::borrow::Cow;
@@ -485,10 +485,7 @@ impl UseTree {
}),
)
| (None, None) => true,
(
Some(codemap::Spanned { node: lnode, .. }),
Some(codemap::Spanned { node: rnode, .. }),
) => lnode == rnode,
(Some(ref a), Some(ref b)) => is_same_visibility(a, b),
_ => false,
}
}
20 changes: 20 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -37,6 +37,26 @@ pub fn extra_offset(text: &str, shape: Shape) -> usize {
}
}

pub fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
match (&a.node, &b.node) {
(
VisibilityKind::Restricted { path: p, .. },
VisibilityKind::Restricted { path: q, .. },
) => format!("{}", p) == format!("{}", q),
(VisibilityKind::Public, VisibilityKind::Public)
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
| (
VisibilityKind::Crate(CrateSugar::PubCrate),
VisibilityKind::Crate(CrateSugar::PubCrate),
)
| (
VisibilityKind::Crate(CrateSugar::JustCrate),
VisibilityKind::Crate(CrateSugar::JustCrate),
) => true,
_ => false,
}
}

// Uses Cow to avoid allocating in the common cases.
pub fn format_visibility(context: &RewriteContext, vis: &Visibility) -> Cow<'static, str> {
match vis.node {