diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-06-25 01:00:21 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-06-30 01:53:32 +0300 |
| commit | 9f92fce77c74cf3c47035e9ff69c29daee0517b3 (patch) | |
| tree | e724e8e72a43d71053f4de32fa893a661ee163bf /src/libsyntax | |
| parent | 297109ea3263a4ea90a7143a82e46903a8890269 (diff) | |
| download | rust-9f92fce77c74cf3c47035e9ff69c29daee0517b3.tar.gz rust-9f92fce77c74cf3c47035e9ff69c29daee0517b3.zip | |
Fortify dummy span checking
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/quoted.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/tokenstream.rs | 8 |
6 files changed, 19 insertions, 19 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 1d5429bdf8f..ea6b39504e8 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -443,7 +443,7 @@ impl CodeMap { } pub fn span_to_string(&self, sp: Span) -> String { - if self.files.borrow().file_maps.is_empty() && sp.source_equal(&DUMMY_SP) { + if self.files.borrow().file_maps.is_empty() && sp.is_dummy() { return "no-location".to_string(); } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index e364e145593..f29bff20f3d 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1297,7 +1297,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { // Detect if this is an inline module (`mod m { ... }` as opposed to `mod m;`). // In the non-inline case, `inner` is never the dummy span (c.f. `parse_item_mod`). // Thus, if `inner` is the dummy span, we know the module is inline. - let inline_module = item.span.contains(inner) || inner == DUMMY_SP; + let inline_module = item.span.contains(inner) || inner.is_dummy(); if inline_module { if let Some(path) = attr::first_attr_value_str_by_name(&item.attrs, "path") { diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index 01b971976a7..82b0fae3e9c 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -14,7 +14,7 @@ use feature_gate::{self, emit_feature_err, Features, GateIssue}; use parse::{token, ParseSess}; use print::pprust; use symbol::keywords; -use syntax_pos::{BytePos, Span, DUMMY_SP}; +use syntax_pos::{BytePos, Span}; use tokenstream; use std::iter::Peekable; @@ -41,8 +41,8 @@ impl Delimited { /// Return a `self::TokenTree` with a `Span` corresponding to the opening delimiter. pub fn open_tt(&self, span: Span) -> TokenTree { - let open_span = if span == DUMMY_SP { - DUMMY_SP + let open_span = if span.is_dummy() { + span } else { span.with_lo(span.lo() + BytePos(self.delim.len() as u32)) }; @@ -51,8 +51,8 @@ impl Delimited { /// Return a `self::TokenTree` with a `Span` corresponding to the closing delimiter. pub fn close_tt(&self, span: Span) -> TokenTree { - let close_span = if span == DUMMY_SP { - DUMMY_SP + let close_span = if span.is_dummy() { + span } else { span.with_lo(span.hi() - BytePos(self.delim.len() as u32)) }; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index cce8da1dcbd..c443f240780 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -13,7 +13,7 @@ use rustc_data_structures::sync::{Lrc, Lock}; use ast::{self, CrateConfig}; use codemap::{CodeMap, FilePathMapping}; -use syntax_pos::{self, Span, FileMap, NO_EXPANSION, FileName}; +use syntax_pos::{Span, FileMap, FileName}; use errors::{Handler, ColorConfig, DiagnosticBuilder}; use feature_gate::UnstableFeatures; use parse::parser::Parser; @@ -188,8 +188,8 @@ fn filemap_to_parser(sess: & ParseSess, filemap: Lrc<FileMap>) -> Parser { let end_pos = filemap.end_pos; let mut parser = stream_to_parser(sess, filemap_to_stream(sess, filemap, None)); - if parser.token == token::Eof && parser.span == syntax_pos::DUMMY_SP { - parser.span = Span::new(end_pos, end_pos, NO_EXPANSION); + if parser.token == token::Eof && parser.span.is_dummy() { + parser.span = Span::new(end_pos, end_pos, parser.span.ctxt()); } parser diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index faf2cf64e1d..96053f988fa 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -43,7 +43,7 @@ use ast::{BinOpKind, UnOp}; use ast::{RangeEnd, RangeSyntax}; use {ast, attr}; use codemap::{self, CodeMap, Spanned, respan}; -use syntax_pos::{self, Span, MultiSpan, BytePos, FileName, DUMMY_SP, edition::Edition}; +use syntax_pos::{self, Span, MultiSpan, BytePos, FileName, edition::Edition}; use errors::{self, Applicability, DiagnosticBuilder}; use parse::{self, SeqSep, classify, token}; use parse::lexer::TokenAndSpan; @@ -567,7 +567,7 @@ impl<'a> Parser<'a> { if let Some(directory) = directory { parser.directory = directory; - } else if !parser.span.source_equal(&DUMMY_SP) { + } else if !parser.span.is_dummy() { if let FileName::Real(mut path) = sess.codemap().span_to_unmapped_path(parser.span) { path.pop(); parser.directory.path = Cow::from(path); @@ -584,7 +584,7 @@ impl<'a> Parser<'a> { } else { self.token_cursor.next() }; - if next.sp == syntax_pos::DUMMY_SP { + if next.sp.is_dummy() { // Tweak the location for better diagnostics, but keep syntactic context intact. next.sp = self.prev_span.with_ctxt(next.sp.ctxt()); } @@ -6137,7 +6137,7 @@ impl<'a> Parser<'a> { return Err(err); } - let hi = if self.span == syntax_pos::DUMMY_SP { + let hi = if self.span.is_dummy() { inner_lo } else { self.prev_span @@ -6368,7 +6368,7 @@ impl<'a> Parser<'a> { } let mut err = self.diagnostic().struct_span_err(id_sp, "cannot declare a new module at this location"); - if id_sp != syntax_pos::DUMMY_SP { + if !id_sp.is_dummy() { let src_path = self.sess.codemap().span_to_filename(id_sp); if let FileName::Real(src_path) = src_path { if let Some(stem) = src_path.file_stem() { diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 455cc4391dd..8736fcf9729 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -57,8 +57,8 @@ impl Delimited { /// Returns the opening delimiter as a token tree. pub fn open_tt(&self, span: Span) -> TokenTree { - let open_span = if span == DUMMY_SP { - DUMMY_SP + let open_span = if span.is_dummy() { + span } else { span.with_hi(span.lo() + BytePos(self.delim.len() as u32)) }; @@ -67,8 +67,8 @@ impl Delimited { /// Returns the closing delimiter as a token tree. pub fn close_tt(&self, span: Span) -> TokenTree { - let close_span = if span == DUMMY_SP { - DUMMY_SP + let close_span = if span.is_dummy() { + span } else { span.with_lo(span.hi() - BytePos(self.delim.len() as u32)) }; |
