Skip to content

Fix pretty printing unsafe match arms #19215

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

Merged
merged 2 commits into from
Nov 23, 2014
Merged

Fix pretty printing unsafe match arms #19215

merged 2 commits into from
Nov 23, 2014

Conversation

aochagavia
Copy link
Contributor

Closes #19077

I would appreciate any guidance on how to write a test for this. I saw some examples in test/pretty, but there are different ways to test... With or without .pp files, with a pp-exact comment, etc.

@rust-highfive
Copy link
Contributor

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@aochagavia
Copy link
Contributor Author

The warning of rust-highfive is not correct... I guess he performs a case-insensitive search for the word unsafe.

@ghost
Copy link

ghost commented Nov 22, 2014

@aochagavia I think pp-exact is probably the best way to go. With your change something like this:

fn main() {

    match true {
        true if true => (),
        false => unsafe { },
        true => { }
        false => (),
    }

}

should pretty-print as-is.

(it may be worth tweaking the pretty printer not to put the extra whitespace in between { } if you feel up for it)

@aochagavia
Copy link
Contributor Author

A problem here is that pretty printing seems to be broken for match.

For example, the following code:

fn main() {
    match true {
        true => { }
        false => { }
    }
}

Is formatted as:

fn main() { match true { true => { } false => { } } }

@ghost
Copy link

ghost commented Nov 22, 2014

@aochagavia It's not really broken so much as it's trying to be space efficient - this is probably an artifact of an old Rust coding style. If the match expression is sufficiently big, the pretty printer will use line-breaks. I tested the example I pasted and I think it should work well for your test.

@aochagavia
Copy link
Contributor Author

Why is it better to have {} instead of { }? Is there a convention about that?

@aochagavia
Copy link
Contributor Author

btw. I have added the test

@ghost
Copy link

ghost commented Nov 23, 2014

@aochagavia I think there's a de-facto convention towards {}. But let's leave this for another day. Thanks!

@bors bors merged commit d678684 into rust-lang:master Nov 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pretty printer strips trailing commas from unsafe match arms
3 participants