Skip to content

Commit d3bc306

Browse files
committed
Use getters to access Span fields
1 parent 4eca284 commit d3bc306

18 files changed

+322
-309
lines changed

src/chains.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ fn rewrite_method_call(
470470
shape: Shape,
471471
) -> Option<String> {
472472
let (lo, type_str) = if types.is_empty() {
473-
(args[0].span.hi, String::new())
473+
(args[0].span.hi(), String::new())
474474
} else {
475475
let type_list: Vec<_> =
476476
try_opt!(types.iter().map(|ty| ty.rewrite(context, shape)).collect());
@@ -481,11 +481,11 @@ fn rewrite_method_call(
481481
format!("::<{}>", type_list.join(", "))
482482
};
483483

484-
(types.last().unwrap().span.hi, type_str)
484+
(types.last().unwrap().span.hi(), type_str)
485485
};
486486

487487
let callee_str = format!(".{}{}", method_name, type_str);
488-
let span = mk_sp(lo, span.hi);
488+
let span = mk_sp(lo, span.hi());
489489

490490
rewrite_call(context, &callee_str, &args[1..], span, shape)
491491
}

src/codemap.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl SpanUtils for CodeMap {
5050
let snippet = self.span_to_snippet(original).unwrap();
5151
let offset = snippet.find_uncommented(needle).unwrap() + needle.len();
5252

53-
original.lo + BytePos(offset as u32)
53+
original.lo() + BytePos(offset as u32)
5454
}
5555

5656
fn span_after_last(&self, original: Span, needle: &str) -> BytePos {
@@ -61,21 +61,21 @@ impl SpanUtils for CodeMap {
6161
offset += additional_offset + needle.len();
6262
}
6363

64-
original.lo + BytePos(offset as u32)
64+
original.lo() + BytePos(offset as u32)
6565
}
6666

6767
fn span_before(&self, original: Span, needle: &str) -> BytePos {
6868
let snippet = self.span_to_snippet(original).unwrap();
6969
let offset = snippet.find_uncommented(needle).unwrap();
7070

71-
original.lo + BytePos(offset as u32)
71+
original.lo() + BytePos(offset as u32)
7272
}
7373
}
7474

