Skip to content

Commit 463033f

Browse files
committed
Fortify dummy span checking
1 parent b5d0393 commit 463033f

File tree

21 files changed

+59
-59
lines changed

21 files changed

+59
-59
lines changed

src/libproc_macro/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ impl iter::FromIterator<TokenStream> for TokenStream {
177177
#[unstable(feature = "proc_macro", issue = "38356")]
178178
pub mod token_stream {
179179
use syntax::tokenstream;
180-
use syntax_pos::DUMMY_SP;
181-
182180
use {TokenTree, TokenStream, Delimiter};
183181

184182
/// An iterator over `TokenStream`'s `TokenTree`s.
@@ -207,7 +205,7 @@ pub mod token_stream {
207205
// need to flattened during iteration over stream's token trees.
208206
// Eventually this needs to be removed in favor of keeping original token trees
209207
// and not doing the roundtrip through AST.
210-
if tree.span().0 == DUMMY_SP {
208+
if tree.span().0.is_dummy() {
211209
if let TokenTree::Group(ref group) = tree {
212210
if group.delimiter() == Delimiter::None {
213211
self.cursor.insert(group.stream.clone().0);

src/librustc/hir/map/definitions.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,7 @@ impl Definitions {
486486
#[inline]
487487
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
488488
if def_id.krate == LOCAL_CRATE {
489-
let span = self.def_index_to_span.get(&def_id.index).cloned().unwrap_or(DUMMY_SP);
490-
if span != DUMMY_SP {
491-
Some(span)
492-
} else {
493-
None
494-
}
489+
self.def_index_to_span.get(&def_id.index).cloned()
495490
} else {
496491
None
497492
}
@@ -588,8 +583,8 @@ impl Definitions {
588583
self.opaque_expansions_that_defined.insert(index, expansion);
589584
}
590585

591-
// The span is added if it isn't DUMMY_SP
592-
if span != DUMMY_SP {
586+
// The span is added if it isn't dummy
587+
if !span.is_dummy() {
593588
self.def_index_to_span.insert(index, span);
594589
}
595590

src/librustc/middle/stability.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ty::{self, TyCtxt};
2020
use middle::privacy::AccessLevels;
2121
use session::DiagnosticMessageId;
2222
use syntax::symbol::Symbol;
23-
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
23+
use syntax_pos::{Span, MultiSpan};
2424
use syntax::ast;
2525
use syntax::ast::{NodeId, Attribute};
2626
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> {
687687
let msp: MultiSpan = span.into();
688688
let cm = &self.sess.parse_sess.codemap();
689689
let span_key = msp.primary_span().and_then(|sp: Span|
690-
if sp != DUMMY_SP {
690+
if !sp.is_dummy() {
691691
let file = cm.lookup_char_pos(sp.lo()).file;
692692
if file.name.is_macros() {
693693
None
@@ -725,7 +725,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
725725
match item.node {
726726
hir::ItemExternCrate(_) => {
727727
// compiler-generated `extern crate` items have a dummy span.
728-
if item.span == DUMMY_SP { return }
728+
if item.span.is_dummy() { return }
729729

730730
let def_id = self.tcx.hir.local_def_id(item.id);
731731
let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) {

src/librustc/ty/query/plumbing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ macro_rules! define_queries {
708708

709709
// FIXME(eddyb) Get more valid Span's on queries.
710710
pub fn default_span(&self, tcx: TyCtxt<'_, $tcx, '_>, span: Span) -> Span {
711-
if span != DUMMY_SP {
711+
if !span.is_dummy() {
712712
return span;
713713
}
714714
// The def_span query is used to calculate default_span,

src/librustc_codegen_llvm/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
16621662
let var_scope = get_namespace_for_item(cx, def_id);
16631663
let span = tcx.def_span(def_id);
16641664

1665-
let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP {
1665+
let (file_metadata, line_number) = if !span.is_dummy() {
16661666
let loc = span_start(cx, span);
16671667
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line as c_uint)
16681668
} else {

src/librustc_codegen_llvm/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
219219
let span = mir.span;
220220

221221
// This can be the case for functions inlined from another crate
222-
if span == syntax_pos::DUMMY_SP {
222+
if span.is_dummy() {
223223
// FIXME(simulacrum): Probably can't happen; remove.
224224
return FunctionDebugContext::FunctionWithoutDebugInfo;
225225
}

src/librustc_errors/emitter.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use self::Destination::*;
1212

13-
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan};
13+
use syntax_pos::{FileMap, Span, MultiSpan};
1414

1515
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapperDyn, DiagnosticId};
1616
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
@@ -216,7 +216,7 @@ impl EmitterWriter {
216216

217217
if let Some(ref cm) = self.cm {
218218
for span_label in msp.span_labels() {
219-
if span_label.span == DUMMY_SP {
219+
if span_label.span.is_dummy() {
220220
continue;
221221
}
222222

@@ -730,7 +730,7 @@ impl EmitterWriter {
730730
let mut max = 0;
731731
if let Some(ref cm) = self.cm {
732732
for primary_span in msp.primary_spans() {
733-
if primary_span != &DUMMY_SP {
733+
if !primary_span.is_dummy() {
734734
let hi = cm.lookup_char_pos(primary_span.hi());
735735
if hi.line > max {
736736
max = hi.line;
@@ -739,7 +739,7 @@ impl EmitterWriter {
739739
}
740740
if !self.short_message {
741741
for span_label in msp.span_labels() {
742-
if span_label.span != DUMMY_SP {
742+
if !span_label.span.is_dummy() {
743743
let hi = cm.lookup_char_pos(span_label.span.hi());
744744
if hi.line > max {
745745
max = hi.line;
@@ -778,7 +778,7 @@ impl EmitterWriter {
778778

779779
// First, find all the spans in <*macros> and point instead at their use site
780780
for sp in span.primary_spans() {
781-
if *sp == DUMMY_SP {
781+
if sp.is_dummy() {
782782
continue;
783783
}
784784
let call_sp = cm.call_span_if_macro(*sp);
@@ -790,7 +790,7 @@ impl EmitterWriter {
790790
// Only show macro locations that are local
791791
// and display them like a span_note
792792
if let Some(def_site) = trace.def_site_span {
793-
if def_site == DUMMY_SP {
793+
if def_site.is_dummy() {
794794
continue;
795795
}
796796
if always_backtrace {
@@ -830,7 +830,7 @@ impl EmitterWriter {
830830
span.push_span_label(label_span, label_text);
831831
}
832832
for sp_label in span.span_labels() {
833-
if sp_label.span == DUMMY_SP {
833+
if sp_label.span.is_dummy() {
834834
continue;
835835
}
836836
if cm.span_to_filename(sp_label.span.clone()).is_macros() &&
@@ -1003,7 +1003,7 @@ impl EmitterWriter {
10031003
// Make sure our primary file comes first
10041004
let (primary_lo, cm) = if let (Some(cm), Some(ref primary_span)) =
10051005
(self.cm.as_ref(), msp.primary_span().as_ref()) {
1006-
if primary_span != &&DUMMY_SP {
1006+
if !primary_span.is_dummy() {
10071007
(cm.lookup_char_pos(primary_span.lo()), cm)
10081008
} else {
10091009
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;

src/librustc_metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use syntax::ast::{self, CRATE_NODE_ID};
4444
use syntax::codemap::Spanned;
4545
use syntax::attr;
4646
use syntax::symbol::Symbol;
47-
use syntax_pos::{self, hygiene, FileName, FileMap, Span, DUMMY_SP};
47+
use syntax_pos::{self, hygiene, FileName, FileMap, Span};
4848

4949
use rustc::hir::{self, PatKind};
5050
use rustc::hir::itemlikevisit::ItemLikeVisitor;
@@ -150,7 +150,7 @@ impl<'a, 'tcx> SpecializedEncoder<DefIndex> for EncodeContext<'a, 'tcx> {
150150

151151
impl<'a, 'tcx> SpecializedEncoder<Span> for EncodeContext<'a, 'tcx> {
152152
fn specialized_encode(&mut self, span: &Span) -> Result<(), Self::Error> {
153-
if *span == DUMMY_SP {
153+
if span.is_dummy() {
154154
return TAG_INVALID_SPAN.encode(self)
155155
}
156156

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct TypeVerifier<'a, 'b: 'a, 'gcx: 'b + 'tcx, 'tcx: 'b> {
191191

192192
impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
193193
fn visit_span(&mut self, span: &Span) {
194-
if *span != DUMMY_SP {
194+
if !span.is_dummy() {
195195
self.last_span = *span;
196196
}
197197
}
@@ -1658,7 +1658,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
16581658
statement_index: 0,
16591659
};
16601660
for stmt in &block_data.statements {
1661-
if stmt.source_info.span != DUMMY_SP {
1661+
if !stmt.source_info.span.is_dummy() {
16621662
self.last_span = stmt.source_info.span;
16631663
}
16641664
self.check_stmt(mir, stmt, location);

src/librustc_resolve/check_unused.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
8686
// because this means that they were generated in some fashion by the
8787
// compiler and we don't need to consider them.
8888
if let ast::ItemKind::Use(..) = item.node {
89-
if item.vis.node == ast::VisibilityKind::Public || item.span.source_equal(&DUMMY_SP) {
89+
if item.vis.node == ast::VisibilityKind::Public || item.span.is_dummy() {
9090
return;
9191
}
9292
}
@@ -129,7 +129,7 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) {
129129
match directive.subclass {
130130
_ if directive.used.get() ||
131131
directive.vis.get() == ty::Visibility::Public ||
132-
directive.span.source_equal(&DUMMY_SP) => {}
132+
directive.span.is_dummy() => {}
133133
ImportDirectiveSubclass::ExternCrate(_) => {
134134
resolver.maybe_unused_extern_crates.push((directive.id, directive.span));
135135
}

src/librustc_resolve/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,7 @@ impl<'a> Resolver<'a> {
28632863
.map(|suggestion| import_candidate_to_paths(&suggestion)).collect::<Vec<_>>();
28642864
enum_candidates.sort();
28652865
for (sp, variant_path, enum_path) in enum_candidates {
2866-
if sp == DUMMY_SP {
2866+
if sp.is_dummy() {
28672867
let msg = format!("there is an enum variant `{}`, \
28682868
try using `{}`?",
28692869
variant_path,
@@ -4287,7 +4287,7 @@ impl<'a> Resolver<'a> {
42874287
let mut err = struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name);
42884288
err.span_note(b1.span, &msg1);
42894289
match b2.def() {
4290-
Def::Macro(..) if b2.span == DUMMY_SP =>
4290+
Def::Macro(..) if b2.span.is_dummy() =>
42914291
err.note(&format!("`{}` is also a builtin macro", name)),
42924292
_ => err.span_note(b2.span, &msg2),
42934293
};
@@ -4400,14 +4400,14 @@ impl<'a> Resolver<'a> {
44004400
container));
44014401

44024402
err.span_label(span, format!("`{}` re{} here", name, new_participle));
4403-
if old_binding.span != DUMMY_SP {
4403+
if !old_binding.span.is_dummy() {
44044404
err.span_label(self.session.codemap().def_span(old_binding.span),
44054405
format!("previous {} of the {} `{}` here", old_noun, old_kind, name));
44064406
}
44074407

44084408
// See https://github.com/rust-lang/rust/issues/32354
44094409
if old_binding.is_import() || new_binding.is_import() {
4410-
let binding = if new_binding.is_import() && new_binding.span != DUMMY_SP {
4410+
let binding = if new_binding.is_import() && !new_binding.span.is_dummy() {
44114411
new_binding
44124412
} else {
44134413
old_binding

src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ fn escape(s: String) -> String {
11561156
// Helper function to determine if a span came from a
11571157
// macro expansion or syntax extension.
11581158
fn generated_code(span: Span) -> bool {
1159-
span.ctxt() != NO_EXPANSION || span == DUMMY_SP
1159+
span.ctxt() != NO_EXPANSION || span.is_dummy()
11601160
}
11611161

11621162
// DefId::index is a newtype and so the JSON serialisation is ugly. Therefore

src/librustc_typeck/check_unused.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use lint;
1212
use rustc::ty::TyCtxt;
1313

1414
use syntax::ast;
15-
use syntax_pos::{Span, DUMMY_SP};
15+
use syntax_pos::Span;
1616

1717
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
1818
use rustc::hir::itemlikevisit::ItemLikeVisitor;
@@ -39,7 +39,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
3939

4040
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CheckVisitor<'a, 'tcx> {
4141
fn visit_item(&mut self, item: &hir::Item) {
42-
if item.vis == hir::Public || item.span == DUMMY_SP {
42+
if item.vis == hir::Public || item.span.is_dummy() {
4343
return;
4444
}
4545
if let hir::ItemUse(ref path, _) = item.node {

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3464,7 +3464,7 @@ impl Span {
34643464

34653465
impl Clean<Span> for syntax_pos::Span {
34663466
fn clean(&self, cx: &DocContext) -> Span {
3467-
if *self == DUMMY_SP {
3467+
if self.is_dummy() {
34683468
return Span::empty();
34693469
}
34703470

src/libsyntax/codemap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl CodeMap {
459459
}
460460

461461
pub fn span_to_string(&self, sp: Span) -> String {
462-
if self.files.borrow().file_maps.is_empty() && sp.source_equal(&DUMMY_SP) {
462+
if self.files.borrow().file_maps.is_empty() && sp.is_dummy() {
463463
return "no-location".to_string();
464464
}
465465

src/libsyntax/ext/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
12891289
// Detect if this is an inline module (`mod m { ... }` as opposed to `mod m;`).
12901290
// In the non-inline case, `inner` is never the dummy span (c.f. `parse_item_mod`).
12911291
// Thus, if `inner` is the dummy span, we know the module is inline.
1292-
let inline_module = item.span.contains(inner) || inner == DUMMY_SP;
1292+
let inline_module = item.span.contains(inner) || inner.is_dummy();
12931293

12941294
if inline_module {
12951295
if let Some(path) = attr::first_attr_value_str_by_name(&item.attrs, "path") {

src/libsyntax/ext/tt/quoted.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use feature_gate::{self, emit_feature_err, Features, GateIssue};
1414
use parse::{token, ParseSess};
1515
use print::pprust;
1616
use symbol::keywords;
17-
use syntax_pos::{BytePos, Span, DUMMY_SP};
17+
use syntax_pos::{BytePos, Span};
1818
use tokenstream;
1919

2020
use std::iter::Peekable;
@@ -41,8 +41,8 @@ impl Delimited {
4141

4242
/// Return a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
4343
pub fn open_tt(&self, span: Span) -> TokenTree {
44-
let open_span = if span == DUMMY_SP {
45-
DUMMY_SP
44+
let open_span = if span.is_dummy() {
45+
span
4646
} else {
4747
span.with_lo(span.lo() + BytePos(self.delim.len() as u32))
4848
};
@@ -51,8 +51,8 @@ impl Delimited {
5151

5252
/// Return a `self::TokenTree` with a `Span` corresponding to the closing delimiter.
5353
pub fn close_tt(&self, span: Span) -> TokenTree {
54-
let close_span = if span == DUMMY_SP {
55-
DUMMY_SP
54+
let close_span = if span.is_dummy() {
55+
span
5656
} else {
5757
span.with_lo(span.hi() - BytePos(self.delim.len() as u32))
5858
};

src/libsyntax/parse/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use rustc_data_structures::sync::{Lrc, Lock};
1414
use ast::{self, CrateConfig};
1515
use codemap::{CodeMap, FilePathMapping};
16-
use syntax_pos::{self, Span, FileMap, NO_EXPANSION, FileName};
16+
use syntax_pos::{Span, FileMap, FileName};
1717
use errors::{Handler, ColorConfig, DiagnosticBuilder};
1818
use feature_gate::UnstableFeatures;
1919
use parse::parser::Parser;
@@ -188,8 +188,8 @@ fn filemap_to_parser(sess: & ParseSess, filemap: Lrc<FileMap>) -> Parser {
188188
let end_pos = filemap.end_pos;
189189
let mut parser = stream_to_parser(sess, filemap_to_stream(sess, filemap, None));
190190

191-
if parser.token == token::Eof && parser.span == syntax_pos::DUMMY_SP {
192-
parser.span = Span::new(end_pos, end_pos, NO_EXPANSION);
191+
if parser.token == token::Eof && parser.span.is_dummy() {
192+
parser.span = Span::new(end_pos, end_pos, parser.span.ctxt());
193193
}
194194

195195
parser

0 commit comments

Comments
 (0)