Skip to content

Commit d0c6a6d

Browse files
authored
Merge pull request rust-lang#3067 from topecongiro/refactor-toexpr
Add println!-like heuristic to the fail attribute
2 parents b32cf4a + bc835b7 commit d0c6a6d

13 files changed

+371
-335
lines changed

.travis.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,12 @@ matrix:
3535
- env: INTEGRATION=stdsimd
3636
- env: INTEGRATION=tempdir
3737
allow_failures:
38-
# Needs `edition = "2018"` in rustfmt.toml
39-
- env: INTEGRATION=chalk
40-
# Fails tests, don't know why
41-
- env: INTEGRATION=crater
4238
# Doesn't build
4339
- env: INTEGRATION=futures-rs
4440
# Doesn't build - seems to be because of an option
4541
- env: INTEGRATION=packed_simd
46-
# Weird bug I can't reproduce: #2969
47-
- env: INTEGRATION=rand
4842
# Test failure
4943
- env: INTEGRATION=rust-clippy
50-
# Build failure
51-
- env: INTEGRATION=rust-semverver
5244

5345
script:
5446
- |

src/attr.rs

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ use config::lists::*;
1515
use config::IndentStyle;
1616
use expr::rewrite_literal;
1717
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
18+
use overflow;
1819
use rewrite::{Rewrite, RewriteContext};
1920
use shape::Shape;
2021
use types::{rewrite_path, PathContext};
2122
use utils::{count_newlines, mk_sp};
2223

23-
use std::borrow::Cow;
2424
use syntax::ast;
2525
use syntax::source_map::{BytePos, Span, DUMMY_SP};
2626

@@ -216,56 +216,21 @@ impl Rewrite for ast::MetaItem {
216216
}
217217
ast::MetaItemKind::List(ref list) => {
218218
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
219-
220-
let has_comma = ::expr::span_ends_with_comma(context, self.span);
221-
let trailing_comma = if has_comma { "," } else { "" };
222-
let combine = list.len() == 1 && match list[0].node {
223-
ast::NestedMetaItemKind::Literal(..) => false,
224-
ast::NestedMetaItemKind::MetaItem(ref inner_meta_item) => {
225-
match inner_meta_item.node {
226-
ast::MetaItemKind::List(..) => rewrite_path(
227-
context,
228-
PathContext::Type,
229-
None,
230-
&inner_meta_item.ident,
231-
shape,
232-
)
233-
.map_or(false, |s| s.len() + path.len() + 2 <= shape.width),
234-
_ => false,
235-
}
236-
}
237-
};
238-
239-
let argument_shape = argument_shape(
240-
path.len() + 1,
241-
2 + trailing_comma.len(),
242-
combine,
243-
shape,
219+
let has_trailing_comma = ::expr::span_ends_with_comma(context, self.span);
220+
overflow::rewrite_with_parens(
244221
context,
245-
)?;
246-
let item_str = format_arg_list(
222+
&path,
247223
list.iter(),
248-
|nested_meta_item| nested_meta_item.span.lo(),
249-
|nested_meta_item| nested_meta_item.span.hi(),
250-
|nested_meta_item| nested_meta_item.rewrite(context, argument_shape),
224+
// 1 = "]"
225+
shape.sub_width(1)?,
251226
self.span,
252-
context,
253-
argument_shape,
254-
// 3 = "()" and "]"
255-
shape
256-
.offset_left(path.len())?
257-
.sub_width(3 + trailing_comma.len())?,
258-
Some(context.config.width_heuristics().fn_call_width),
259-
combine,
260-
)?;
261-
262-
let indent = if item_str.starts_with('\n') {
263-
shape.indent.to_string_with_newline(context.config)
264-
} else {
265-
Cow::Borrowed("")
266-
};
267-
268-
format!("{}({}{}{})", path, item_str, trailing_comma, indent)
227+
context.config.width_heuristics().fn_call_width,
228+
Some(if has_trailing_comma {
229+
SeparatorTactic::Always
230+
} else {
231+
SeparatorTactic::Never
232+
}),
233+
)?
269234
}
270235
ast::MetaItemKind::NameValue(ref literal) => {
271236
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;

src/closures.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ use syntax::parse::classify;
1313
use syntax::source_map::Span;
1414
use syntax::{ast, ptr};
1515

16-
use expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond, ToExpr};
16+
use expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond};
1717
use items::{span_hi_for_arg, span_lo_for_arg};
1818
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
19+
use overflow::OverflowableItem;
1920
use rewrite::{Rewrite, RewriteContext};
2021
use shape::Shape;
2122
use source_map::SpanUtils;
@@ -358,18 +359,12 @@ pub fn rewrite_last_closure(
358359
}
359360

360361
/// Returns true if the given vector of arguments has more than one `ast::ExprKind::Closure`.
361-
pub fn args_have_many_closure<T>(args: &[&T]) -> bool
362-
where
363-
T: ToExpr,
364-
{
362+
pub fn args_have_many_closure(args: &[OverflowableItem]) -> bool {
365363
args.iter()
366-
.filter(|arg| {
367-
arg.to_expr()
368-
.map(|e| match e.node {
369-
ast::ExprKind::Closure(..) => true,
370-
_ => false,
371-
})
372-
.unwrap_or(false)
364+
.filter_map(|arg| arg.to_expr())
365+
.filter(|expr| match expr.node {
366+
ast::ExprKind::Closure(..) => true,
367+
_ => false,
373368
})
374369
.count()
375370
> 1

0 commit comments

Comments
 (0)