self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind, Path,
Visibility, VisibilityKind,
};
-use syntax::codemap::{BytePos, Span, NO_EXPANSION};
use syntax::ptr;
+use syntax::source_map::{BytePos, Span, NO_EXPANSION};
+use comment::filter_normal_code;
use rewrite::RewriteContext;
use shape::Shape;
}
}
+#[inline]
+pub fn format_async(is_async: ast::IsAsync) -> &'static str {
+ match is_async {
+ ast::IsAsync::Async { .. } => "async ",
+ ast::IsAsync::NotAsync => "",
+ }
+}
+
#[inline]
pub fn format_constness(constness: ast::Constness) -> &'static str {
match constness {
!$self.config.file_lines().is_all() && !$self
.config
.file_lines()
- .intersects(&$self.codemap.lookup_line_range($span))
+ .intersects(&$self.source_map.lookup_line_range($span))
};
}
// Wraps String in an Option. Returns Some when the string adheres to the
// Rewrite constraints defined for the Rewrite trait and None otherwise.
pub fn wrap_str(s: String, max_width: usize, shape: Shape) -> Option<String> {
- if is_valid_str(&s, max_width, shape) {
+ if is_valid_str(&filter_normal_code(&s), max_width, shape) {
Some(s)
} else {
None
}
}
+#[inline]
pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
match e.node {
ast::ExprKind::Call(ref e, _)
}
}
+#[inline]
pub fn starts_with_newline(s: &str) -> bool {
s.starts_with('\n') || s.starts_with("\r\n")
}
+
+#[inline]
+pub fn first_line_ends_with(s: &str, c: char) -> bool {
+ s.lines().next().map_or(false, |l| l.ends_with(c))
+}