-
Notifications
You must be signed in to change notification settings - Fork 899
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
Add option to break after = in assignment #3514
Comments
Indeed, I was surprised when trying to customize my
|
I'm also looking for an option to prevent the following line-break after a long expression assignment (once it reaches past the 80-character line-width rule): mod tests {
#[test]
fn test1() {
let principal =
Principal::new(ID::new_v4(), RoleDiscriminants::Consumer);
}
} I would rather enforce this style with block indentation: mod tests {
#[test]
fn test1() {
let principal = Principal::new(
ID::new_v4(),
RoleDiscriminants::Consumer
);
}
} Is it possible to enforce arguments are placed on newlines instead of the entire expression put onto a new line? |
+1 for this. Sometimes, async and lambdas need to be differentiated from simple multi-line allocations For example: let logic_invoked_immediately/* sometimes-great-IDE-supported-long-inlay-hint-inserted-here */ = if let Some(something) = do_something {
something
}else {
fallback
};
let logic_run_later/* sometimes-great-IDE-supported-long-inlay-hint-inserted-here */ = |param_1| {
do_ops_with(¶m_1);
param_1.do_something_else();
param_1
};
let this_one_differentiates_from_immediately_invoked_logics =
|param_1| {
do_ops_with(¶m_1);
param_1.do_something_else();
param_1
};
let this_might_be_executed_later_either =
async move {
do_some_async_calc().await
}; CLion rust plugin formatter is much more permissive on these kind of line breaks, IMO it helps me a lot to improve readability and reduce confusions from any logic's execution points. |
+1 on this, although I want to use this option to prevent precisely the "nicer" way you suggested (I dislike it). |
I would like to see an option in rustfmt to break after the
=
in an assignment when the right-hand-side is "complex". I admit I don't know what "complex" is — possibly if the right-hand-side is subject to block/visual formatting. Here are a couple examples:To me, it would be nicer to see this as:
In both cases, it seems more readable to me to keep the block together at the same indent level, especially when the variable name gets long.
Compare
You can also replace long variable names with patterns or reasonable variables with type hints.
To be clear, I want to keep block formatting. I just would like the option to have the block start indented on the next line.
PS. I didn't want to include this as a motivating example, because it's hardly rustfmt's fault, but editors like IntelliJ will insert "smart" type hints inline automatically. This pads out the line length in a way that rustfmt can't see, and it's why I don't suggest basing this on line length, but rather on whether the right-hand-side is "complex", block-formatted, or something like that.
The text was updated successfully, but these errors were encountered: