-
Notifications
You must be signed in to change notification settings - Fork 931
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
Format loops #128
Conversation
// Stringify visitor | ||
let file_name = context.codemap.span_to_filename(self.span); | ||
let string_buffer = visitor.changes.get_mut(&file_name); | ||
|
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; fixed.
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 { |
There was a problem hiding this comment.
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)
NIce! The relatively small amount of code is a good sign for the new approach :-) |
@marcusklaas this just needs a comment on |
Wait, shouldn't we figure out how to do this properly first? |
@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? |
That's what I meant, yea. I'll push the comment in a bit then. |
Updated! |
Thanks! |
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!