-
Notifications
You must be signed in to change notification settings - Fork 56
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
function calls #65
Comments
Suggestion from @vitiral (#73):
rustfmt currently uses the Method 1 way too often. I'm not sure the right balance here. Like @joshtriplett said in #47 , you really want to define "simple". IMO "simple" would be:
|
I think we probably want to use block rather than visual indentation. As discussed on other issues, we should avoid putting multiple args on one line if we are in multi-line mode. |
@nrc so you're saying it will use (approximately) the format suggested there? That would be awesome! Edit: I think that an exception should be if the end of the
should instead be:
|
I'm proposing:
I don't think we should make such an exception for short names - they tend to be rare, and when they do occur they tend not to spill onto multiple lines (anyone who makes a one-char function name which takes enough complex arguments to trigger multi-line formatting deserves what they get). |
that's a good point. I would like to suggest that we do:
I think that anywhere people are using just For something like a struct, it makes sense for them to be their own line because they are passed in Agh... as I talk about it more I am not sure, but I really don't want something like this:
to become this:
just because I changed |
In the context of function definitions, we talked about allowing an intermediate style, where if breaking the arguments onto their own line made them fit on one line, they didn't require breaking onto a line each. We ended up dropping that for simplicity. I wonder if we should reconsider it for function calls? (And for consistency, function definitions, because having the two differ on that point seems odd.) Function calls make a compelling case for it; I do prefer this: long_function_name(
arg1, arg2, arg3
); instead of this: long_function_name(
arg1,
arg2,
arg3,
); On the other hand, I'm really tempted to just go with "if you have to break onto multiple lines, use one line per argument", perhaps along with what we bounced around as a |
I prefer not to for the same reason as before - you save some vertical space at the expense of clarity. It is rare for arguments to calls to be single variables, much more likely to be sub-expressions, and there I think you get into the complexity argument for using multiple lines quickly. |
OK, an attempt at a somewhat full description: A function call consists of a callee and expression arguments:
A method call has a receiver a method name, generic args, and expr args:
To simplify things, I'm going to discuss only the function form, for methods we assume
|
I like the rules above, but I don't see the reasoning behind: "If the callee terminates with punctuation, put a space before the (." |
@gsingh93 Same here. In fact, there's a relatively common case where I specifically prefer the opposite: calling a function pointer field. (foo.x)(42) |
Can we clarify the question I raised above, and then move to FCP? |
@gsingh93 I don't know what that refers to either. And it seems directly untrue; for instance, |
I'm not sure, would enum constructors be covered by this issue? I don't like the way rustfmt treats code like: return Ok(FancyStruct {
member_a: stuff,
member_b: stuff,
}); it gets reformated to: return Ok(
FancyStruct {
member_a: stuff,
member_b: stuff,
}
); And no way to turn it off :( |
Entering FCP based on #65 (comment) (note: edited to remove punctuation/spacing thing). |
And static method calls, method calls should be specified separately.
The text was updated successfully, but these errors were encountered: