Merge pull request #1593 from topecongiro/issue-1439

Allow comments after where clause
This commit is contained in:
Nick Cameron
2017-05-27 13:34:50 +12:00
committed by GitHub
3 changed files with 27 additions and 3 deletions
+6 -2
View File
@@ -500,7 +500,11 @@ fn format_variant(&self, field: &ast::Variant) -> Option<String> {
}
}
pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -> Option<String> {
pub fn format_impl(context: &RewriteContext,
item: &ast::Item,
offset: Indent,
where_span_end: Option<BytePos>)
-> Option<String> {
if let ast::ItemKind::Impl(_, _, ref generics, ref trait_ref, _, ref items) = item.node {
let mut result = String::new();
// First try to format the ref and type without a split at the 'for'.
@@ -527,7 +531,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
"{",
false,
last_line_width(&ref_and_type) == 1,
None));
where_span_end));
if try_opt!(is_impl_single_line(context, &items, &result, &where_clause_str, &item)) {
result.push_str(&where_clause_str);
+10 -1
View File
@@ -19,6 +19,7 @@
use {Indent, Shape};
use utils;
use codemap::{LineRangeUtils, SpanUtils};
use comment::FindUncommented;
use config::Config;
use rewrite::{Rewrite, RewriteContext};
use comment::rewrite_comment;
@@ -249,7 +250,15 @@ pub fn visit_item(&mut self, item: &ast::Item) {
}
ast::ItemKind::Impl(..) => {
self.format_missing_with_indent(source!(self, item.span).lo);
if let Some(impl_str) = format_impl(&self.get_context(), item, self.block_indent) {
let snippet = self.get_context().snippet(item.span);
let where_span_end =
snippet
.find_uncommented("{")
.map(|x| (BytePos(x as u32)) + source!(self, item.span).lo);
if let Some(impl_str) = format_impl(&self.get_context(),
item,
self.block_indent,
where_span_end) {
self.buffer.push_str(&impl_str);
self.last_pos = source!(self, item.span).hi;
}
+11
View File
@@ -5,3 +5,14 @@
impl<K, V, NodeRef: Deref<Target = Node<K, V>>> Handle<NodeRef, handle::Edge, handle::Internal> {
// Keep this.
}
impl<V> Test<V>
where V: Clone // This comment is NOT removed by formating!
{
pub fn new(value: V) -> Self {
Test {
cloned_value: value.clone(),
value: value,
}
}
}