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

[unstable option] where_single_line #3359

Open
scampi opened this issue Feb 13, 2019 · 6 comments
Open

[unstable option] where_single_line #3359

scampi opened this issue Feb 13, 2019 · 6 comments
Labels
unstable option tracking issue of an unstable option

Comments

@scampi
Copy link
Contributor

scampi commented Feb 13, 2019

Tracking issue for unstable option: where_single_line

@scampi scampi added the unstable option tracking issue of an unstable option label Feb 13, 2019
@scampi scampi changed the title [unstable option] unstable option: where_single_line [unstable option] where_single_line Feb 18, 2019
@dhardy
Copy link

dhardy commented Jan 1, 2020

Is this supposed to allow multiple bounds on a single line (similar to how function arguments, struct fields etc. are only split if they won't fit on a single line)?

Here's an example diff from applying rustfmt to Rand which looks kind of weird (splits one already short line, and collapses a block into a single, longer line):

@@ -207,13 +235,11 @@ pub trait Distribution<T> {
     /// }
     /// ```
     fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
-    where R: Rng, Self: Sized
+    where
+        R: Rng,
+        Self: Sized,
     {
-        DistIter {
-            distr: self,
-            rng,
-            phantom: ::core::marker::PhantomData,
-        }
+        DistIter { distr: self, rng, phantom: ::core::marker::PhantomData }
     }
 }

@dhardy
Copy link

dhardy commented Jan 1, 2020

With this option turned on, I think the following change to the where condition should not have happened? Or is this a different case since the where directly follows a )?

        fn test_samples<T: SampleUniform + Copy + core::fmt::Debug + PartialEq>(
-            lb: T, ub: T, expected_single: &[T], expected_multiple: &[T]
-        )
-        where Uniform<T>: Distribution<T>
+            lb: T,
+            ub: T,
+            expected_single: &[T],
+            expected_multiple: &[T],
+        ) where
+            Uniform<T>: Distribution<T>,
         {

@CJKay
Copy link

CJKay commented May 20, 2022

I'm also struggling to figure out what this option actually does. I expected these bounds to all be on the same line:

 impl<S, T, I, O, Ix> Machine for DfaMachine<S, T, I, O, Ix>
-where I: Iterator, O: Iterator, Ix: IndexType,
+where
+    I: Iterator,
+    O: Iterator,
+    Ix: IndexType,
 {
     type State = S;
     type Transition = T;

@calebcartwright
Copy link
Member

Thank you both for sharing, and apologies @dhardy for missing the prior questions (suspect it got list in the github inbox noise). I'm not sure offhand if the behavior shared above is a bug or if we've simply got spectacularly underspecified docs for the option, but I vaguely remember having a similar thought/question in the past over the formatting of a type alias.

@InsertCreativityHere
Copy link

I've been using this option for a while under the impression that it means:
"if there is only a single where condition, put it on one line"
otherwise format it like normal.

I don't want to speak on behalf of the author, but this is the behavior I've consistently observed from it,
and honestly, is the behavior I personally want.

I think supporting a 3rd option (that always puts all clauses on one line), and updating the docs might go a long way here.

@KaitlynEthylia
Copy link

I think it would look neater to have it based on length rather than just if there's one, as stacking two pretty short bounds on top of each other looks less than ideal to me.

I also wonder how this could interact with brace_style. I would personally want it to be on the same line if the where clause is on a single line, but on the next line of the where clause is expanded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unstable option tracking issue of an unstable option
Projects
None yet
Development

No branches or pull requests

6 participants