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 | |
parent | 297109ea3263a4ea90a7143a82e46903a8890269 (diff) | |
download | rust-9f92fce77c74cf3c47035e9ff69c29daee0517b3.tar.gz |
Fortify dummy span checking
Diffstat (limited to 'src')
-rw-r--r-- | src/libproc_macro/lib.rs | 4 | ||||
-rw-r--r-- | src/librustc/hir/map/definitions.rs | 11 | ||||
-rw-r--r-- | src/librustc/middle/stability.rs | 6 | ||||
-rw-r--r-- | src/librustc/ty/query/plumbing.rs | 2 | ||||
-rw-r--r-- | src/librustc_codegen_llvm/debuginfo/metadata.rs | 2 | ||||
-rw-r--r-- | src/librustc_codegen_llvm/debuginfo/mod.rs | 2 | ||||
-rw-r--r-- | src/librustc_errors/emitter.rs | 16 | ||||
-rw-r--r-- | src/librustc_metadata/encoder.rs | 4 | ||||
-rw-r--r-- | src/librustc_mir/borrow_check/nll/type_check/mod.rs | 4 | ||||
-rw-r--r-- | src/librustc_resolve/check_unused.rs | 4 | ||||
-rw-r--r-- | src/librustc_resolve/lib.rs | 8 | ||||
-rw-r--r-- | src/librustc_save_analysis/lib.rs | 2 | ||||
-rw-r--r-- | src/librustc_typeck/check_unused.rs | 4 | ||||
-rw-r--r-- | src/librustdoc/clean/mod.rs | 2 | ||||
-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 | ||||
-rw-r--r-- | src/libsyntax_pos/lib.rs | 9 |
21 files changed, 59 insertions, 59 deletions
diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index e580b459196..820b0906a75 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -177,8 +177,6 @@ impl iter::FromIterator<TokenStream> for TokenStream { #[unstable(feature = "proc_macro", issue = "38356")] pub mod token_stream { use syntax::tokenstream; - use syntax_pos::DUMMY_SP; - use {TokenTree, TokenStream, Delimiter}; /// An iterator over `TokenStream`'s `TokenTree`s. @@ -207,7 +205,7 @@ pub mod token_stream { // need to flattened during iteration over stream's token trees. // Eventually this needs to be removed in favor of keeping original token trees // and not doing the roundtrip through AST. - if tree.span().0 == DUMMY_SP { + if tree.span().0.is_dummy() { if let TokenTree::Group(ref group) = tree { if group.delimiter() == Delimiter::None { self.cursor.insert(group.stream.clone().0); diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index b2365e22cc6..e262c951e39 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -486,12 +486,7 @@ impl Definitions { #[inline] pub fn opt_span(&self, def_id: DefId) -> Option<Span> { if def_id.krate == LOCAL_CRATE { - let span = self.def_index_to_span.get(&def_id.index).cloned().unwrap_or(DUMMY_SP); - if span != DUMMY_SP { - Some(span) - } else { - None - } + self.def_index_to_span.get(&def_id.index).cloned() } else { None } @@ -588,8 +583,8 @@ impl Definitions { self.opaque_expansions_that_defined.insert(index, expansion); } - // The span is added if it isn't DUMMY_SP - if span != DUMMY_SP { + // The span is added if it isn't dummy + if !span.is_dummy() { self.def_index_to_span.insert(index, span); } diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index a289a2c21ce..9bf5c4d72b7 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -20,7 +20,7 @@ use ty::{self, TyCtxt}; use middle::privacy::AccessLevels; use session::DiagnosticMessageId; use syntax::symbol::Symbol; -use syntax_pos::{Span, MultiSpan, DUMMY_SP}; +use syntax_pos::{Span, MultiSpan}; use syntax::ast; use syntax::ast::{NodeId, Attribute}; use syntax::feature_gate::{GateIssue, emit_feature_err, find_lang_feature_accepted_version}; @@ -687,7 +687,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let msp: MultiSpan = span.into(); let cm = &self.sess.parse_sess.codemap(); let span_key = msp.primary_span().and_then(|sp: Span| - if sp != DUMMY_SP { + if !sp.is_dummy() { let file = cm.lookup_char_pos(sp.lo()).file; if file.name.is_macros() { None @@ -725,7 +725,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { match item.node { hir::ItemExternCrate(_) => { // compiler-generated `extern crate` items have a dummy span. - if item.span == DUMMY_SP { return } + if item.span.is_dummy() { return } let def_id = self.tcx.hir.local_def_id(item.id); let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) { diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index e17c6fba74c..d783b9574ef 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -708,7 +708,7 @@ macro_rules! define_queries { // FIXME(eddyb) Get more valid Span's on queries. pub fn default_span(&self, tcx: TyCtxt<'_, $tcx, '_>, span: Span) -> Span { - if span != DUMMY_SP { + if !span.is_dummy() { return span; } // The def_span query is used to calculate default_span, diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 1eec57c9c87..6d727f7b048 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -1662,7 +1662,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx, let var_scope = get_namespace_for_item(cx, def_id); let span = tcx.def_span(def_id); - let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP { + let (file_metadata, line_number) = if !span.is_dummy() { let loc = span_start(cx, span); (file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line as c_uint) } else { diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 803966145f7..068dd9821ac 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -219,7 +219,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, let span = mir.span; // This can be the case for functions inlined from another crate - if span == syntax_pos::DUMMY_SP { + if span.is_dummy() { // FIXME(simulacrum): Probably can't happen; remove. return FunctionDebugContext::FunctionWithoutDebugInfo; } diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 92e72fe91d3..e79a3a87738 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -10,7 +10,7 @@ use self::Destination::*; -use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan}; +use syntax_pos::{FileMap, Span, MultiSpan}; use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapperDyn, DiagnosticId}; use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style}; @@ -216,7 +216,7 @@ impl EmitterWriter { if let Some(ref cm) = self.cm { for span_label in msp.span_labels() { - if span_label.span == DUMMY_SP { + if span_label.span.is_dummy() { continue; } @@ -730,7 +730,7 @@ impl EmitterWriter { let mut max = 0; if let Some(ref cm) = self.cm { for primary_span in msp.primary_spans() { - if primary_span != &DUMMY_SP { + if !primary_span.is_dummy() { let hi = cm.lookup_char_pos(primary_span.hi()); if hi.line > max { max = hi.line; @@ -739,7 +739,7 @@ impl EmitterWriter { } if !self.short_message { for span_label in msp.span_labels() { - if span_label.span != DUMMY_SP { + if !span_label.span.is_dummy() { let hi = cm.lookup_char_pos(span_label.span.hi()); if hi.line > max { max = hi.line; @@ -778,7 +778,7 @@ impl EmitterWriter { // First, find all the spans in <*macros> and point instead at their use site for sp in span.primary_spans() { - if *sp == DUMMY_SP { + if sp.is_dummy() { continue; } let call_sp = cm.call_span_if_macro(*sp); @@ -790,7 +790,7 @@ impl EmitterWriter { // Only show macro locations that are local // and display them like a span_note if let Some(def_site) = trace.def_site_span { - if def_site == DUMMY_SP { + if def_site.is_dummy() { continue; } if always_backtrace { @@ -830,7 +830,7 @@ impl EmitterWriter { span.push_span_label(label_span, label_text); } for sp_label in span.span_labels() { - if sp_label.span == DUMMY_SP { + if sp_label.span.is_dummy() { continue; } if cm.span_to_filename(sp_label.span.clone()).is_macros() && @@ -1003,7 +1003,7 @@ impl EmitterWriter { // Make sure our primary file comes first let (primary_lo, cm) = if let (Some(cm), Some(ref primary_span)) = (self.cm.as_ref(), msp.primary_span().as_ref()) { - if primary_span != &&DUMMY_SP { + if !primary_span.is_dummy() { (cm.lookup_char_pos(primary_span.lo()), cm) } else { emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?; diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index d8a224d3bad..93294075272 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -41,7 +41,7 @@ use std::u32; use syntax::ast::{self, CRATE_NODE_ID}; use syntax::attr; use syntax::symbol::keywords; -use syntax_pos::{self, hygiene, FileName, FileMap, Span, DUMMY_SP}; +use syntax_pos::{self, hygiene, FileName, FileMap, Span}; use rustc::hir::{self, PatKind}; use rustc::hir::itemlikevisit::ItemLikeVisitor; @@ -147,7 +147,7 @@ impl<'a, 'tcx> SpecializedEncoder<DefIndex> for EncodeContext<'a, 'tcx> { impl<'a, 'tcx> SpecializedEncoder<Span> for EncodeContext<'a, 'tcx> { fn specialized_encode(&mut self, span: &Span) -> Result<(), Self::Error> { - if *span == DUMMY_SP { + if span.is_dummy() { return TAG_INVALID_SPAN.encode(self) } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 2da2b10edb8..9b6e3e0cab6 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -190,7 +190,7 @@ struct TypeVerifier<'a, 'b: 'a, 'gcx: 'b + 'tcx, 'tcx: 'b> { impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> { fn visit_span(&mut self, span: &Span) { - if *span != DUMMY_SP { + if !span.is_dummy() { self.last_span = *span; } } @@ -1601,7 +1601,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { statement_index: 0, }; for stmt in &block_data.statements { - if stmt.source_info.span != DUMMY_SP { + if !stmt.source_info.span.is_dummy() { self.last_span = stmt.source_info.span; } self.check_stmt(mir, stmt, location); diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 590ce168d5d..0c4b9a546cb 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -86,7 +86,7 @@ impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> { // because this means that they were generated in some fashion by the // compiler and we don't need to consider them. if let ast::ItemKind::Use(..) = item.node { - if item.vis.node == ast::VisibilityKind::Public || item.span.source_equal(&DUMMY_SP) { + if item.vis.node == ast::VisibilityKind::Public || item.span.is_dummy() { return; } } @@ -129,7 +129,7 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) { match directive.subclass { _ if directive.used.get() || directive.vis.get() == ty::Visibility::Public || - directive.span.source_equal(&DUMMY_SP) => {} + directive.span.is_dummy() => {} ImportDirectiveSubclass::ExternCrate(_) => { resolver.maybe_unused_extern_crates.push((directive.id, directive.span)); } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 640e650207e..9887abd60bf 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2861,7 +2861,7 @@ impl<'a> Resolver<'a> { .map(|suggestion| import_candidate_to_paths(&suggestion)).collect::<Vec<_>>(); enum_candidates.sort(); for (sp, variant_path, enum_path) in enum_candidates { - if sp == DUMMY_SP { + if sp.is_dummy() { let msg = format!("there is an enum variant `{}`, \ try using `{}`?", variant_path, @@ -4285,7 +4285,7 @@ impl<'a> Resolver<'a> { let mut err = struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name); err.span_note(b1.span, &msg1); match b2.def() { - Def::Macro(..) if b2.span == DUMMY_SP => + Def::Macro(..) if b2.span.is_dummy() => err.note(&format!("`{}` is also a builtin macro", name)), _ => err.span_note(b2.span, &msg2), }; @@ -4398,14 +4398,14 @@ impl<'a> Resolver<'a> { container)); err.span_label(span, format!("`{}` re{} here", name, new_participle)); - if old_binding.span != DUMMY_SP { + if !old_binding.span.is_dummy() { err.span_label(self.session.codemap().def_span(old_binding.span), format!("previous {} of the {} `{}` here", old_noun, old_kind, name)); } // See https://github.com/rust-lang/rust/issues/32354 if old_binding.is_import() || new_binding.is_import() { - let binding = if new_binding.is_import() && new_binding.span != DUMMY_SP { + let binding = if new_binding.is_import() && !new_binding.span.is_dummy() { new_binding } else { old_binding diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 89d30fd666a..c07db44b36c 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -1157,7 +1157,7 @@ fn escape(s: String) -> String { // Helper function to determine if a span came from a // macro expansion or syntax extension. fn generated_code(span: Span) -> bool { - span.ctxt() != NO_EXPANSION || span == DUMMY_SP + span.ctxt() != NO_EXPANSION || span.is_dummy() } // DefId::index is a newtype and so the JSON serialisation is ugly. Therefore diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 41adde0d4a1..ae5ca5441ad 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -12,7 +12,7 @@ use lint; use rustc::ty::TyCtxt; use syntax::ast; -use syntax_pos::{Span, DUMMY_SP}; +use syntax_pos::Span; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; @@ -39,7 +39,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CheckVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { - if item.vis == hir::Public || item.span == DUMMY_SP { + if item.vis == hir::Public || item.span.is_dummy() { return; } if let hir::ItemUse(ref path, _) = item.node { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 23c367da48d..65babbffffe 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3464,7 +3464,7 @@ impl Span { impl Clean<Span> for syntax_pos::Span { fn clean(&self, cx: &DocContext) -> Span { - if *self == DUMMY_SP { + if self.is_dummy() { return Span::empty(); } 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)) }; diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 308fb118f07..491ce720f36 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -248,6 +248,13 @@ impl Span { self.data().with_ctxt(ctxt) } + /// Returns `true` if this is a dummy span with any hygienic context. + #[inline] + pub fn is_dummy(self) -> bool { + let span = self.data(); + span.lo.0 == 0 && span.hi.0 == 0 + } + /// Returns a new span representing an empty span at the beginning of this span #[inline] pub fn shrink_to_lo(self) -> Span { @@ -263,7 +270,7 @@ impl Span { /// Returns `self` if `self` is not the dummy span, and `other` otherwise. pub fn substitute_dummy(self, other: Span) -> Span { - if self.source_equal(&DUMMY_SP) { other } else { self } + if self.is_dummy() { other } else { self } } /// Return true if `self` fully encloses `other`. |