7575
impl LineRangeUtils for CodeMap {
7676
fn lookup_line_range(&self, span: Span) -> LineRange {
77-
let lo = self.lookup_char_pos(span.lo);
78-
let hi = self.lookup_char_pos(span.hi);
77+
let lo = self.lookup_char_pos(span.lo());
78+
let hi = self.lookup_char_pos(span.hi());
7979

8080
assert!(
8181
lo.file.name == hi.file.name,

src/expr.rs

+49-46
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn format_expr(
6565
let expr_rw = match expr.node {
6666
ast::ExprKind::Array(ref expr_vec) => rewrite_array(
6767
expr_vec.iter().map(|e| &**e),
68-
mk_sp(context.codemap.span_after(expr.span, "["), expr.span.hi),
68+
mk_sp(context.codemap.span_after(expr.span, "["), expr.span.hi()),
6969
context,
7070
shape,
7171
false,
@@ -81,7 +81,7 @@ pub fn format_expr(
8181
),
8282
},
8383
ast::ExprKind::Call(ref callee, ref args) => {
84-
let inner_span = mk_sp(callee.span.hi, expr.span.hi);
84+
let inner_span = mk_sp(callee.span.hi(), expr.span.hi());
8585
rewrite_call_with_binary_search(
8686
context,
8787
&**callee,
@@ -308,8 +308,8 @@ pub fn format_expr(
308308
let attrs = outer_attributes(&expr.attrs);
309309
let attrs_str = try_opt!(attrs.rewrite(context, shape));
310310
let span = mk_sp(
311-
attrs.last().map_or(expr.span.lo, |attr| attr.span.hi),
312-
expr.span.lo,
311+
attrs.last().map_or(expr.span.lo(), |attr| attr.span.hi()),
312+
expr.span.lo(),
313313
);
314314
combine_strs_with_missing_comments(context, &attrs_str, &expr_str, span, shape, false)
315315
})
@@ -417,11 +417,11 @@ where
417417
context.codemap,
418418
expr_iter,
419419
"]",
420-
|item| item.span.lo,
421-
|item| item.span.hi,
420+
|item| item.span.lo(),
421+
|item| item.span.hi(),
422422
|item| item.rewrite(context, nested_shape),
423-
span.lo,
424-
span.hi,
423+
span.lo(),
424+
span.hi(),
425425
false,
426426
).collect::<Vec<_>>();
427427

@@ -536,7 +536,7 @@ fn rewrite_closure_fn_decl(
536536
|arg| span_hi_for_arg(context, arg),
537537
|arg| arg.rewrite(context, arg_shape),
538538
context.codemap.span_after(span, "|"),
539-
body.span.lo,
539+
body.span.lo(),
540540
false,
541541
);
542542
let item_vec = arg_items.collect::<Vec<_>>();
@@ -837,9 +837,9 @@ fn rewrite_block_with_visitor(
837837
ast::BlockCheckMode::Unsafe(..) => {
838838
let snippet = context.snippet(block.span);
839839
let open_pos = try_opt!(snippet.find_uncommented("{"));
840-
visitor.last_pos = block.span.lo + BytePos(open_pos as u32)
840+
visitor.last_pos = block.span.lo() + BytePos(open_pos as u32)
841841
}
842-
ast::BlockCheckMode::Default => visitor.last_pos = block.span.lo,
842+
ast::BlockCheckMode::Default => visitor.last_pos = block.span.lo(),
843843
}
844844

845845
visitor.visit_block(block, None);
@@ -1193,19 +1193,19 @@ impl<'a> ControlFlow<'a> {
11931193
let cond_span = if let Some(cond) = self.cond {
11941194
cond.span
11951195
} else {
1196-
mk_sp(self.block.span.lo, self.block.span.lo)
1196+
mk_sp(self.block.span.lo(), self.block.span.lo())
11971197
};
11981198

11991199
// `for event in event`
12001200
// Do not include label in the span.
1201-
let lo = self.label.map_or(self.span.lo, |label| label.span.hi);
1201+
let lo = self.label.map_or(self.span.lo(), |label| label.span.hi());
12021202
let between_kwd_cond = mk_sp(
12031203
context
12041204
.codemap
1205-
.span_after(mk_sp(lo, self.span.hi), self.keyword.trim()),
1205+
.span_after(mk_sp(lo, self.span.hi()), self.keyword.trim()),
12061206
self.pat
1207-
.map_or(cond_span.lo, |p| if self.matcher.is_empty() {
1208-
p.span.lo
1207+
.map_or(cond_span.lo(), |p| if self.matcher.is_empty() {
1208+
p.span.lo()
12091209
} else {
12101210
context.codemap.span_before(self.span, self.matcher.trim())
12111211
}),
@@ -1214,7 +1214,7 @@ impl<'a> ControlFlow<'a> {
12141214
let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape);
12151215

12161216
let after_cond_comment =
1217-
extract_comment(mk_sp(cond_span.hi, self.block.span.lo), context, shape);
1217+
extract_comment(mk_sp(cond_span.hi(), self.block.span.lo()), context, shape);
12181218

12191219
let block_sep = if self.cond.is_none() && between_kwd_cond_comment.is_some() {
12201220
""
@@ -1305,7 +1305,7 @@ impl<'a> Rewrite for ControlFlow<'a> {
13051305
next_else_block.as_ref().map(|e| &**e),
13061306
false,
13071307
true,
1308-
mk_sp(else_block.span.lo, self.span.hi),
1308+
mk_sp(else_block.span.lo(), self.span.hi()),
13091309
).rewrite(context, shape)
13101310
}
13111311
ast::ExprKind::If(ref cond, ref if_block, ref next_else_block) => {
@@ -1316,7 +1316,7 @@ impl<'a> Rewrite for ControlFlow<'a> {
13161316
next_else_block.as_ref().map(|e| &**e),
13171317
false,
13181318
true,
1319-
mk_sp(else_block.span.lo, self.span.hi),
1319+
mk_sp(else_block.span.lo(), self.span.hi()),
13201320
).rewrite(context, shape)
13211321
}
13221322
_ => {
@@ -1332,19 +1332,19 @@ impl<'a> Rewrite for ControlFlow<'a> {
13321332
};
13331333

13341334
let between_kwd_else_block = mk_sp(
1335-
self.block.span.hi,
1335+
self.block.span.hi(),
13361336
context
13371337
.codemap
1338-
.span_before(mk_sp(self.block.span.hi, else_block.span.lo), "else"),
1338+
.span_before(mk_sp(self.block.span.hi(), else_block.span.lo()), "else"),
13391339
);
13401340
let between_kwd_else_block_comment =
13411341
extract_comment(between_kwd_else_block, context, shape);
13421342

13431343
let after_else = mk_sp(
13441344
context
13451345
.codemap
1346-
.span_after(mk_sp(self.block.span.hi, else_block.span.lo), "else"),
1347-
else_block.span.lo,
1346+
.span_after(mk_sp(self.block.span.hi(), else_block.span.lo()), "else"),
1347+
else_block.span.lo(),
13481348
);
13491349
let after_else_comment = extract_comment(after_else, context, shape);
13501350

@@ -1504,9 +1504,9 @@ fn rewrite_match(
15041504
let open_brace_pos = if inner_attrs.is_empty() {
15051505
context
15061506
.codemap
1507-
.span_after(mk_sp(cond.span.hi, arms[0].span().lo), "{")
1507+
.span_after(mk_sp(cond.span.hi(), arms[0].span().lo()), "{")
15081508
} else {
1509-
inner_attrs[inner_attrs.len() - 1].span().hi
1509+
inner_attrs[inner_attrs.len() - 1].span().hi()
15101510
};
15111511

15121512
let arm_indent_str = if context.config.indent_match_arms() {
@@ -1571,11 +1571,11 @@ fn rewrite_match_arms(
15711571
.zip(is_last_iter)
15721572
.map(|(arm, is_last)| ArmWrapper::new(arm, is_last)),
15731573
"}",
1574-
|arm| arm.arm.span().lo,
1575-
|arm| arm.arm.span().hi,
1574+
|arm| arm.arm.span().lo(),
1575+
|arm| arm.arm.span().hi(),
15761576
|arm| arm.rewrite(context, arm_shape),
15771577
open_brace_pos,
1578-
span.hi,
1578+
span.hi(),
15791579
false,
15801580
);
15811581
let arms_vec: Vec<_> = items.collect();
@@ -1611,11 +1611,14 @@ fn rewrite_match_arm(
16111611
));
16121612
}
16131613
(
1614-
mk_sp(arm.attrs[arm.attrs.len() - 1].span.hi, arm.pats[0].span.lo),
1614+
mk_sp(
1615+
arm.attrs[arm.attrs.len() - 1].span.hi(),
1616+
arm.pats[0].span.lo(),
1617+
),
16151618
try_opt!(arm.attrs.rewrite(context, shape)),
16161619
)
16171620
} else {
1618-
(mk_sp(arm.span().lo, arm.span().lo), String::new())
1621+
(mk_sp(arm.span().lo(), arm.span().lo()), String::new())
16191622
};
16201623
let pats_str = try_opt!(
16211624
rewrite_match_pattern(context, &arm.pats, &arm.guard, shape).and_then(|pats_str| {
@@ -1973,7 +1976,7 @@ fn string_requires_rewrite(
19731976
string: &str,
19741977
shape: Shape,
19751978
) -> bool {
1976-
if context.codemap.lookup_char_pos(span.lo).col.0 != shape.indent.width() {
1979+
if context.codemap.lookup_char_pos(span.lo()).col.0 != shape.indent.width() {
19771980
return true;
19781981
}
19791982

@@ -2087,7 +2090,7 @@ where
20872090
).ok_or(Ordering::Greater)?;
20882091

20892092
let span_lo = context.codemap.span_after(span, "(");
2090-
let args_span = mk_sp(span_lo, span.hi);
2093+
let args_span = mk_sp(span_lo, span.hi());
20912094

20922095
let (extendable, list_str) = rewrite_call_args(
20932096
context,
@@ -2146,11 +2149,11 @@ where
21462149
context.codemap,
21472150
args.iter(),
21482151
")",
2149-
|item| item.span().lo,
2150-
|item| item.span().hi,
2152+
|item| item.span().lo(),
2153+
|item| item.span().hi(),
21512154
|item| item.rewrite(context, shape),
2152-
span.lo,
2153-
span.hi,
2155+
span.lo(),
2156+
span.hi(),
21542157
true,
21552158
);
21562159
let mut item_vec: Vec<_> = items.collect();
@@ -2569,7 +2572,7 @@ fn rewrite_struct_lit<'a>(
25692572
fields,
25702573
context,
25712574
shape,
2572-
mk_sp(body_lo, span.hi),
2575+
mk_sp(body_lo, span.hi()),
25732576
one_line_width,
25742577
))
25752578
} else {
@@ -2579,17 +2582,17 @@ fn rewrite_struct_lit<'a>(
25792582
.chain(base.into_iter().map(StructLitField::Base));
25802583

25812584
let span_lo = |item: &StructLitField| match *item {
2582-
StructLitField::Regular(field) => field.span().lo,
2585+
StructLitField::Regular(field) => field.span().lo(),
25832586
StructLitField::Base(expr) => {
2584-
let last_field_hi = fields.last().map_or(span.lo, |field| field.span.hi);
2585-
let snippet = context.snippet(mk_sp(last_field_hi, expr.span.lo));
2587+
let last_field_hi = fields.last().map_or(span.lo(), |field| field.span.hi());
2588+
let snippet = context.snippet(mk_sp(last_field_hi, expr.span.lo()));
25862589
let pos = snippet.find_uncommented("..").unwrap();
25872590
last_field_hi + BytePos(pos as u32)
25882591
}
25892592
};
25902593
let span_hi = |item: &StructLitField| match *item {
2591-
StructLitField::Regular(field) => field.span().hi,
2592-
StructLitField::Base(expr) => expr.span.hi,
2594+
StructLitField::Regular(field) => field.span().hi(),
2595+
StructLitField::Base(expr) => expr.span.hi(),
25932596
};
25942597
let rewrite = |item: &StructLitField| match *item {
25952598
StructLitField::Regular(field) => {
@@ -2611,7 +2614,7 @@ fn rewrite_struct_lit<'a>(
26112614
span_hi,
26122615
rewrite,
26132616
body_lo,
2614-
span.hi,
2617+
span.hi(),
26152618
false,
26162619
);
26172620
let item_vec = items.collect::<Vec<_>>();
@@ -2760,11 +2763,11 @@ where
27602763
context.codemap,
27612764
items,
27622765
")",
2763-
|item| item.span().lo,
2764-
|item| item.span().hi,
2766+
|item| item.span().lo(),
2767+
|item| item.span().hi(),
27652768
|item| item.rewrite(context, nested_shape),
27662769
list_lo,
2767-
span.hi - BytePos(1),
2770+
span.hi() - BytePos(1),
27682771
false,
27692772
);
27702773
let item_vec: Vec<_> = items.collect();

0 commit comments

Comments
 (0)