-
Notifications
You must be signed in to change notification settings - Fork 911
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
Consider omitting trailing commas in function calls of one argument #3796
Comments
Thank you for creating a feature request to rustfmt! I am sorry to say, however, that we are unlikely to accept this feature. One of the core design principles of rustfmt is consistency, and I feel that this feature does not have enough benefit to break it.
Concerning a builder pattern, I think that we can just add a new element in the middle of the method chain, instead of appending it. That way the trailing comma should not bother you. On a side note, it seems to me that the current behavior of |
Okay, understandable. Thank you for your quick reply! Adding calls to Thanks also for the references to Black’s behavior; that’s great to |
Hi, I am looking for the solution, any way to disable the trailing comma inside function call? It bothers me much. fn on_rsp_user_login(
&mut self,
pRspUserLogin: *mut CThostFtdcRspUserLoginField,
pRspInfo: *mut CThostFtdcRspInfoField,
nRequestID: ::std::os::raw::c_int,
bIsLast: bool, <==== HERE, I DON'T WHAT THIS COMMA!
) {
debug!("user login");
self.tx.send(Event::UserLogin).unwrap();
} |
@sweihub you can try setting fn on_rsp_user_login(
&mut self,
pRspUserLogin: *mut CThostFtdcRspUserLoginField,
pRspInfo: *mut CThostFtdcRspInfoField,
nRequestID: ::std::os::raw::c_int,
bIsLast: bool
) {
debug!("user login");
self.tx.send(Event::UserLogin).unwrap();
} |
@ytmimi Hi, thanks for your suggestion, unfortunately, it dose't work at all, and I'm using the nightly build already. The
|
@sweihub The examples listed in the docs use functions. Perhaps the docs need some clarification, but If you'd like to continue the discussion I think opening a new issue would be best. |
Builder patterns are common in Rust’s standard library and ecosystem.
Here are a few real (adapted) examples, with current
rustfmt
output(version 1.3.0-stable):
Unfortunately, in all these cases the trailing comma is actively
unhelpful. The common modification pattern for such builders is not
adding an additional argument to the enclosing function call, but rather
additional mutations to the builder: like
.stderr(Stdio::piped())
toCommand
, or.short("v")
toArg
, or.contents_first(true)
toWalkDir
. In such a case, one must remove the trailing commainserted by
rustfmt
before adding the desired change, and of courserustfmt
will insert a new trailing comma after that.I’m a big advocate for trailing commas when they make sense, which is
most of the time—but the friction here is notable. Perhaps
rustfmt
could accommodate this pattern by omitting trailing commas in function
calls of one argument. Python’s
black
is quite similar torustfmt
inboth spirit and output, and it follows this guideline (as of v19.3);
here’s an example.
I will be happy to contribute this change if it would be entertained.
(#3166 is related, but this is a feature request for a general pattern.)
The text was updated successfully, but these errors were encountered: