Skip to content
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

Comment between typebounds #4474

Merged
merged 6 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Removed unwanted whitespaces
  • Loading branch information
whizsid committed Oct 15, 2020
commit ec62b30f3cf84d863a2c70eb903632fcd71aac92
10 changes: 0 additions & 10 deletions src/formatting/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,6 @@ fn join_bounds_inner(
debug_assert!(!items.is_empty());

let generic_bounds_in_order = is_generic_bounds_in_order(items);

let is_bound_extendable = |s: &str, b: &ast::GenericBound| match b {
ast::GenericBound::Outlives(..) => true,
ast::GenericBound::Trait(..) => last_line_extendable(s),
Expand All @@ -876,7 +875,6 @@ fn join_bounds_inner(
} else {
None
};

let (leading_span, has_leading_comment) = if i > 0 {
let lo = context
.snippet_provider
Expand All @@ -890,7 +888,6 @@ fn join_bounds_inner(
} else {
(None, false)
};

let prev_has_trailing_comment = match prev_trailing_span {
Some(ts) => contains_comment(context.snippet(ts)),
_ => false,
Expand All @@ -903,7 +900,6 @@ fn join_bounds_inner(
} else {
shape
};

let whitespace = if force_newline && (!prev_extendable || !generic_bounds_in_order) {
shape
.indent
Expand All @@ -917,13 +913,11 @@ fn join_bounds_inner(
TypeDensity::Compressed => String::from("+"),
TypeDensity::Wide => whitespace + "+ ",
};

let joiner = if has_leading_comment {
joiner.trim_end()
} else {
&joiner
};

let joiner = if prev_has_trailing_comment {
joiner.trim_start()
} else {
Expand All @@ -932,13 +926,10 @@ fn join_bounds_inner(

let (trailing_str, extendable) = if i == 0 {
let bound_str = item.rewrite(context, shape)?;

let bound_str_clone = bound_str.clone();

(bound_str, is_bound_extendable(&bound_str_clone, item))
} else {
let bound_str = &item.rewrite(context, shape)?;

match leading_span {
Some(ls) if has_leading_comment => (
combine_strs_with_missing_comments(
Expand All @@ -952,7 +943,6 @@ fn join_bounds_inner(
),
}
};

match prev_trailing_span {
Some(ts) if prev_has_trailing_comment => combine_strs_with_missing_comments(
context,
Expand Down
29 changes: 29 additions & 0 deletions tmp/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
fn main() {
type A: AA /*AA*/ + /*AB*/ AB
+ AC = AA
/*AA*/
+
/*AB*/
AB
+ AC;

type B: BA /*BAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA*/
+ /*BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB*/ BB
+ BC = BA /*BAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA*/
+ /*BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB*/ BB
+ BC;

type C: CA // CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
// CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
// CBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
// CBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CB
+ CC = CA // CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
// CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
// CBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
// CBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CB
+ CC;
}
9 changes: 9 additions & 0 deletions tmp/test1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type C: AAAAAA+AAAAA+AAAAA+AAAAAAA + BBBBBB+BBBBBBBBBB+BBBBBB+BBBBBB + CCCCCCCC
// A comment
+
// A comment
CCCCCCCCCC+CCCCCCC+CCCCCCCCC = AAA+AA+AAAA+AAAA+AAAAA+AAA
// A comment
+AAAA +
// A comment
BBBB+BBBBB+BBBBB+BBBBB+BBB+BBB + CCCC+CCCC+CCCC+CCCCC+CCCCCC+CCCCC+CCCCCC;