Skip to content

Commit d40ed14

Browse files
committed
Fix breaking changes
cc rust-lang/rust#51829.
1 parent 52f9f7b commit d40ed14

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

src/closures.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext) -> bo
118118
|| prefix.contains('\n')
119119
}
120120

121+
fn veto_block(e: &ast::Expr) -> bool {
122+
match e.node {
123+
ast::ExprKind::Call(..)
124+
| ast::ExprKind::Binary(..)
125+
| ast::ExprKind::Cast(..)
126+
| ast::ExprKind::Type(..)
127+
| ast::ExprKind::Assign(..)
128+
| ast::ExprKind::AssignOp(..)
129+
| ast::ExprKind::Field(..)
130+
| ast::ExprKind::Index(..)
131+
| ast::ExprKind::Range(..)
132+
| ast::ExprKind::Try(..) => true,
133+
_ => false,
134+
}
135+
}
136+
121137
// Rewrite closure with a single expression wrapping its body with block.
122138
fn rewrite_closure_with_block(
123139
body: &ast::Expr,
@@ -126,7 +142,7 @@ fn rewrite_closure_with_block(
126142
shape: Shape,
127143
) -> Option<String> {
128144
let left_most = left_most_sub_expr(body);
129-
let veto_block = left_most != body && !classify::expr_requires_semi_to_be_stmt(left_most);
145+
let veto_block = veto_block(body) && !classify::expr_requires_semi_to_be_stmt(left_most);
130146
if veto_block {
131147
return None;
132148
}

src/imports.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListIte
2121
use rewrite::{Rewrite, RewriteContext};
2222
use shape::Shape;
2323
use spanned::Spanned;
24-
use utils::{mk_sp, rewrite_ident};
24+
use utils::{is_same_visibility, mk_sp, rewrite_ident};
2525
use visitor::FmtVisitor;
2626

2727
use std::borrow::Cow;
@@ -485,10 +485,7 @@ impl UseTree {
485485
}),
486486
)
487487
| (None, None) => true,
488-
(
489-
Some(codemap::Spanned { node: lnode, .. }),
490-
Some(codemap::Spanned { node: rnode, .. }),
491-
) => lnode == rnode,
488+
(Some(ref a), Some(ref b)) => is_same_visibility(a, b),
492489
_ => false,
493490
}
494491
}

src/utils.rs

+20
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ pub fn extra_offset(text: &str, shape: Shape) -> usize {
3737
}
3838
}
3939

40+
pub fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
41+
match (&a.node, &b.node) {
42+
(
43+
VisibilityKind::Restricted { path: p, .. },
44+
VisibilityKind::Restricted { path: q, .. },
45+
) => format!("{}", p) == format!("{}", q),
46+
(VisibilityKind::Public, VisibilityKind::Public)
47+
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
48+
| (
49+
VisibilityKind::Crate(CrateSugar::PubCrate),
50+
VisibilityKind::Crate(CrateSugar::PubCrate),
51+
)
52+
| (
53+
VisibilityKind::Crate(CrateSugar::JustCrate),
54+
VisibilityKind::Crate(CrateSugar::JustCrate),
55+
) => true,
56+
_ => false,
57+
}
58+
}
59+
4060
// Uses Cow to avoid allocating in the common cases.
4161
pub fn format_visibility(context: &RewriteContext, vis: &Visibility) -> Cow<'static, str> {
4262
match vis.node {

0 commit comments

Comments
 (0)