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

update rewrite_assignment to return RewriteResult #6295

Merged
merged 1 commit into from
Sep 1, 2024

Conversation

ding-young
Copy link
Contributor

tracked by #6206

Description

update rewrite_assignment to return RewriteResult

src/expr.rs Outdated
Comment on lines 2208 to 2229
match (orig_rhs, new_rhs) {
(Some(ref orig_rhs), Some(ref new_rhs))
(Ok(ref orig_rhs), Ok(ref new_rhs))
if !filtered_str_fits(&new_rhs, context.config.max_width(), new_shape) =>
{
Some(format!("{before_space_str}{orig_rhs}"))
Ok(format!("{before_space_str}{orig_rhs}"))
}
(Some(ref orig_rhs), Some(ref new_rhs))
(Ok(ref orig_rhs), Ok(ref new_rhs))
if prefer_next_line(orig_rhs, new_rhs, rhs_tactics) =>
{
Some(format!("{new_indent_str}{new_rhs}"))
Ok(format!("{new_indent_str}{new_rhs}"))
}
(None, Some(ref new_rhs)) => Some(format!("{new_indent_str}{new_rhs}")),
(None, None) if rhs_tactics == RhsTactics::AllowOverflow => {
(Err(_), Ok(ref new_rhs)) => Ok(format!("{new_indent_str}{new_rhs}")),
(Err(_), Err(_)) if rhs_tactics == RhsTactics::AllowOverflow => {
let shape = shape.infinite_width();
expr.rewrite(context, shape)
expr.rewrite_result(context, shape)
.map(|s| format!("{}{}", before_space_str, s))
}
(None, None) => None,
(Some(orig_rhs), _) => Some(format!("{before_space_str}{orig_rhs}")),
(Err(_), Err(new_rhs_err)) => Err(new_rhs_err),
(Ok(orig_rhs), _) => Ok(format!("{before_space_str}{orig_rhs}")),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Err(_), Err(new_rhs_err)) => Err(new_rhs_err),
refer to the comment in #6291

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a similar response: #6291 (comment). I think it's fine to use the 2nd error as the return, and I think adding a comment to explain that we could have chosen either would be nice.

@ytmimi ytmimi added GSoC Google Summer of Code pr-waiting-on-author and removed pr-not-reviewed labels Aug 29, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Sep 1, 2024

Thanks for leaving the note!

I've started the Diff Check
Edit: Diff Check Job passed ✅

@ytmimi ytmimi merged commit 1930514 into rust-lang:master Sep 1, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSoC Google Summer of Code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants