Skip to content

Commit

Permalink
Rollup merge of rust-lang#66025 - petrochenkov:lohi, r=eddyb
Browse files Browse the repository at this point in the history
`Span` cannot represent `span.hi < span.lo`

So we can remove the corresponding checks from various code
  • Loading branch information
pietroalbini committed Nov 5, 2019
2 parents b5bcb28 + ecaa964 commit 6ad9f56
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 25 deletions.
5 changes: 0 additions & 5 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
// position that belongs to it, as opposed to hashing the first
// position past it.
let span = self.data();

if span.hi < span.lo {
return std_hash::Hash::hash(&TAG_INVALID_SPAN, hasher);
}

let (file_lo, line_lo, col_lo) = match hcx.source_map()
.byte_pos_to_line_and_col(span.lo) {
Some(pos) => pos,
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,11 +796,6 @@ where
}

let span_data = span.data();

if span_data.hi < span_data.lo {
return TAG_INVALID_SPAN.encode(self);
}

let (file_lo, line_lo, col_lo) = match self.source_map
.byte_pos_to_line_and_col(span_data.lo) {
Some(pos) => pos,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> StringReader<'a> {
let end = sess.source_map().lookup_byte_offset(span.hi());

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

Expand Down
18 changes: 5 additions & 13 deletions src/libsyntax/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,6 @@ impl SourceMap {
pub fn span_to_lines(&self, sp: Span) -> FileLinesResult {
debug!("span_to_lines(sp={:?})", sp);

if sp.lo() > sp.hi() {
return Err(SpanLinesError::IllFormedSpan(sp));
}

let lo = self.lookup_char_pos(sp.lo());
debug!("span_to_lines: lo={:?}", lo);
let hi = self.lookup_char_pos(sp.hi());
Expand Down Expand Up @@ -549,10 +545,6 @@ impl SourceMap {
fn span_to_source<F>(&self, sp: Span, extract_source: F) -> Result<String, SpanSnippetError>
where F: Fn(&str, usize, usize) -> Result<String, SpanSnippetError>
{
if sp.lo() > sp.hi() {
return Err(SpanSnippetError::IllFormedSpan(sp));
}

let local_begin = self.lookup_byte_offset(sp.lo());
let local_end = self.lookup_byte_offset(sp.hi());

Expand Down Expand Up @@ -762,14 +754,14 @@ impl SourceMap {

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

let local_begin = self.lookup_byte_offset(sp.lo());
let local_end = self.lookup_byte_offset(sp.hi());
let local_begin = self.lookup_byte_offset(sp.lo);
let local_end = self.lookup_byte_offset(sp.hi);
debug!("find_width_of_character_at_span: local_begin=`{:?}`, local_end=`{:?}`",
local_begin, local_end);

Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,6 @@ pub type FileLinesResult = Result<FileLines, SpanLinesError>;

#[derive(Clone, PartialEq, Eq, Debug)]
pub enum SpanLinesError {
IllFormedSpan(Span),
DistinctSources(DistinctSources),
}

Expand Down

0 comments on commit 6ad9f56

Please sign in to comment.