Skip to content

Commit 9f92fce

Browse files
committed
Fortify dummy span checking
1 parent 297109e commit 9f92fce

File tree

21 files changed

+59
-59
lines changed

21 files changed

+59
-59
lines changed

src/libproc_macro/lib.rs

Lines changed: 1 addition & 3 deletions
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

Lines changed: 3 additions & 8 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::u32;
4141
use syntax::ast::{self, CRATE_NODE_ID};
4242
use syntax::attr;
4343
use syntax::symbol::keywords;
44-
use syntax_pos::{self, hygiene, FileName, FileMap, Span, DUMMY_SP};
44+
use syntax_pos::{self, hygiene, FileName, FileMap, Span};
4545

4646
use rustc::hir::{self, PatKind};
4747
use rustc::hir::itemlikevisit::ItemLikeVisitor;
@@ -147,7 +147,7 @@ impl<'a, 'tcx> SpecializedEncoder<DefIndex> for EncodeContext<'a, 'tcx> {
147147

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ struct TypeVerifier<'a, 'b: 'a, 'gcx: 'b + 'tcx, 'tcx: 'b> {
190190

191191
impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
192192
fn visit_span(&mut self, span: &Span) {
193-
if *span != DUMMY_SP {
193+
if !span.is_dummy() {
194194
self.last_span = *span;
195195
}
196196
}
@@ -1601,7 +1601,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
16011601
statement_index: 0,
16021602
};
16031603
for stmt in &block_data.statements {
1604-
if stmt.source_info.span != DUMMY_SP {
1604+
if !stmt.source_info.span.is_dummy() {
16051605
self.last_span = stmt.source_info.span;
16061606
}
16071607
self.check_stmt(mir, stmt, location);

src/librustc_resolve/check_unused.rs

Lines changed: 2 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)