-
Notifications
You must be signed in to change notification settings - Fork 901
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
Indentation on multiline single generic bound #4730
Indentation on multiline single generic bound #4730
Conversation
src/formatting/types.rs
Outdated
let retry_with_force_newline = | ||
if force_newline || (!result.0.contains('\n') && result.0.len() <= shape.width) { | ||
false | ||
} else { | ||
if items.len() > 1 { | ||
true | ||
} else { | ||
match items[0] { | ||
ast::GenericBound::Trait(ref poly_trait_ref, ..) => { | ||
let segments = &poly_trait_ref.trait_ref.path.segments; | ||
if segments.len() > 1 { | ||
true | ||
} else { | ||
if let Some(args_in) = &segments[0].args { | ||
match &**args_in { | ||
ast::AngleBracketed(args) => { | ||
if args.args.len() > 1 { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
_ => false, | ||
} | ||
} else { | ||
false | ||
} | ||
} | ||
} | ||
_ => false, | ||
} | ||
} | ||
}; |
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.
👀 this is a pretty gnarly looking conditional.
before thinking about the approach, i'd really like to see if this can be refactored (e.g. with different control flows) to reduce the excessive nesting or otherwise extract it out entirely as a separate function to be able to reduce the levels and rightward drift
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.
... or otherwise extract it out entirely as a separate function to be able to reduce the levels and rightward drift
Refactored by add is_segment_with_multi_items_array
function which took out part of the conditions nesting. Also re-based, so old version is not available.
32e3ee9
to
879b592
Compare
I think this probably could be simplified a bit more (e.g. guards on the match arms) but really just stylistic nits so going to go ahead and merge, thank you! |
Suggested fix for issue #4689. The change is that
join_bounds_inner
is calling itself withforce_newline
set, not only when theitems.len() > 1
, but also when the single item isTrait
which containssegments
array with more then one item, orAngleBracketed
args
array with more then one item.I don't know rust well enough to understand whether the test cases fully cover these cases.