-
Notifications
You must be signed in to change notification settings - Fork 925
fix: correct generic bound indentation [2.x/master] #4640
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
Merged
calebcartwright
merged 2 commits into
rust-lang:master
from
calebcartwright:fix-generic-bound-indentation
Jan 13, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -933,7 +933,7 @@ fn join_bounds_inner( | |
_ => false, | ||
}; | ||
|
||
let shape = if i > 0 && need_indent && force_newline { | ||
let shape = if need_indent && force_newline { | ||
shape | ||
.block_indent(context.config.tab_spaces()) | ||
.with_max_width(context.config) | ||
|
@@ -964,22 +964,21 @@ fn join_bounds_inner( | |
joiner | ||
}; | ||
|
||
let (trailing_str, extendable) = if i == 0 { | ||
let (extendable, trailing_str) = 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)) | ||
(is_bound_extendable(&bound_str, item), bound_str) | ||
Comment on lines
+967
to
+969
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neither related to the underlying bug nor necessary to fix it, just noticed while in here that we were unnecessarily cloning the formatted bound |
||
} else { | ||
let bound_str = &item.rewrite(context, shape)?; | ||
match leading_span { | ||
Some(ls) if has_leading_comment => ( | ||
is_bound_extendable(bound_str, item), | ||
combine_strs_with_missing_comments( | ||
context, joiner, bound_str, ls, shape, true, | ||
)?, | ||
is_bound_extendable(bound_str, item), | ||
), | ||
_ => ( | ||
String::from(joiner) + bound_str, | ||
is_bound_extendable(bound_str, item), | ||
String::from(joiner) + bound_str, | ||
), | ||
} | ||
}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pub trait PrettyPrinter<'tcx>: | ||
Printer< | ||
'tcx, | ||
Error = fmt::Error, | ||
Path = Self, | ||
Region = Self, | ||
Type = Self, | ||
DynExistential = Self, | ||
Const = Self, | ||
> + fmt::Write | ||
{ | ||
// | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pub trait PrettyPrinter<'tcx>: | ||
Printer< | ||
'tcx, | ||
Error = fmt::Error, | ||
Path = Self, | ||
Region = Self, | ||
Type = Self, | ||
DynExistential = Self, | ||
Const = Self, | ||
> + fmt::Write | ||
{ | ||
// | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way the code is structured,
force_newline
will always be false on the first pass through and a second pass is only triggered in situations where we have to use multiple lines to format. As such this index check only serves to cause a bug