Skip to content

Commit 8981fea

Browse files
committed
rustfmt?
1 parent 5fc5f21 commit 8981fea

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/tools/rustfmt/src/spanned.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ impl<T> Spanned for source_map::Spanned<T> {
2727
macro_rules! span_with_attrs_lo_hi {
2828
($this:ident, $lo:expr, $hi:expr) => {{
2929
let attrs = outer_attributes(&$this.attrs);
30-
if attrs.is_empty() {
31-
mk_sp($lo, $hi)
30+
if let Some(attr) = attrs.first() {
31+
mk_sp(attr.span.lo(), $hi)
3232
} else {
33-
mk_sp(attrs[0].span.lo(), $hi)
33+
mk_sp($lo, $hi)
3434
}
3535
}};
3636
}
@@ -68,10 +68,10 @@ impl Spanned for ast::Stmt {
6868
mk_sp(expr.span().lo(), self.span.hi())
6969
}
7070
ast::StmtKind::MacCall(ref mac_stmt) => {
71-
if mac_stmt.attrs.is_empty() {
72-
self.span
71+
if let Some(attr) = mac_stmt.attrs.first() {
72+
mk_sp(attr.span.lo(), self.span.hi())
7373
} else {
74-
mk_sp(mac_stmt.attrs[0].span.lo(), self.span.hi())
74+
self.span
7575
}
7676
}
7777
ast::StmtKind::Empty => self.span,
@@ -93,10 +93,10 @@ impl Spanned for ast::Ty {
9393

9494
impl Spanned for ast::Arm {
9595
fn span(&self) -> Span {
96-
let lo = if self.attrs.is_empty() {
97-
self.pat.span.lo()
96+
let lo = if let Some(attr) = self.attrs.first() {
97+
attr.span.lo()
9898
} else {
99-
self.attrs[0].span.lo()
99+
self.pat.span.lo()
100100
};
101101
let hi = if let Some(body) = &self.body {
102102
body.span.hi()
@@ -119,15 +119,15 @@ impl Spanned for ast::Param {
119119

120120
impl Spanned for ast::GenericParam {
121121
fn span(&self) -> Span {
122-
let lo = match self.kind {
123-
_ if !self.attrs.is_empty() => self.attrs[0].span.lo(),
124-
ast::GenericParamKind::Const { kw_span, .. } => kw_span.lo(),
122+
let lo = match (&self.kind, self.attrs.first()) {
123+
(_, Some(attr)) => attr.span.lo(),
124+
(ast::GenericParamKind::Const { kw_span, .. }, _) => kw_span.lo(),
125125
_ => self.ident.span.lo(),
126126
};
127-
let hi = if self.bounds.is_empty() {
128-
self.ident.span.hi()
127+
let hi = if let Some(bound) = self.bounds.last() {
128+
bound.span().hi()
129129
} else {
130-
self.bounds.last().unwrap().span().hi()
130+
self.ident.span.hi()
131131
};
132132
let ty_hi = if let ast::GenericParamKind::Type {
133133
default: Some(ref ty),

0 commit comments

Comments
 (0)