Skip to content

Format loops #128

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 1 commit into from
Jul 15, 2015
Merged

Format loops #128

merged 1 commit into from
Jul 15, 2015

Conversation

marcusklaas
Copy link
Contributor

This was previously attempted by @chellmuth in https://github.com/nrc/rustfmt/pull/103. It hasn't seen any activity in three weeks, so I've taken the liberty to try as well.

My approach was as suggested in https://github.com/nrc/rustfmt/pull/103#issuecomment-111297423. While it is not optimal performance-wise, it has a low complexity. If this deemed acceptable for now, we can use it to easily format a whole class of expressions like if-else statements and even match blocks!

// Stringify visitor
let file_name = context.codemap.span_to_filename(self.span);
let string_buffer = visitor.changes.get_mut(&file_name);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_mut is surprizing here. Maybe write a ChangeSet::get or simply visitor.changes.file_map.get(&filename).unwrap ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed; fixed.

@marcusklaas
Copy link
Contributor Author

Formatting labels is currently blocked on rust-lang/rust#27042.

@@ -99,6 +99,10 @@ impl<'a> ChangeSet<'a> {
self.push_str(&file_name, text)
}

pub fn get(&mut self, file_name: &str) -> &StringBuffer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should document that this panics if file_name is unknown (also for get_mut)

@nrc
Copy link
Member

nrc commented Jul 14, 2015

NIce! The relatively small amount of code is a good sign for the new approach :-)

@nrc
Copy link
Member

nrc commented Jul 15, 2015

@marcusklaas this just needs a comment on get before I merge

@nrc nrc mentioned this pull request Jul 15, 2015
@marcusklaas
Copy link
Contributor Author

Wait, shouldn't we figure out how to do this properly first?

@nrc
Copy link
Member

nrc commented Jul 15, 2015

@marcusklaas what is 'this'? The FmtVisitor stuff? I'd be happy to see that as a separate PR and land this as is. Or did you have something else in mind?

@marcusklaas
Copy link
Contributor Author

That's what I meant, yea. I'll push the comment in a bit then.

@marcusklaas
Copy link
Contributor Author

Updated!

@nrc
Copy link
Member

nrc commented Jul 15, 2015

Thanks!

nrc added a commit that referenced this pull request Jul 15, 2015
@nrc nrc merged commit e4a6f96 into rust-lang:master Jul 15, 2015
@marcusklaas marcusklaas deleted the subexpr branch July 15, 2015 22:10
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.

3 participants