-
Notifications
You must be signed in to change notification settings - Fork 878
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
fix to extract comments to stop internal error #3857
Conversation
@@ -1892,6 +1904,7 @@ fn choose_rhs<R: Rewrite>( | |||
shape: Shape, | |||
orig_rhs: Option<String>, | |||
rhs_tactics: RhsTactics, | |||
has_rhs_comment: bool, |
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.
Perhaps there is a better way than adding a flag. But I can't think of a good idea ...
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.
What about inspecting the content of orig_rhs
and see if it starts with the comment? Something like the following:
let has_rhs_comment = orig_rhs.map_or(false, |s| starts_with_comment(s.trim_left()));
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.
I tried your proposal, but it's failed. The orig_rhs doesn't have the comments. The lhs has the comment and indent insteadof orig_rhs. below is an example.
fn main() {
let after =
// after_comment
if true {
1.0
};
}
// &lhs = "let after =\n // after_comment\n "
// &orig_rhs = Some("if true {\n 1.0\n }",)
lhs is this
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.
I see, thank you for your explanation. In that case, is it possible to use the lhs
to detect comments instead? Something like the following:
let has_rhs_comment = !lhs.trim_right().ends_with_comment();
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.
Absolutely. It's a good idea. I fixed it.
I reverted the commit. |
369eefe
to
b57ded9
Compare
to remove has_rhs_comment
fix: #3851