Implement Spanned for ast::StructField and ast::Field
@@ -48,6 +48,7 @@ use filemap::FileMap;
use visitor::FmtVisitor;
use config::Config;
use checkstyle::{output_header, output_footer};
+use utils::mk_sp;
pub use self::summary::Summary;
@@ -112,6 +113,28 @@ impl Spanned for ast::Arg {
}
}
+impl Spanned for ast::StructField {
+ fn span(&self) -> Span {
+ if self.attrs.is_empty() {
+ mk_sp(self.span.lo, self.ty.span.hi)
+ } else {
+ // Include attributes and doc comments, if present
+ mk_sp(self.attrs[0].span.lo, self.ty.span.hi)
+ }
+ }
+}
+
+impl Spanned for ast::Field {
+ fn span(&self) -> Span {
+ let lo = if self.attrs.is_empty() {
+ self.span.lo
+ } else {
+ self.attrs[0].span.lo
+ };
+ mk_sp(lo, self.span.hi)
+ }
+}
+
#[derive(Copy, Clone, Debug)]
pub struct Indent {
// Width of the block indent, in characters. Must be a multiple of
