-
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
Single-line where
.
#74
Comments
Am I right to assume that for simple functions the where clause will be inline? So that with this proposal we have another intermediate step between "short fn" and "complex fn"? I can see where you are coming from (too many lines for the where clauses), but I would prefer not to do this, as it adds another special case and also the potential for diff churn each time we add a new clause. (Please note that having the where clause at the end of the return type's line could also make this nicer.) |
I guess I didn't make clear that I'm only talking about single-bound fn blah()
where T: Abc, U: Abc, F: Abc, // long line is not allowed |
See redox-os/tfs@a929e98 for examples. |
Ah, okay. I'd say fn key_matches(&self, key: &K) -> bool
where K: PartialEq { can be put on one line, like fn key_matches(&self, key: &K) -> bool where K: PartialEq { The next fn, fn scan_mut<F>(&self, key: &K, matches: F) -> RwLockWriteGuard<Bucket<K, V>>
where F: Fn(&Bucket<K, V>) -> bool {
let hash = self.hash(key);
// .... is too long for one line and has a 'complex' constraint (as do many fns taking closures – is this common case we should optimize for?). I think your suggestion is a good suggestion for that case. I's a bit unfortunate that adding another constraint will result in 4 changed lines (+4 -1), though: fn scan_mut<F>(&self, key: &K, matches: F) -> RwLockWriteGuard<Bucket<K, V>>
where
F: Fn(&Bucket<K, V>) -> bool,
K: Hash,
{
let hash = self.hash(key);
// .... Because of that, and because I think the currently suggested version (basically the previous example without the second constraint) still looks okay, I'm wary of introducing an in-between version. |
I dislike that, because it's harder to scan for the return type. |
Also, it clogs the diff. |
Yeah, I really don't want to have |
I think we discussed this option in the @rust-lang-nursery/style What does the rest of the team think? |
OK, so this came up in the style meeting while discussing other issues. While we still agree that this should not be the default, we think that Rustfmt should support it as an option, in particular for people who prefer to use I see the following constraints:
In terms of formatting I think the only non-obvious point is that there should be no trailing comma. |
On May 15, 2017 3:50:18 PM PDT, Nick Cameron ***@***.***> wrote:
OK, so this came up in the style meeting while discussing other issues.
While we still agree that this should not be the default, we think that
Rustfmt should support it as an option, in particular for people who
prefer to use `where` clauses all the time, rather than putting simple
bounds inline. Furthermore, it seems that it is a common enough option
(and complicated enough) that we should specify how it works, rather
than just hacking it in Rustfmt.
I see the following constraints:
* there must be exactly one clause of the where clause
* the whole signature of the item including the where clause must fit
on one line (e.g., multi-line args also force a multi-line where
clause)
* do we want to enforce a simplicity constraint on the where clause?
I.e., to prevent something like `where T: Copy + Clone + 'a + 'b +
?Sized` to be on one line?
In terms of formatting I think the only non-obvious point is that there
should be no trailing comma.
For the first two: agreed on both counts.
For the third: no, I don't think so.
|
For fn foo<T, U>(in: U) -> T
where T: Default,
U: MyTrait,
{
} I like the trailing comma because I like the consistency (the only place I drop it are for single-line The hoisted |
Entering FCP that this will be an option supported by Rustfmt, but off by default. When switched on it has the following constraints:
The formatting would be that the where clause starts at the same indent as
|
https://users.rust-lang.org/t/new-style-guidelines/10037/46?u=ticki
The text was updated successfully, but these errors were encountered: