use comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar};
use config::IndentStyle;
use expr::rewrite_call;
-use lists::{extract_post_comment, extract_pre_comment, get_comment_end};
+use lists::extract_pre_comment;
use macros::convert_try_mac;
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use utils::{
- first_line_width, last_line_extendable, last_line_width, mk_sp, trimmed_last_line_width,
- wrap_str,
+ first_line_width, last_line_extendable, last_line_width, mk_sp, rewrite_ident,
+ trimmed_last_line_width, wrap_str,
};
use std::borrow::Cow;
ChainItemKind::MethodCall(ref segment, ref types, ref exprs) => {
Self::rewrite_method_call(segment.ident, types, exprs, self.span, context, shape)?
}
- ChainItemKind::StructField(ident) => format!(".{}", ident.name),
- ChainItemKind::TupleField(ident, nested) => {
- format!("{}.{}", if nested { " " } else { "" }, ident.name)
- }
+ ChainItemKind::StructField(ident) => format!(".{}", rewrite_ident(context, ident)),
+ ChainItemKind::TupleField(ident, nested) => format!(
+ "{}.{}",
+ if nested { " " } else { "" },
+ rewrite_ident(context, ident)
+ ),
ChainItemKind::Comment(ref comment, _) => {
rewrite_comment(comment, false, shape, context.config)?
}
format!("::<{}>", type_list.join(", "))
};
- let callee_str = format!(".{}{}", method_name, type_str);
+ let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
rewrite_call(context, &callee_str, &args[1..], span, shape)
}
}
s.chars().all(|c| c == '?')
}
+ fn is_post_comment(s: &str) -> bool {
+ let comment_start_index = s.chars().position(|c| c == '/');
+ if comment_start_index.is_none() {
+ return false;
+ }
+
+ let newline_index = s.chars().position(|c| c == '\n');
+ if newline_index.is_none() {
+ return true;
+ }
+
+ comment_start_index.unwrap() < newline_index.unwrap()
+ }
+
fn handle_post_comment(
post_comment_span: Span,
post_comment_snippet: &str,
// No post comment.
return;
}
- // HACK: Treat `?`s as separators.
- let trimmed_snippet = post_comment_snippet.trim_matches('?');
- let comment_end = get_comment_end(trimmed_snippet, "?", "", false);
- let maybe_post_comment = extract_post_comment(trimmed_snippet, comment_end, "?")
- .and_then(|comment| {
- if comment.is_empty() {
- None
- } else {
- Some((comment, comment_end))
- }
- });
-
- if let Some((post_comment, comment_end)) = maybe_post_comment {
+ let trimmed_snippet = trim_tries(post_comment_snippet);
+ if is_post_comment(&trimmed_snippet) {
children.push(ChainItem::comment(
post_comment_span,
- post_comment,
+ trimmed_snippet.trim().to_owned(),
CommentPosition::Back,
));
- *prev_span_end = *prev_span_end + BytePos(comment_end as u32);
+ *prev_span_end = post_comment_span.hi();
}
}