Skip to content

Commit 8155734

Browse files
committed
refactor: Move assert for disjoint substitution spans
1 parent af00ff2 commit 8155734

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,6 @@ impl HumanEmitter {
23542354
.sum();
23552355
let underline_start = (span_start_pos + start) as isize + offset;
23562356
let underline_end = (span_start_pos + start + sub_len) as isize + offset;
2357-
assert!(underline_start >= 0 && underline_end >= 0);
23582357
let padding: usize = max_line_num_len + 3;
23592358
for p in underline_start..underline_end {
23602359
if let DisplaySuggestion::Underline = show_code_change

compiler/rustc_errors/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@ impl CodeSuggestion {
381381
// Assumption: all spans are in the same file, and all spans
382382
// are disjoint. Sort in ascending order.
383383
substitution.parts.sort_by_key(|part| part.span.lo());
384+
// Verify the assumption that all spans are disjoint
385+
assert_eq!(
386+
substitution.parts.array_windows().find(|[a, b]| a.span.overlaps(b.span)),
387+
None,
388+
"all spans must be disjoint",
389+
);
384390

385391
// Find the bounding span.
386392
let lo = substitution.parts.iter().map(|part| part.span.lo()).min()?;

0 commit comments

Comments
 (0)