Skip to content

Weird newline in string literal #1210

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

Closed
nrc opened this issue Nov 7, 2016 · 4 comments
Closed

Weird newline in string literal #1210

nrc opened this issue Nov 7, 2016 · 4 comments
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce poor-formatting

Comments

@nrc
Copy link
Member

nrc commented Nov 7, 2016

     fn cxx(&self, target: &str) -> &Path {
         match self.cxx.get(target) {
             Some(p) => p.path(),
-            None => panic!("\n\ntarget `{}` is not configured as a host,
-                            only as a target\n\n", target),
+            None => {
+                panic!("\n\ntarget `{}` is not configured as a host,
+                            \
+                        only as a target\n\n",
+                       target)
+            }
         }
     }
@nrc nrc added bug Panic, non-idempotency, invalid code, etc. poor-formatting labels Nov 7, 2016
@nrc nrc added the only-with-option requires a non-default option value to reproduce label Jan 26, 2017
@topecongiro
Copy link
Contributor

In 0.8.3 (), rustfmt formarts

impl Foo {
    fn cxx(&self, target: &str) -> &Path {
        match self.cxx.get(target) {
            Some(p) => p.path(),
            None => panic!("\n\ntarget `{}` is not configured as a host,
                            only as a target\n\n", target),
        }
    }
}

to

impl Foo {
    fn cxx(&self, target: &str) -> &Path {
        match self.cxx.get(target) {
            Some(p) => p.path(),
            None => {
                panic!("\n\ntarget `{}` is not configured as a host,
                            only as a target\n\n",
                       target)
            }
        }
    }
}

so the weird newline is gone.

@nrc
Copy link
Member Author

nrc commented Apr 6, 2017

This only reproduces with the format_strings option set.

@topecongiro
Copy link
Contributor

Just setting format_strings does not reproduce the above bug anymore.
However, when the max_width is set to smaller value, the bug gets reproduced.

rustfmt.toml:

format_strings = true
max_width = 50

Output:

impl Foo {
    fn cxx(&self, target: &str) -> &Path {
        match self.cxx.get(target) {
            Some(p) => p.path(),
            None => {
                panic!("\n\ntarget `{}` is not \
                        configured as a host,
                        \
                        only as a target\n\n",
                       target)
            }
        }
    }
}

@scampi
Copy link
Contributor

scampi commented Jul 4, 2018

@nrc @topecongiro I am having a look at this issue and I was wondering if you could clarify the signature of rewrite_string which takes in addition to a format specification an optional max_width: https://github.com/rust-lang-nursery/rustfmt/blob/f711078126f95bd580c69c39af9fc16e3f83c859/src/string.rs#L47-L51

However, it seems that the fmt.width property is enough:

Could it be that argument is a left-over of a previous refactoring ? Could it be removed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce poor-formatting
Projects
None yet
Development

No branches or pull requests

3 participants