Skip to content

Commit 6ad9f56

Browse files
authored
Rollup merge of #66025 - petrochenkov:lohi, r=eddyb
`Span` cannot represent `span.hi < span.lo` So we can remove the corresponding checks from various code
2 parents b5bcb28 + ecaa964 commit 6ad9f56

File tree

5 files changed

+6
-25
lines changed

5 files changed

+6
-25
lines changed

src/librustc/ich/hcx.rs

-5
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
309309
// position that belongs to it, as opposed to hashing the first
310310
// position past it.
311311
let span = self.data();
312-
313-
if span.hi < span.lo {
314-
return std_hash::Hash::hash(&TAG_INVALID_SPAN, hasher);
315-
}
316-
317312
let (file_lo, line_lo, col_lo) = match hcx.source_map()
318313
.byte_pos_to_line_and_col(span.lo) {
319314
Some(pos) => pos,

src/librustc/ty/query/on_disk_cache.rs

-5
Original file line numberDiff line numberDiff line change
@@ -796,11 +796,6 @@ where
796796
}
797797

798798
let span_data = span.data();
799-
800-
if span_data.hi < span_data.lo {
801-
return TAG_INVALID_SPAN.encode(self);
802-
}
803-
804799
let (file_lo, line_lo, col_lo) = match self.source_map
805800
.byte_pos_to_line_and_col(span_data.lo) {
806801
Some(pos) => pos,

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'a> StringReader<'a> {
6868
let end = sess.source_map().lookup_byte_offset(span.hi());
6969

7070
// Make the range zero-length if the span is invalid.
71-
if span.lo() > span.hi() || begin.sf.start_pos != end.sf.start_pos {
71+
if begin.sf.start_pos != end.sf.start_pos {
7272
span = span.shrink_to_lo();
7373
}
7474

src/libsyntax/source_map.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,6 @@ impl SourceMap {
498498
pub fn span_to_lines(&self, sp: Span) -> FileLinesResult {
499499
debug!("span_to_lines(sp={:?})", sp);
500500

501-
if sp.lo() > sp.hi() {
502-
return Err(SpanLinesError::IllFormedSpan(sp));
503-
}
504-
505501
let lo = self.lookup_char_pos(sp.lo());
506502
debug!("span_to_lines: lo={:?}", lo);
507503
let hi = self.lookup_char_pos(sp.hi());
@@ -549,10 +545,6 @@ impl SourceMap {
549545
fn span_to_source<F>(&self, sp: Span, extract_source: F) -> Result<String, SpanSnippetError>
550546
where F: Fn(&str, usize, usize) -> Result<String, SpanSnippetError>
551547
{
552-
if sp.lo() > sp.hi() {
553-
return Err(SpanSnippetError::IllFormedSpan(sp));
554-
}
555-
556548
let local_begin = self.lookup_byte_offset(sp.lo());
557549
let local_end = self.lookup_byte_offset(sp.hi());
558550

@@ -762,14 +754,14 @@ impl SourceMap {
762754

763755
/// Finds the width of a character, either before or after the provided span.
764756
fn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32 {
765-
// Disregard malformed spans and assume a one-byte wide character.
766-
if sp.lo() >= sp.hi() {
767-
debug!("find_width_of_character_at_span: early return malformed span");
757+
let sp = sp.data();
758+
if sp.lo == sp.hi {
759+
debug!("find_width_of_character_at_span: early return empty span");
768760
return 1;
769761
}
770762

771-
let local_begin = self.lookup_byte_offset(sp.lo());
772-
let local_end = self.lookup_byte_offset(sp.hi());
763+
let local_begin = self.lookup_byte_offset(sp.lo);
764+
let local_end = self.lookup_byte_offset(sp.hi);
773765
debug!("find_width_of_character_at_span: local_begin=`{:?}`, local_end=`{:?}`",
774766
local_begin, local_end);
775767

src/libsyntax_pos/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,6 @@ pub type FileLinesResult = Result<FileLines, SpanLinesError>;
15121512

15131513
#[derive(Clone, PartialEq, Eq, Debug)]
15141514
pub enum SpanLinesError {
1515-
IllFormedSpan(Span),
15161515
DistinctSources(DistinctSources),
15171516
}
15181517

0 commit comments

Comments
 (0)