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
This commit is contained in:
Pietro Albini 2019-11-05 14:37:01 +01:00 committed by GitHub
commit 6ad9f56316
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 25 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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();
}

View file

@ -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());
@ -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());
@ -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);

View file

@ -1512,7 +1512,6 @@ pub type FileLinesResult = Result<FileLines, SpanLinesError>;
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum SpanLinesError {
IllFormedSpan(Span),
DistinctSources(DistinctSources),
}