Skip to content

Commit 1959c23

Browse files
committed
Use getters to access Span fields
1 parent 6fb17c4 commit 1959c23

18 files changed

+309
-301
lines changed

src/chains.rs

Lines changed: 3 additions & 3 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 42 additions & 42 deletions
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,
@@ -304,8 +304,8 @@ pub fn format_expr(
304304
let attrs = outer_attributes(&expr.attrs);
305305
let attrs_str = try_opt!(attrs.rewrite(context, shape));
306306
let span = mk_sp(
307-
attrs.last().map_or(expr.span.lo, |attr| attr.span.hi),
308-
expr.span.lo,
307+
attrs.last().map_or(expr.span.lo(), |attr| attr.span.hi()),
308+
expr.span.lo(),
309309
);
310310
combine_strs_with_missing_comments(context, &attrs_str, &expr_str, span, shape, false)
311311
})
@@ -413,11 +413,11 @@ where
413413
context.codemap,
414414
expr_iter,
415415
"]",
416-
|item| item.span.lo,
417-
|item| item.span.hi,
416+
|item| item.span.lo(),
417+
|item| item.span.hi(),
418418
|item| item.rewrite(context, nested_shape),
419-
span.lo,
420-
span.hi,
419+
span.lo(),
420+
span.hi(),
421421
false,
422422
).collect::<Vec<_>>();
423423

@@ -531,7 +531,7 @@ fn rewrite_closure_fn_decl(
531531
|arg| span_hi_for_arg(context, arg),
532532
|arg| arg.rewrite(context, arg_shape),
533533
context.codemap.span_after(span, "|"),
534-
body.span.lo,
534+
body.span.lo(),
535535
false,
536536
);
537537
let item_vec = arg_items.collect::<Vec<_>>();
@@ -824,9 +824,9 @@ fn rewrite_block_with_visitor(
824824
ast::BlockCheckMode::Unsafe(..) => {
825825
let snippet = context.snippet(block.span);
826826
let open_pos = try_opt!(snippet.find_uncommented("{"));
827-
visitor.last_pos = block.span.lo + BytePos(open_pos as u32)
827+
visitor.last_pos = block.span.lo() + BytePos(open_pos as u32)
828828
}
829-
ast::BlockCheckMode::Default => visitor.last_pos = block.span.lo,
829+
ast::BlockCheckMode::Default => visitor.last_pos = block.span.lo(),
830830
}
831831

