Merge pull request #1923 from topecongiro/issue-1920
Allow pre-line single-lined comments to stay on the same line
This commit is contained in:
commit
536db5b83f
7 changed files with 22 additions and 54 deletions
14
src/lists.rs
14
src/lists.rs
|
|
@ -117,13 +117,23 @@ impl ListItem {
|
|||
self.item.as_ref().map_or("", |s| &*s)
|
||||
}
|
||||
|
||||
pub fn is_multiline(&self) -> bool {
|
||||
pub fn is_different_group(&self) -> bool {
|
||||
self.inner_as_ref().contains('\n') || self.pre_comment.is_some() ||
|
||||
self.post_comment
|
||||
.as_ref()
|
||||
.map_or(false, |s| s.contains('\n'))
|
||||
}
|
||||
|
||||
pub fn is_multiline(&self) -> bool {
|
||||
self.inner_as_ref().contains('\n') ||
|
||||
self.pre_comment
|
||||
.as_ref()
|
||||
.map_or(false, |s| s.contains('\n')) ||
|
||||
self.post_comment
|
||||
.as_ref()
|
||||
.map_or(false, |s| s.contains('\n'))
|
||||
}
|
||||
|
||||
pub fn has_comment(&self) -> bool {
|
||||
self.pre_comment
|
||||
.as_ref()
|
||||
|
|
@ -469,7 +479,7 @@ where
|
|||
let item = item.as_ref();
|
||||
let inner_item_width = item.inner_as_ref().len();
|
||||
if !first &&
|
||||
(item.is_multiline() || !item.post_comment.is_some() ||
|
||||
(item.is_different_group() || !item.post_comment.is_some() ||
|
||||
inner_item_width + overhead > max_budget)
|
||||
{
|
||||
return max_width;
|
||||
|
|
|
|||
|
|
@ -80,11 +80,7 @@ fn arrays() {
|
|||
0,
|
||||
];
|
||||
|
||||
let y = [
|
||||
/* comment */ 1,
|
||||
2, /* post comment */
|
||||
3,
|
||||
];
|
||||
let y = [/* comment */ 1, 2 /* post comment */, 3];
|
||||
|
||||
let xy = [
|
||||
strukt {
|
||||
|
|
|
|||
|
|
@ -208,12 +208,7 @@ fn arrays() {
|
|||
0,
|
||||
];
|
||||
|
||||
let y = [
|
||||
// comment
|
||||
1,
|
||||
2, // post comment
|
||||
3,
|
||||
];
|
||||
let y = [/* comment */ 1, 2 /* post comment */, 3];
|
||||
|
||||
let xy = [
|
||||
strukt {
|
||||
|
|
|
|||
|
|
@ -25,11 +25,7 @@ fn weird_comment(
|
|||
// Does this work?
|
||||
y: World,
|
||||
) {
|
||||
simple(
|
||||
// does this preserve comments now?
|
||||
42,
|
||||
NoWay,
|
||||
)
|
||||
simple(/* does this preserve comments now? */ 42, NoWay)
|
||||
}
|
||||
|
||||
fn generic<T>(arg: T) -> &SomeType
|
||||
|
|
|
|||
|
|
@ -6,15 +6,8 @@ fn main() {
|
|||
S(.., true) => (),
|
||||
S(..) => (),
|
||||
S(_) => (),
|
||||
S(
|
||||
// ..
|
||||
..
|
||||
) => (),
|
||||
S(
|
||||
// ..
|
||||
..,
|
||||
true,
|
||||
) => (),
|
||||
S(/* .. */ ..) => (),
|
||||
S(/* .. */ .., true) => (),
|
||||
}
|
||||
|
||||
match y {
|
||||
|
|
@ -23,14 +16,7 @@ fn main() {
|
|||
(.., true) => (),
|
||||
(..) => (),
|
||||
(_,) => (),
|
||||
(
|
||||
// ..
|
||||
..
|
||||
) => (),
|
||||
(
|
||||
// ..
|
||||
..,
|
||||
true,
|
||||
) => (),
|
||||
(/* .. */ ..) => (),
|
||||
(/* .. */ .., true) => (),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,6 @@ fn main() {
|
|||
Tup(_) => "nah",
|
||||
Quad(_, _, x, _) => " also no rewrite",
|
||||
Quad(x, ..) => "condense me pls",
|
||||
Weird(
|
||||
x,
|
||||
_,
|
||||
_,
|
||||
// dont condense before
|
||||
..
|
||||
) => "pls work",
|
||||
Weird(x, _, _, /* dont condense before */ ..) => "pls work",
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,22 +2,13 @@
|
|||
fn types() {
|
||||
let x: [Vec<_>] = [];
|
||||
let y: *mut [SomeType; konst_funk()] = expr();
|
||||
let z: (
|
||||
// #digits
|
||||
usize,
|
||||
// exp
|
||||
i16,
|
||||
) = funk();
|
||||
let z: (/* #digits */ usize, /* exp */ i16) = funk();
|
||||
let z: (usize /* #digits */, i16 /* exp */) = funk();
|
||||
}
|
||||
|
||||
struct F {
|
||||
f: extern "C" fn(x: u8, ... /* comment */),
|
||||
g: extern "C" fn(
|
||||
x: u8,
|
||||
// comment
|
||||
...
|
||||
),
|
||||
g: extern "C" fn(x: u8, /* comment */ ...),
|
||||
h: extern "C" fn(x: u8, ...),
|
||||
i: extern "C" fn(
|
||||
x: u8,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue