Skip to content

Commit 32fa51a

Browse files
committed
Move Spanned to spanned.rs from lib.rs
1 parent df7d2be commit 32fa51a

File tree

9 files changed

+188
-173
lines changed

9 files changed

+188
-173
lines changed

src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syntax::{ast, ptr};
1717
use syntax::codemap::{BytePos, CodeMap, Span};
1818
use syntax::parse::classify;
1919

20-
use Spanned;
20+
use spanned::Spanned;
2121
use chains::rewrite_chain;
2222
use codemap::{LineRangeUtils, SpanUtils};
2323
use comment::{combine_strs_with_missing_comments, contains_comment, recover_comment_removed,

src/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::cmp::Ordering;
1313
use syntax::ast;
1414
use syntax::codemap::{BytePos, Span};
1515

16-
use Spanned;
16+
use spanned::Spanned;
1717
use codemap::SpanUtils;
1818
use comment::combine_strs_with_missing_comments;
1919
use config::IndentStyle;

src/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use syntax::{abi, ast, ptr, symbol};
1616
use syntax::ast::ImplItem;
1717
use syntax::codemap::{BytePos, Span};
1818

19-
use Spanned;
19+
use spanned::Spanned;
2020
use codemap::{LineRangeUtils, SpanUtils};
2121
use comment::{combine_strs_with_missing_comments, contains_comment, recover_comment_removed,
2222
recover_missing_comment_in_span, rewrite_missing_comment, FindUncommented};

src/lib.rs

Lines changed: 3 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ use std::rc::Rc;
3434

3535
use errors::{DiagnosticBuilder, Handler};
3636
use errors::emitter::{ColorConfig, EmitterWriter};
37-
use macros::MacroArg;
3837
use strings::string_buffer::StringBuffer;
3938
use syntax::ast;
40-
use syntax::codemap::{CodeMap, FilePathMapping, Span};
39+
use syntax::codemap::{CodeMap, FilePathMapping};
4140
use syntax::parse::{self, ParseSess};
4241

4342
use checkstyle::{output_footer, output_header};
4443
use config::Config;
4544
use filemap::FileMap;
4645
use issues::{BadIssueSeeker, Issue};
47-
use utils::{isatty, mk_sp, outer_attributes};
46+
use utils::isatty;
4847
use visitor::FmtVisitor;
4948

5049
pub use self::summary::Summary;
5150

5251
#[macro_use]
5352
mod utils;
5453
mod shape;
54+
mod spanned;
5555
pub mod config;
5656
pub mod codemap;
5757
pub mod filemap;
@@ -76,169 +76,6 @@ mod patterns;
7676
mod summary;
7777
mod vertical;
7878

79-
/// Spanned returns a span including attributes, if available.
80-
pub trait Spanned {
81-
fn span(&self) -> Span;
82-
}
83-
84-
macro_rules! span_with_attrs_lo_hi {
85-
($this:ident, $lo:expr, $hi:expr) => {
86-
{
87-
let attrs = outer_attributes(&$this.attrs);
88-
if attrs.is_empty() {
89-
mk_sp($lo, $hi)
90-
} else {
91-
mk_sp(attrs[0].span.lo(), $hi)
92-
}
93-
}
94-
}
95-
}
96-
97-
macro_rules! span_with_attrs {
98-
($this:ident) => {
99-
span_with_attrs_lo_hi!($this, $this.span.lo(), $this.span.hi())
100-
}
101-
}
102-
103-
macro_rules! implement_spanned {
104-
($this:ty) => {
105-
impl Spanned for $this {
106-
fn span(&self) -> Span {
107-
span_with_attrs!(self)
108-
}
109-
}
110-
}
111-
}
112-
113-
// Implement `Spanned` for structs with `attrs` field.
114-
implement_spanned!(ast::Expr);
115-
implement_spanned!(ast::Field);
116-
implement_spanned!(ast::ForeignItem);
117-
implement_spanned!(ast::Item);
118-
implement_spanned!(ast::Local);
119-
120-
impl Spanned for ast::Stmt {
121-
fn span(&self) -> Span {
122-
match self.node {
123-
ast::StmtKind::Local(ref local) => mk_sp(local.span().lo(), self.span.hi()),
124-
ast::StmtKind::Item(ref item) => mk_sp(item.span().lo(), self.span.hi()),
125-
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => {
126-
mk_sp(expr.span().lo(), self.span.hi())
127-
}
128-
ast::StmtKind::Mac(ref mac) => {
129-
let (_, _, ref attrs) = **mac;
130-
if attrs.is_empty() {
131-
self.span
132-
} else {
133-
mk_sp(attrs[0].span.lo(), self.span.hi())
134-
}
135-
}
136-
}
137-
}
138-
}
139-
140-
impl Spanned for ast::Pat {
141-
fn span(&self) -> Span {
142-
self.span
143-
}
144-
}
145-
146-
impl Spanned for ast::Ty {
147-
fn span(&self) -> Span {
148-
self.span
149-
}
150-
}
151-
152-
impl Spanned for ast::Arm {
153-
fn span(&self) -> Span {
154-
span_with_attrs_lo_hi!(self, self.pats[0].span.lo(), self.body.span.hi())
155-
}
156-
}
157-
158-
impl Spanned for ast::Arg {
159-
fn span(&self) -> Span {
160-
if items::is_named_arg(self) {
161-
utils::mk_sp(self.pat.span.lo(), self.ty.span.hi())
162-
} else {
163-
self.ty.span
164-
}
165-
}
166-
}
167-
168-
impl Spanned for ast::StructField {
169-
fn span(&self) -> Span {
170-
span_with_attrs_lo_hi!(self, self.span.lo(), self.ty.span.hi())
171-
}
172-
}
173-
174-
impl Spanned for ast::WherePredicate {
175-
fn span(&self) -> Span {
176-
match *self {
177-
ast::WherePredicate::BoundPredicate(ref p) => p.span,
178-
ast::WherePredicate::RegionPredicate(ref p) => p.span,
179-
ast::WherePredicate::EqPredicate(ref p) => p.span,
180-
}
181-
}
182-
}
183-
184-
impl Spanned for ast::FunctionRetTy {
185-
fn span(&self) -> Span {
186-
match *self {
187-
ast::FunctionRetTy::Default(span) => span,
188-
ast::FunctionRetTy::Ty(ref ty) => ty.span,
189-
}
190-
}
191-
}
192-
193-
impl Spanned for ast::TyParam {
194-
fn span(&self) -> Span {
195-
// Note that ty.span is the span for ty.ident, not the whole item.
196-
let lo = if self.attrs.is_empty() {
197-
self.span.lo()
198-
} else {
199-
self.attrs[0].span.lo()
200-
};
201-
if let Some(ref def) = self.default {
202-
return mk_sp(lo, def.span.hi());
203-
}
204-
if self.bounds.is_empty() {
205-
return mk_sp(lo, self.span.hi());
206-
}
207-
let hi = self.bounds[self.bounds.len() - 1].span().hi();
208-
mk_sp(lo, hi)
209-
}
210-
}
211-
212-
impl Spanned for ast::TyParamBound {
213-
fn span(&self) -> Span {
214-
match *self {
215-
ast::TyParamBound::TraitTyParamBound(ref ptr, _) => ptr.span,
216-
ast::TyParamBound::RegionTyParamBound(ref l) => l.span,
217-
}
218-
}
219-
}
220-
221-
impl Spanned for ast::LifetimeDef {
222-
fn span(&self) -> Span {
223-
let hi = if self.bounds.is_empty() {
224-
self.lifetime.span.hi()
225-
} else {
226-
self.bounds[self.bounds.len() - 1].span.hi()
227-
};
228-
mk_sp(self.lifetime.span.lo(), hi)
229-
}
230-
}
231-
232-
impl Spanned for MacroArg {
233-
fn span(&self) -> Span {
234-
match *self {
235-
MacroArg::Expr(ref expr) => expr.span(),
236-
MacroArg::Ty(ref ty) => ty.span(),
237-
MacroArg::Pat(ref pat) => pat.span(),
238-
}
239-
}
240-
}
241-
24279
pub enum ErrorKind {
24380
// Line has exceeded character limit (found, maximum)
24481
LineOverflow(usize, usize),

src/patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd};
1212
use syntax::codemap::{self, BytePos, Span};
1313
use syntax::ptr;
1414

15-
use Spanned;
15+
use spanned::Spanned;
1616
use codemap::SpanUtils;
1717
use comment::FindUncommented;
1818
use expr::{can_be_overflowed_expr, rewrite_call_inner, rewrite_pair, rewrite_unary_prefix,

0 commit comments

Comments
 (0)