832832
visitor.visit_block(block, None);
@@ -1183,15 +1183,15 @@ impl<'a> ControlFlow<'a> {
11831183
let cond_span = if let Some(cond) = self.cond {
11841184
cond.span
11851185
} else {
1186-
mk_sp(self.block.span.lo, self.block.span.lo)
1186+
mk_sp(self.block.span.lo(), self.block.span.lo())
11871187
};
11881188

11891189
// for event in event
11901190
let between_kwd_cond = mk_sp(
11911191
context.codemap.span_after(self.span, self.keyword.trim()),
11921192
self.pat
1193-
.map_or(cond_span.lo, |p| if self.matcher.is_empty() {
1194-
p.span.lo
1193+
.map_or(cond_span.lo(), |p| if self.matcher.is_empty() {
1194+
p.span.lo()
11951195
} else {
11961196
context.codemap.span_before(self.span, self.matcher.trim())
11971197
}),
@@ -1200,7 +1200,7 @@ impl<'a> ControlFlow<'a> {
12001200
let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape);
12011201

12021202
let after_cond_comment =
1203-
extract_comment(mk_sp(cond_span.hi, self.block.span.lo), context, shape);
1203+
extract_comment(mk_sp(cond_span.hi(), self.block.span.lo()), context, shape);
12041204

12051205
let block_sep = if self.cond.is_none() && between_kwd_cond_comment.is_some() {
12061206
""
@@ -1291,7 +1291,7 @@ impl<'a> Rewrite for ControlFlow<'a> {
12911291
next_else_block.as_ref().map(|e| &**e),
12921292
false,
12931293
true,
1294-
mk_sp(else_block.span.lo, self.span.hi),
1294+
mk_sp(else_block.span.lo(), self.span.hi()),
12951295
).rewrite(context, shape)
12961296
}
12971297
ast::ExprKind::If(ref cond, ref if_block, ref next_else_block) => {
@@ -1302,7 +1302,7 @@ impl<'a> Rewrite for ControlFlow<'a> {
13021302
next_else_block.as_ref().map(|e| &**e),
13031303
false,
13041304
true,
1305-
mk_sp(else_block.span.lo, self.span.hi),
1305+
mk_sp(else_block.span.lo(), self.span.hi()),
13061306
).rewrite(context, shape)
13071307
}
13081308
_ => {
@@ -1318,19 +1318,19 @@ impl<'a> Rewrite for ControlFlow<'a> {
13181318
};
13191319

13201320
let between_kwd_else_block = mk_sp(
1321-
self.block.span.hi,
1321+
self.block.span.hi(),
13221322
context
13231323
.codemap
1324-
.span_before(mk_sp(self.block.span.hi, else_block.span.lo), "else"),
1324+
.span_before(mk_sp(self.block.span.hi(), else_block.span.lo()), "else"),
13251325
);
13261326
let between_kwd_else_block_comment =
13271327
extract_comment(between_kwd_else_block, context, shape);
13281328

13291329
let after_else = mk_sp(
13301330
context
13311331
.codemap
1332-
.span_after(mk_sp(self.block.span.hi, else_block.span.lo), "else"),
1333-
else_block.span.lo,
1332+
.span_after(mk_sp(self.block.span.hi(), else_block.span.lo()), "else"),
1333+
else_block.span.lo(),
13341334
);
13351335
let after_else_comment = extract_comment(after_else, context, shape);
13361336

@@ -1518,9 +1518,9 @@ fn rewrite_match(
15181518
let open_brace_pos = if inner_attrs.is_empty() {
15191519
context
15201520
.codemap
1521-
.span_after(mk_sp(cond.span.hi, arms[0].span().lo), "{")
1521+
.span_after(mk_sp(cond.span.hi(), arms[0].span().lo()), "{")
15221522
} else {
1523-
inner_attrs[inner_attrs.len() - 1].span().hi
1523+
inner_attrs[inner_attrs.len() - 1].span().hi()
15241524
};
15251525

15261526
Some(format!(
@@ -1573,9 +1573,9 @@ fn rewrite_match_arms(
15731573
for (i, arm) in arms.iter().enumerate() {
15741574
// Make sure we get the stuff between arms.
15751575
let missed_str = if i == 0 {
1576-
context.snippet(mk_sp(open_brace_pos, arm.span().lo))
1576+
context.snippet(mk_sp(open_brace_pos, arm.span().lo()))
15771577
} else {
1578-
context.snippet(mk_sp(arms[i - 1].span().hi, arm.span().lo))
1578+
context.snippet(mk_sp(arms[i - 1].span().hi(), arm.span().lo()))
15791579
};
15801580
let comment = try_opt!(rewrite_match_arm_comment(
15811581
context,
@@ -1609,7 +1609,7 @@ fn rewrite_match_arms(
16091609
}
16101610
}
16111611
// BytePos(1) = closing match brace.
1612-
let last_span = mk_sp(arms[arms.len() - 1].span().hi, span.hi - BytePos(1));
1612+
let last_span = mk_sp(arms[arms.len() - 1].span().hi(), span.hi() - BytePos(1));
16131613
let last_comment = context.snippet(last_span);
16141614
let comment = try_opt!(rewrite_match_arm_comment(
16151615
context,
@@ -1957,7 +1957,7 @@ fn string_requires_rewrite(
19571957
string: &str,
19581958
shape: Shape,
19591959
) -> bool {
1960-
if context.codemap.lookup_char_pos(span.lo).col.0 != shape.indent.width() {
1960+
if context.codemap.lookup_char_pos(span.lo()).col.0 != shape.indent.width() {
19611961
return true;
19621962
}
19631963

@@ -2071,7 +2071,7 @@ where
20712071
).ok_or(Ordering::Greater)?;
20722072

20732073
let span_lo = context.codemap.span_after(span, "(");
2074-
let args_span = mk_sp(span_lo, span.hi);
2074+
let args_span = mk_sp(span_lo, span.hi());
20752075

20762076
let (extendable, list_str) = rewrite_call_args(
20772077
context,
@@ -2130,11 +2130,11 @@ where
21302130
context.codemap,
21312131
args.iter(),
21322132
")",
2133-
|item| item.span().lo,
2134-
|item| item.span().hi,
2133+
|item| item.span().lo(),
2134+
|item| item.span().hi(),
21352135
|item| item.rewrite(context, shape),
2136-
span.lo,
2137-
span.hi,
2136+
span.lo(),
2137+
span.hi(),
21382138
true,
21392139
);
21402140
let mut item_vec: Vec<_> = items.collect();
@@ -2552,7 +2552,7 @@ fn rewrite_struct_lit<'a>(
25522552
fields,
25532553
context,
25542554
shape,
2555-
mk_sp(body_lo, span.hi),
2555+
mk_sp(body_lo, span.hi()),
25562556
one_line_width,
25572557
))
25582558
} else {
@@ -2562,17 +2562,17 @@ fn rewrite_struct_lit<'a>(
25622562
.chain(base.into_iter().map(StructLitField::Base));
25632563

25642564
let span_lo = |item: &StructLitField| match *item {
2565-
StructLitField::Regular(field) => field.span().lo,
2565+
StructLitField::Regular(field) => field.span().lo(),
25662566
StructLitField::Base(expr) => {
2567-
let last_field_hi = fields.last().map_or(span.lo, |field| field.span.hi);
2568-
let snippet = context.snippet(mk_sp(last_field_hi, expr.span.lo));
2567+
let last_field_hi = fields.last().map_or(span.lo(), |field| field.span.hi());
2568+
let snippet = context.snippet(mk_sp(last_field_hi, expr.span.lo()));
25692569
let pos = snippet.find_uncommented("..").unwrap();
25702570
last_field_hi + BytePos(pos as u32)
25712571
}
25722572
};
25732573
let span_hi = |item: &StructLitField| match *item {
2574-
StructLitField::Regular(field) => field.span().hi,
2575-
StructLitField::Base(expr) => expr.span.hi,
2574+
StructLitField::Regular(field) => field.span().hi(),
2575+
StructLitField::Base(expr) => expr.span.hi(),
25762576
};
25772577
let rewrite = |item: &StructLitField| match *item {
25782578
StructLitField::Regular(field) => {
@@ -2594,7 +2594,7 @@ fn rewrite_struct_lit<'a>(
25942594
span_hi,
25952595
rewrite,
25962596
body_lo,
2597-
span.hi,
2597+
span.hi(),
25982598
false,
25992599
);
26002600
let item_vec = items.collect::<Vec<_>>();
@@ -2743,11 +2743,11 @@ where
27432743
context.codemap,
27442744
items,
27452745
")",
2746-
|item| item.span().lo,
2747-
|item| item.span().hi,
2746+
|item| item.span().lo(),
2747+
|item| item.span().hi(),
27482748
|item| item.rewrite(context, nested_shape),
27492749
list_lo,
2750-
span.hi - BytePos(1),
2750+
span.hi() - BytePos(1),
27512751
false,
27522752
);
27532753
let item_vec: Vec<_> = items.collect();

src/imports.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ impl<'a> FmtVisitor<'a> {
198198
self.last_pos,
199199
p_i.attrs
200200
.iter()
201-
.map(|attr| attr.span.lo)
201+
.map(|attr| attr.span.lo())
202202
.min()
203-
.unwrap_or(p_i.span.lo),
203+
.unwrap_or(p_i.span.lo()),
204204
)
205205
})
206206
.unwrap_or(self.last_pos);
@@ -211,7 +211,7 @@ impl<'a> FmtVisitor<'a> {
211211
.iter()
212212
.map(|p_i| {
213213
let new_item = (&*p_i, last_pos_of_prev_use_item);
214-
last_pos_of_prev_use_item = p_i.span.hi;
214+
last_pos_of_prev_use_item = p_i.span.hi();
215215
new_item
216216
})
217217
.collect::<Vec<_>>();
@@ -275,23 +275,23 @@ impl<'a> FmtVisitor<'a> {
275275
match rw {
276276
Some(ref s) if s.is_empty() => {
277277
// Format up to last newline
278-
let prev_span = utils::mk_sp(self.last_pos, source!(self, span).lo);
278+
let prev_span = utils::mk_sp(self.last_pos, source!(self, span).lo());
279279
let span_end = match self.snippet(prev_span).rfind('\n') {
280280
Some(offset) => self.last_pos + BytePos(offset as u32),
281-
None => source!(self, span).lo,
281+
None => source!(self, span).lo(),
282282
};
283283
self.format_missing(span_end);
284-
self.last_pos = source!(self, span).hi;
284+
self.last_pos = source!(self, span).hi();
285285
}
286286
Some(ref s) => {
287287
let s = format!("{}use {};", vis, s);
288-
self.format_missing_with_indent(source!(self, span).lo);
288+
self.format_missing_with_indent(source!(self, span).lo());
289289
self.buffer.push_str(&s);
290-
self.last_pos = source!(self, span).hi;
290+
self.last_pos = source!(self, span).hi();
291291
}
292292
None => {
293-
self.format_missing_with_indent(source!(self, span).lo);
294-
self.format_missing(source!(self, span).hi);
293+
self.format_missing_with_indent(source!(self, span).lo());
294+
self.format_missing(source!(self, span).hi());
295295
}
296296
}
297297
}
@@ -442,11 +442,11 @@ fn rewrite_use_list(
442442
context.codemap,
443443
path_list.iter(),
444444
"}",
445-
|vpi| vpi.span.lo,
446-
|vpi| vpi.span.hi,
445+
|vpi| vpi.span.lo(),
446+
|vpi| vpi.span.hi(),
447447
rewrite_path_item,
448448
context.codemap.span_after(span, "{"),
449-
span.hi,
449+
span.hi(),
450450
false,
451451
);
452452
items.extend(iter);

0 commit comments

Comments
 (0)