Merge pull request #3298 from topecongiro/issue-3272
Use the same rule between function and macro
This commit is contained in:
commit
923da60f72
11 changed files with 124 additions and 22 deletions
|
|
@ -11,6 +11,7 @@
|
|||
//! Rewrite a list some items with overflow.
|
||||
|
||||
use config::lists::*;
|
||||
use config::Version;
|
||||
use syntax::parse::token::DelimToken;
|
||||
use syntax::source_map::Span;
|
||||
use syntax::{ast, ptr};
|
||||
|
|
@ -466,6 +467,13 @@ impl<'a> Context<'a> {
|
|||
{
|
||||
self.context.force_one_line_chain.replace(true);
|
||||
}
|
||||
Some(OverflowableItem::MacroArg(MacroArg::Expr(expr)))
|
||||
if !combine_arg_with_callee
|
||||
&& is_method_call(expr)
|
||||
&& self.context.config.version() == Version::Two =>
|
||||
{
|
||||
self.context.force_one_line_chain.replace(true);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
let result = last_item_shape(
|
||||
|
|
@ -632,8 +640,6 @@ impl<'a> Context<'a> {
|
|||
_ => (self.prefix, self.suffix),
|
||||
};
|
||||
|
||||
// 2 = `()`
|
||||
let fits_one_line = items_str.len() + 2 <= shape.width;
|
||||
let extend_width = if items_str.is_empty() {
|
||||
2
|
||||
} else {
|
||||
|
|
@ -652,10 +658,16 @@ impl<'a> Context<'a> {
|
|||
);
|
||||
result.push_str(self.ident);
|
||||
result.push_str(prefix);
|
||||
if !self.context.use_block_indent()
|
||||
|| (self.context.inside_macro() && !items_str.contains('\n') && fits_one_line)
|
||||
|| (is_extendable && extend_width <= shape.width)
|
||||
{
|
||||
let force_single_line = if self.context.config.version() == Version::Two {
|
||||
!self.context.use_block_indent() || (is_extendable && extend_width <= shape.width)
|
||||
} else {
|
||||
// 2 = `()`
|
||||
let fits_one_line = items_str.len() + 2 <= shape.width;
|
||||
!self.context.use_block_indent()
|
||||
|| (self.context.inside_macro() && !items_str.contains('\n') && fits_one_line)
|
||||
|| (is_extendable && extend_width <= shape.width)
|
||||
};
|
||||
if force_single_line {
|
||||
result.push_str(items_str);
|
||||
} else {
|
||||
if !items_str.is_empty() {
|
||||
|
|
|
|||
15
tests/source/issue-3272/v1.rs
Normal file
15
tests/source/issue-3272/v1.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// rustfmt-version: One
|
||||
|
||||
fn main() {
|
||||
assert!(HAYSTACK
|
||||
.par_iter()
|
||||
.find_any(|&&x| x[0] % 1000 == 999)
|
||||
.is_some());
|
||||
|
||||
assert(
|
||||
HAYSTACK
|
||||
.par_iter()
|
||||
.find_any(|&&x| x[0] % 1000 == 999)
|
||||
.is_some(),
|
||||
);
|
||||
}
|
||||
15
tests/source/issue-3272/v2.rs
Normal file
15
tests/source/issue-3272/v2.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// rustfmt-version: Two
|
||||
|
||||
fn main() {
|
||||
assert!(HAYSTACK
|
||||
.par_iter()
|
||||
.find_any(|&&x| x[0] % 1000 == 999)
|
||||
.is_some());
|
||||
|
||||
assert(
|
||||
HAYSTACK
|
||||
.par_iter()
|
||||
.find_any(|&&x| x[0] % 1000 == 999)
|
||||
.is_some(),
|
||||
);
|
||||
}
|
||||
|
|
@ -400,14 +400,6 @@ fn foo() {
|
|||
foo!(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,);
|
||||
}
|
||||
|
||||
// #2652
|
||||
// Preserve trailing comma inside macro, even if it looks an array.
|
||||
macro_rules! bar {
|
||||
($m:ident) => {
|
||||
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]);
|
||||
};
|
||||
}
|
||||
|
||||
// #2830
|
||||
// Preserve trailing comma-less/ness inside nested macro.
|
||||
named!(
|
||||
|
|
|
|||
10
tests/source/single-line-macro/v1.rs
Normal file
10
tests/source/single-line-macro/v1.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// rustfmt-version: One
|
||||
|
||||
// #2652
|
||||
// Preserve trailing comma inside macro, even if it looks an array.
|
||||
macro_rules! bar {
|
||||
($m:ident) => {
|
||||
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,]);
|
||||
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]);
|
||||
};
|
||||
}
|
||||
10
tests/source/single-line-macro/v2.rs
Normal file
10
tests/source/single-line-macro/v2.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// rustfmt-version: Two
|
||||
|
||||
// #2652
|
||||
// Preserve trailing comma inside macro, even if it looks an array.
|
||||
macro_rules! bar {
|
||||
($m:ident) => {
|
||||
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,]);
|
||||
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]);
|
||||
};
|
||||
}
|
||||
15
tests/target/issue-3272/v1.rs
Normal file
15
tests/target/issue-3272/v1.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// rustfmt-version: One
|
||||
|
||||
fn main() {
|
||||
assert!(HAYSTACK
|
||||
.par_iter()
|
||||
.find_any(|&&x| x[0] % 1000 == 999)
|
||||
.is_some());
|
||||
|
||||
assert(
|
||||
HAYSTACK
|
||||
.par_iter()
|
||||
.find_any(|&&x| x[0] % 1000 == 999)
|
||||
.is_some(),
|
||||
);
|
||||
}
|
||||
17
tests/target/issue-3272/v2.rs
Normal file
17
tests/target/issue-3272/v2.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// rustfmt-version: Two
|
||||
|
||||
fn main() {
|
||||
assert!(
|
||||
HAYSTACK
|
||||
.par_iter()
|
||||
.find_any(|&&x| x[0] % 1000 == 999)
|
||||
.is_some()
|
||||
);
|
||||
|
||||
assert(
|
||||
HAYSTACK
|
||||
.par_iter()
|
||||
.find_any(|&&x| x[0] % 1000 == 999)
|
||||
.is_some(),
|
||||
);
|
||||
}
|
||||
|
|
@ -980,14 +980,6 @@ fn foo() {
|
|||
);
|
||||
}
|
||||
|
||||
// #2652
|
||||
// Preserve trailing comma inside macro, even if it looks an array.
|
||||
macro_rules! bar {
|
||||
($m:ident) => {
|
||||
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]);
|
||||
};
|
||||
}
|
||||
|
||||
// #2830
|
||||
// Preserve trailing comma-less/ness inside nested macro.
|
||||
named!(
|
||||
|
|
|
|||
10
tests/target/single-line-macro/v1.rs
Normal file
10
tests/target/single-line-macro/v1.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// rustfmt-version: One
|
||||
|
||||
// #2652
|
||||
// Preserve trailing comma inside macro, even if it looks an array.
|
||||
macro_rules! bar {
|
||||
($m:ident) => {
|
||||
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,]);
|
||||
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]);
|
||||
};
|
||||
}
|
||||
14
tests/target/single-line-macro/v2.rs
Normal file
14
tests/target/single-line-macro/v2.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// rustfmt-version: Two
|
||||
|
||||
// #2652
|
||||
// Preserve trailing comma inside macro, even if it looks an array.
|
||||
macro_rules! bar {
|
||||
($m:ident) => {
|
||||
$m!([
|
||||
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,
|
||||
]);
|
||||
$m!([
|
||||
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
|
||||
]);
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue