Skip to content

Commit a34c5f9

Browse files
committed
docs: Rename 'range' parameter to 'span'
1 parent a928524 commit a34c5f9

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

Diff for: src/renderer/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ impl Renderer {
15231523
}
15241524
if suggestion.origin != primary_origin {
15251525
if let Some(origin) = suggestion.origin {
1526-
let (loc, _) = sm.span_to_locations(parts[0].range.clone());
1526+
let (loc, _) = sm.span_to_locations(parts[0].span.clone());
15271527
// --> file.rs:line:col
15281528
// |
15291529
let arrow = self.file_start();
@@ -1563,8 +1563,8 @@ impl Renderer {
15631563
row_num += 1;
15641564
}
15651565

1566-
let file_lines = sm.span_to_lines(parts[0].range.clone());
1567-
let (line_start, line_end) = sm.span_to_locations(parts[0].range.clone());
1566+
let file_lines = sm.span_to_lines(parts[0].span.clone());
1567+
let (line_start, line_end) = sm.span_to_locations(parts[0].span.clone());
15681568
let mut lines = complete.lines();
15691569
if lines.clone().next().is_none() {
15701570
// Account for a suggestion to completely remove a line(s) with whitespace (#94192).
@@ -1697,8 +1697,8 @@ impl Renderer {
16971697
// already existing code, despite the colors and UI elements.
16981698
// We special case `#[derive(_)]\n` and other attribute suggestions, because those
16991699
// are the ones where context is most useful.
1700-
let file_lines = sm.span_to_lines(parts[0].range.end..parts[0].range.end);
1701-
let (lo, _) = sm.span_to_locations(parts[0].range.clone());
1700+
let file_lines = sm.span_to_lines(parts[0].span.end..parts[0].span.end);
1701+
let (lo, _) = sm.span_to_locations(parts[0].span.clone());
17021702
let line_num = lo.line;
17031703
if let Some(line) = sm.get_line(line_num) {
17041704
let line = normalize_whitespace(line);
@@ -1724,7 +1724,7 @@ impl Renderer {
17241724
show_code_change
17251725
{
17261726
for part in parts {
1727-
let (span_start, span_end) = sm.span_to_locations(part.range.clone());
1727+
let (span_start, span_end) = sm.span_to_locations(part.span.clone());
17281728
let span_start_pos = span_start.display;
17291729
let span_end_pos = span_end.display;
17301730

@@ -1764,7 +1764,7 @@ impl Renderer {
17641764
let padding: usize = max_line_num_len + 3;
17651765
for p in underline_start..underline_end {
17661766
if matches!(show_code_change, DisplaySuggestion::Underline)
1767-
&& is_different(sm, part.replacement, part.range.clone())
1767+
&& is_different(sm, part.replacement, part.span.clone())
17681768
{
17691769
// If this is a replacement, underline with `~`, if this is an addition
17701770
// underline with `+`.

Diff for: src/renderer/source_map.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ impl<'a> SourceMap<'a> {
129129
let source_len = self.source.len();
130130
if let Some(bigger) = annotations.iter().find_map(|x| {
131131
// Allow highlighting one past the last character in the source.
132-
if source_len + 1 < x.range.end {
133-
Some(&x.range)
132+
if source_len + 1 < x.span.end {
133+
Some(&x.span)
134134
} else {
135135
None
136136
}
@@ -150,13 +150,13 @@ impl<'a> SourceMap<'a> {
150150
let mut multiline_annotations = vec![];
151151

152152
for Annotation {
153-
range,
153+
span,
154154
label,
155155
kind,
156156
highlight_source,
157157
} in annotations
158158
{
159-
let (lo, mut hi) = self.span_to_locations(range.clone());
159+
let (lo, mut hi) = self.span_to_locations(span.clone());
160160

161161
// Watch out for "empty spans". If we get a span like 6..6, we
162162
// want to just display a `^` at 6, so convert that to
@@ -374,13 +374,13 @@ impl<'a> SourceMap<'a> {
374374
}
375375
// Assumption: all spans are in the same file, and all spans
376376
// are disjoint. Sort in ascending order.
377-
patches.sort_by_key(|p| p.range.start);
377+
patches.sort_by_key(|p| p.span.start);
378378

379379
// Find the bounding span.
380-
let Some(lo) = patches.iter().map(|p| p.range.start).min() else {
380+
let Some(lo) = patches.iter().map(|p| p.span.start).min() else {
381381
return Vec::new();
382382
};
383-
let Some(hi) = patches.iter().map(|p| p.range.end).max() else {
383+
let Some(hi) = patches.iter().map(|p| p.span.end).max() else {
384384
return Vec::new();
385385
};
386386

@@ -410,7 +410,7 @@ impl<'a> SourceMap<'a> {
410410
// suggestion and snippet to look as if we just suggested to add
411411
// `"b"`, which is typically much easier for the user to understand.
412412
part.trim_trivial_replacements(self);
413-
let (cur_lo, cur_hi) = self.span_to_locations(part.range.clone());
413+
let (cur_lo, cur_hi) = self.span_to_locations(part.span.clone());
414414
if prev_hi.line == cur_lo.line {
415415
let mut count = push_trailing(&mut buf, prev_line, &prev_hi, Some(&cur_lo));
416416
while count > 0 {
@@ -454,7 +454,7 @@ impl<'a> SourceMap<'a> {
454454
_ => 1,
455455
})
456456
.sum();
457-
if !is_different(self, part.replacement, part.range.clone()) {
457+
if !is_different(self, part.replacement, part.span.clone()) {
458458
// Account for cases where we are suggesting the same code that's already
459459
// there. This shouldn't happen often, but in some cases for multipart
460460
// suggestions it's much easier to handle it here than in the origin.

Diff for: src/snippet.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'a> Message<'a> {
3939
let end = cause
4040
.markers
4141
.iter()
42-
.map(|a| a.range.end)
42+
.map(|a| a.span.end)
4343
.max()
4444
.unwrap_or(cause.source.len())
4545
.min(cause.source.len());
@@ -50,7 +50,7 @@ impl<'a> Message<'a> {
5050
let end = suggestion
5151
.markers
5252
.iter()
53-
.map(|a| a.range.end)
53+
.map(|a| a.span.end)
5454
.max()
5555
.unwrap_or(suggestion.source.len())
5656
.min(suggestion.source.len());
@@ -222,7 +222,7 @@ impl<'a> Snippet<'a, Patch<'a>> {
222222

223223
#[derive(Clone, Debug)]
224224
pub struct Annotation<'a> {
225-
pub(crate) range: Range<usize>,
225+
pub(crate) span: Range<usize>,
226226
pub(crate) label: Option<&'a str>,
227227
pub(crate) kind: AnnotationKind,
228228
pub(crate) highlight_source: bool,
@@ -254,7 +254,7 @@ pub enum AnnotationKind {
254254
impl AnnotationKind {
255255
pub fn span<'a>(self, span: Range<usize>) -> Annotation<'a> {
256256
Annotation {
257-
range: span,
257+
span: span,
258258
label: None,
259259
kind: self,
260260
highlight_source: false,
@@ -268,16 +268,16 @@ impl AnnotationKind {
268268

269269
#[derive(Clone, Debug)]
270270
pub struct Patch<'a> {
271-
pub(crate) range: Range<usize>,
271+
pub(crate) span: Range<usize>,
272272
pub(crate) replacement: &'a str,
273273
}
274274

275275
impl<'a> Patch<'a> {
276276
/// Text passed to this function is considered "untrusted input", as such
277277
/// all text is passed through a normalization function. Pre-styled text is
278278
/// not allowed to be passed to this function.
279-
pub fn new(range: Range<usize>, replacement: &'a str) -> Self {
280-
Self { range, replacement }
279+
pub fn new(span: Range<usize>, replacement: &'a str) -> Self {
280+
Self { span, replacement }
281281
}
282282

283283
pub(crate) fn is_addition(&self, sm: &SourceMap<'_>) -> bool {
@@ -299,16 +299,16 @@ impl<'a> Patch<'a> {
299299
pub(crate) fn is_destructive_replacement(&self, sm: &SourceMap<'_>) -> bool {
300300
self.is_replacement(sm)
301301
&& !sm
302-
.span_to_snippet(self.range.clone())
302+
.span_to_snippet(self.span.clone())
303303
// This should use `is_some_and` when our MSRV is >= 1.70
304304
.map_or(false, |s| {
305305
as_substr(s.trim(), self.replacement.trim()).is_some()
306306
})
307307
}
308308

309309
fn replaces_meaningful_content(&self, sm: &SourceMap<'_>) -> bool {
310-
sm.span_to_snippet(self.range.clone())
311-
.map_or(!self.range.is_empty(), |snippet| !snippet.trim().is_empty())
310+
sm.span_to_snippet(self.span.clone())
311+
.map_or(!self.span.is_empty(), |snippet| !snippet.trim().is_empty())
312312
}
313313

314314
/// Try to turn a replacement into an addition when the span that is being
@@ -317,12 +317,12 @@ impl<'a> Patch<'a> {
317317
if self.replacement.is_empty() {
318318
return;
319319
}
320-
let Some(snippet) = sm.span_to_snippet(self.range.clone()) else {
320+
let Some(snippet) = sm.span_to_snippet(self.span.clone()) else {
321321
return;
322322
};
323323

324324
if let Some((prefix, substr, suffix)) = as_substr(snippet, self.replacement) {
325-
self.range = self.range.start + prefix..self.range.end.saturating_sub(suffix);
325+
self.span = self.span.start + prefix..self.span.end.saturating_sub(suffix);
326326
self.replacement = substr;
327327
}
328328
}

0 commit comments

Comments
 (0)