diff options
| author | Pietro Albini <pietro@pietroalbini.org> | 2019-11-05 14:37:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-05 14:37:01 +0100 |
| commit | 6ad9f5631623060a9f34f40f2c614cfd8b967c08 (patch) | |
| tree | c37977c330c216614755b7eda95d5607ff2a641d /src/libsyntax | |
| parent | b5bcb28b72097c5633922b437f9eca57d6791c95 (diff) | |
| parent | ecaa96418bfff378a229ebf79d14f9e3c312cf78 (diff) | |
| download | rust-6ad9f5631623060a9f34f40f2c614cfd8b967c08.tar.gz rust-6ad9f5631623060a9f34f40f2c614cfd8b967c08.zip | |
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
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/source_map.rs | 18 |
2 files changed, 6 insertions, 14 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 48cf117f65a..e2a7ea28b9b 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -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(); } diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs index d7760e0cf9e..d9f618602a4 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax/source_map.rs @@ -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); |
