I've decided to try it on one of my projects. Personally, I like how it worked very much but there are few things which I couldn't find out how to tweak and which make it unsuitable for me yet (everything below except "minor points").
First, as was already mentioned, is the rightward drift, for example:
- try!(write!(
- target, " {}=\"{}\"",
- attr.name.repr_display(),
- if self.config.perform_escaping { escape_str_attribute(attr.value) }
- else { Cow::Borrowed(attr.value) }
- ))
+ try!(write!(target,
+ " {}=\"{}\"",
+ attr.name.repr_display(),
+ if self.config.perform_escaping {
+ escape_str_attribute(attr.value)
+ } else {
+ Cow::Borrowed(attr.value)
+ }))
and
- let attr = Attribute::new(
- Name::qualified("attribute", "urn:namespace", Some("n")),
- "its value with > & \" ' < weird symbols"
- );
-
- assert_eq!(
- &*attr.to_string(),
- "{urn:namespace}n:attribute=\"its value with > & " ' < weird symbols\""
- )
+ let attr = Attribute::new(Name::qualified("attribute", "urn:namespace", Some("n")),
+ "its value with > & \" ' < weird symbols");
+
+ assert_eq!(&*attr.to_string(),
+ "{urn:namespace}n:attribute=\"its value with > & " ' < \
+ weird symbols\"")
I prefer having long function calls to be indented like blocks, and indeed there is an option for this (fn_args_layout), however it also affects function declarations which begin to be always formatted as blocks, which I don't want - I like Visual layout for function signatures.
Second point I don't like is that rustfmt inserts spaces in associated types inside constraints:
- fn extend<I: IntoIterator<Item=Value>>(&mut self, it: I) {
+ fn extend<I: IntoIterator<Item = Value>>(&mut self, it: I) {
I dislike this very much because without spaces it is visually clear that e.g. IntoIterator<Item=Value> is a single constraint; much less so with them. This behavior doesn't seem to be tweakable at all.
There is also a bug, as far as I can see: doc comments on fields of enum struct variants is off:
StartDocument {
- /// XML version.
- ///
- /// If XML declaration is not present, defaults to `Version10`.
+ /// XML version.
+ ///
+ /// If XML declaration is not present, defaults to `Version10`.
version: XmlVersion,
I probably should report it, if it isn't already.
I was also under impression that chain_base_indent defines how chained method calls are indented - I prefer them to be indented like blocks, on the next line:
some_long.expression.method()
.method2()
.method3()
However, this option doesn't seem to affect chained calls:
- let attributes: Vec<String> = attributes.iter().map(
- |a| format!("{} -> {}", a.name, a.value)
- ).collect();
+ let attributes: Vec<String> = attributes.iter()
+ .map(|a| format!("{} -> {}", a.name, a.value))
+ .collect();
It would be nice if the following situations inside a match were also tweakable but this is a minor point:
- "xml"|"xmL"|"xMl"|"xML"|"Xml"|"XmL"|"XMl"|"XML"
- if self.encountered_element || self.parsed_declaration =>
+ "xml" | "xmL" | "xMl" | "xML" | "Xml" | "XmL" | "XMl" | "XML" if self.encountered_element ||
+ self.parsed_declaration =>
I mean the positioning of pattern guard clause - I prefer the original one.
This:
- if self.encountered_element && self.st == State::OutsideTag { // all is ok
+ if self.encountered_element && self.st == State::OutsideTag {
+ // all is ok
was really unexpected. I'd expect comments to be kept in place.
I think it would be great if there was the following logic for formatting chained calls: if the part before the last dot in the first line is short, like here:
something.emitter
.namespace_stack_mut()
.push_empty()
.checked_target()
.extend(namespace.as_ref())
then chained calls should be aligned by this dot. Otherwise, they should be indented as blocks:
some_function(a.long_something.whatever)
.chained_method()
.another_one()
Another minor point is to allow keeping vertical structure in multiple sequential definitions or pattern match arms. For example:
ClosingSubstate::First => match c {
'-' => self.move_to(State::CommentClosing(ClosingSubstate::Second)),
- _ => self.move_to_with_unread(State::Normal, &[c], Token::Character('-'))
+ _ => self.move_to_with_unread(State::Normal, &[c], Token::Character('-')),
},
here I'd prefer => to be aligned.
Anyway, most of this is probably only my preferences, so certainly I don't expect them to be fixed soon
And regardless of that, I think that rustfmt is indeed a very powerful tool, and it works really great.