Fortify dummy span checking
This commit is contained in:
parent
297109ea32
commit
9f92fce77c
21 changed files with 59 additions and 59 deletions
|
@ -177,8 +177,6 @@ impl iter::FromIterator<TokenStream> for TokenStream {
|
||||||
#[unstable(feature = "proc_macro", issue = "38356")]
|
#[unstable(feature = "proc_macro", issue = "38356")]
|
||||||
pub mod token_stream {
|
pub mod token_stream {
|
||||||
use syntax::tokenstream;
|
use syntax::tokenstream;
|
||||||
use syntax_pos::DUMMY_SP;
|
|
||||||
|
|
||||||
use {TokenTree, TokenStream, Delimiter};
|
use {TokenTree, TokenStream, Delimiter};
|
||||||
|
|
||||||
/// An iterator over `TokenStream`'s `TokenTree`s.
|
/// 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.
|
// need to flattened during iteration over stream's token trees.
|
||||||
// Eventually this needs to be removed in favor of keeping original token trees
|
// Eventually this needs to be removed in favor of keeping original token trees
|
||||||
// and not doing the roundtrip through AST.
|
// 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 let TokenTree::Group(ref group) = tree {
|
||||||
if group.delimiter() == Delimiter::None {
|
if group.delimiter() == Delimiter::None {
|
||||||
self.cursor.insert(group.stream.clone().0);
|
self.cursor.insert(group.stream.clone().0);
|
||||||
|
|
|
@ -486,12 +486,7 @@ impl Definitions {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
|
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
|
||||||
if def_id.krate == LOCAL_CRATE {
|
if def_id.krate == LOCAL_CRATE {
|
||||||
let span = self.def_index_to_span.get(&def_id.index).cloned().unwrap_or(DUMMY_SP);
|
self.def_index_to_span.get(&def_id.index).cloned()
|
||||||
if span != DUMMY_SP {
|
|
||||||
Some(span)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -588,8 +583,8 @@ impl Definitions {
|
||||||
self.opaque_expansions_that_defined.insert(index, expansion);
|
self.opaque_expansions_that_defined.insert(index, expansion);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The span is added if it isn't DUMMY_SP
|
// The span is added if it isn't dummy
|
||||||
if span != DUMMY_SP {
|
if !span.is_dummy() {
|
||||||
self.def_index_to_span.insert(index, span);
|
self.def_index_to_span.insert(index, span);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ use ty::{self, TyCtxt};
|
||||||
use middle::privacy::AccessLevels;
|
use middle::privacy::AccessLevels;
|
||||||
use session::DiagnosticMessageId;
|
use session::DiagnosticMessageId;
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
|
use syntax_pos::{Span, MultiSpan};
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast::{NodeId, Attribute};
|
use syntax::ast::{NodeId, Attribute};
|
||||||
use syntax::feature_gate::{GateIssue, emit_feature_err, find_lang_feature_accepted_version};
|
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 msp: MultiSpan = span.into();
|
||||||
let cm = &self.sess.parse_sess.codemap();
|
let cm = &self.sess.parse_sess.codemap();
|
||||||
let span_key = msp.primary_span().and_then(|sp: Span|
|
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;
|
let file = cm.lookup_char_pos(sp.lo()).file;
|
||||||
if file.name.is_macros() {
|
if file.name.is_macros() {
|
||||||
None
|
None
|
||||||
|
@ -725,7 +725,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
||||||
match item.node {
|
match item.node {
|
||||||
hir::ItemExternCrate(_) => {
|
hir::ItemExternCrate(_) => {
|
||||||
// compiler-generated `extern crate` items have a dummy span.
|
// 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 def_id = self.tcx.hir.local_def_id(item.id);
|
||||||
let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) {
|
let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) {
|
||||||
|
|
|
@ -708,7 +708,7 @@ macro_rules! define_queries {
|
||||||
|
|
||||||
// FIXME(eddyb) Get more valid Span's on queries.
|
// FIXME(eddyb) Get more valid Span's on queries.
|
||||||
pub fn default_span(&self, tcx: TyCtxt<'_, $tcx, '_>, span: Span) -> Span {
|
pub fn default_span(&self, tcx: TyCtxt<'_, $tcx, '_>, span: Span) -> Span {
|
||||||
if span != DUMMY_SP {
|
if !span.is_dummy() {
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
// The def_span query is used to calculate default_span,
|
// The def_span query is used to calculate default_span,
|
||||||
|
|
|
@ -1662,7 +1662,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
|
||||||
let var_scope = get_namespace_for_item(cx, def_id);
|
let var_scope = get_namespace_for_item(cx, def_id);
|
||||||
let span = tcx.def_span(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);
|
let loc = span_start(cx, span);
|
||||||
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line as c_uint)
|
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line as c_uint)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -219,7 +219,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
||||||
let span = mir.span;
|
let span = mir.span;
|
||||||
|
|
||||||
// This can be the case for functions inlined from another crate
|
// 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.
|
// FIXME(simulacrum): Probably can't happen; remove.
|
||||||
return FunctionDebugContext::FunctionWithoutDebugInfo;
|
return FunctionDebugContext::FunctionWithoutDebugInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
use self::Destination::*;
|
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 {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapperDyn, DiagnosticId};
|
||||||
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
|
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
|
||||||
|
@ -216,7 +216,7 @@ impl EmitterWriter {
|
||||||
|
|
||||||
if let Some(ref cm) = self.cm {
|
if let Some(ref cm) = self.cm {
|
||||||
for span_label in msp.span_labels() {
|
for span_label in msp.span_labels() {
|
||||||
if span_label.span == DUMMY_SP {
|
if span_label.span.is_dummy() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,7 +730,7 @@ impl EmitterWriter {
|
||||||
let mut max = 0;
|
let mut max = 0;
|
||||||
if let Some(ref cm) = self.cm {
|
if let Some(ref cm) = self.cm {
|
||||||
for primary_span in msp.primary_spans() {
|
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());
|
let hi = cm.lookup_char_pos(primary_span.hi());
|
||||||
if hi.line > max {
|
if hi.line > max {
|
||||||
max = hi.line;
|
max = hi.line;
|
||||||
|
@ -739,7 +739,7 @@ impl EmitterWriter {
|
||||||
}
|
}
|
||||||
if !self.short_message {
|
if !self.short_message {
|
||||||
for span_label in msp.span_labels() {
|
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());
|
let hi = cm.lookup_char_pos(span_label.span.hi());
|
||||||
if hi.line > max {
|
if hi.line > max {
|
||||||
max = hi.line;
|
max = hi.line;
|
||||||
|
@ -778,7 +778,7 @@ impl EmitterWriter {
|
||||||
|
|
||||||
// First, find all the spans in <*macros> and point instead at their use site
|
// First, find all the spans in <*macros> and point instead at their use site
|
||||||
for sp in span.primary_spans() {
|
for sp in span.primary_spans() {
|
||||||
if *sp == DUMMY_SP {
|
if sp.is_dummy() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let call_sp = cm.call_span_if_macro(*sp);
|
let call_sp = cm.call_span_if_macro(*sp);
|
||||||
|
@ -790,7 +790,7 @@ impl EmitterWriter {
|
||||||
// Only show macro locations that are local
|
// Only show macro locations that are local
|
||||||
// and display them like a span_note
|
// and display them like a span_note
|
||||||
if let Some(def_site) = trace.def_site_span {
|
if let Some(def_site) = trace.def_site_span {
|
||||||
if def_site == DUMMY_SP {
|
if def_site.is_dummy() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if always_backtrace {
|
if always_backtrace {
|
||||||
|
@ -830,7 +830,7 @@ impl EmitterWriter {
|
||||||
span.push_span_label(label_span, label_text);
|
span.push_span_label(label_span, label_text);
|
||||||
}
|
}
|
||||||
for sp_label in span.span_labels() {
|
for sp_label in span.span_labels() {
|
||||||
if sp_label.span == DUMMY_SP {
|
if sp_label.span.is_dummy() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if cm.span_to_filename(sp_label.span.clone()).is_macros() &&
|
if cm.span_to_filename(sp_label.span.clone()).is_macros() &&
|
||||||
|
@ -1003,7 +1003,7 @@ impl EmitterWriter {
|
||||||
// Make sure our primary file comes first
|
// Make sure our primary file comes first
|
||||||
let (primary_lo, cm) = if let (Some(cm), Some(ref primary_span)) =
|
let (primary_lo, cm) = if let (Some(cm), Some(ref primary_span)) =
|
||||||
(self.cm.as_ref(), msp.primary_span().as_ref()) {
|
(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)
|
(cm.lookup_char_pos(primary_span.lo()), cm)
|
||||||
} else {
|
} else {
|
||||||
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
|
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
|
||||||
|
|
|
@ -41,7 +41,7 @@ use std::u32;
|
||||||
use syntax::ast::{self, CRATE_NODE_ID};
|
use syntax::ast::{self, CRATE_NODE_ID};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::symbol::keywords;
|
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::{self, PatKind};
|
||||||
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
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> {
|
impl<'a, 'tcx> SpecializedEncoder<Span> for EncodeContext<'a, 'tcx> {
|
||||||
fn specialized_encode(&mut self, span: &Span) -> Result<(), Self::Error> {
|
fn specialized_encode(&mut self, span: &Span) -> Result<(), Self::Error> {
|
||||||
if *span == DUMMY_SP {
|
if span.is_dummy() {
|
||||||
return TAG_INVALID_SPAN.encode(self)
|
return TAG_INVALID_SPAN.encode(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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> {
|
impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
|
||||||
fn visit_span(&mut self, span: &Span) {
|
fn visit_span(&mut self, span: &Span) {
|
||||||
if *span != DUMMY_SP {
|
if !span.is_dummy() {
|
||||||
self.last_span = *span;
|
self.last_span = *span;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1601,7 +1601,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
||||||
statement_index: 0,
|
statement_index: 0,
|
||||||
};
|
};
|
||||||
for stmt in &block_data.statements {
|
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.last_span = stmt.source_info.span;
|
||||||
}
|
}
|
||||||
self.check_stmt(mir, stmt, location);
|
self.check_stmt(mir, stmt, location);
|
||||||
|
|
|
@ -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
|
// because this means that they were generated in some fashion by the
|
||||||
// compiler and we don't need to consider them.
|
// compiler and we don't need to consider them.
|
||||||
if let ast::ItemKind::Use(..) = item.node {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) {
|
||||||
match directive.subclass {
|
match directive.subclass {
|
||||||
_ if directive.used.get() ||
|
_ if directive.used.get() ||
|
||||||
directive.vis.get() == ty::Visibility::Public ||
|
directive.vis.get() == ty::Visibility::Public ||
|
||||||
directive.span.source_equal(&DUMMY_SP) => {}
|
directive.span.is_dummy() => {}
|
||||||
ImportDirectiveSubclass::ExternCrate(_) => {
|
ImportDirectiveSubclass::ExternCrate(_) => {
|
||||||
resolver.maybe_unused_extern_crates.push((directive.id, directive.span));
|
resolver.maybe_unused_extern_crates.push((directive.id, directive.span));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2861,7 +2861,7 @@ impl<'a> Resolver<'a> {
|
||||||
.map(|suggestion| import_candidate_to_paths(&suggestion)).collect::<Vec<_>>();
|
.map(|suggestion| import_candidate_to_paths(&suggestion)).collect::<Vec<_>>();
|
||||||
enum_candidates.sort();
|
enum_candidates.sort();
|
||||||
for (sp, variant_path, enum_path) in enum_candidates {
|
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 `{}`, \
|
let msg = format!("there is an enum variant `{}`, \
|
||||||
try using `{}`?",
|
try using `{}`?",
|
||||||
variant_path,
|
variant_path,
|
||||||
|
@ -4285,7 +4285,7 @@ impl<'a> Resolver<'a> {
|
||||||
let mut err = struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name);
|
let mut err = struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name);
|
||||||
err.span_note(b1.span, &msg1);
|
err.span_note(b1.span, &msg1);
|
||||||
match b2.def() {
|
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.note(&format!("`{}` is also a builtin macro", name)),
|
||||||
_ => err.span_note(b2.span, &msg2),
|
_ => err.span_note(b2.span, &msg2),
|
||||||
};
|
};
|
||||||
|
@ -4398,14 +4398,14 @@ impl<'a> Resolver<'a> {
|
||||||
container));
|
container));
|
||||||
|
|
||||||
err.span_label(span, format!("`{}` re{} here", name, new_participle));
|
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),
|
err.span_label(self.session.codemap().def_span(old_binding.span),
|
||||||
format!("previous {} of the {} `{}` here", old_noun, old_kind, name));
|
format!("previous {} of the {} `{}` here", old_noun, old_kind, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// See https://github.com/rust-lang/rust/issues/32354
|
// See https://github.com/rust-lang/rust/issues/32354
|
||||||
if old_binding.is_import() || new_binding.is_import() {
|
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
|
new_binding
|
||||||
} else {
|
} else {
|
||||||
old_binding
|
old_binding
|
||||||
|
|
|
@ -1157,7 +1157,7 @@ fn escape(s: String) -> String {
|
||||||
// Helper function to determine if a span came from a
|
// Helper function to determine if a span came from a
|
||||||
// macro expansion or syntax extension.
|
// macro expansion or syntax extension.
|
||||||
fn generated_code(span: Span) -> bool {
|
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
|
// DefId::index is a newtype and so the JSON serialisation is ugly. Therefore
|
||||||
|
|
|
@ -12,7 +12,7 @@ use lint;
|
||||||
use rustc::ty::TyCtxt;
|
use rustc::ty::TyCtxt;
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||||
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
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> {
|
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CheckVisitor<'a, 'tcx> {
|
||||||
fn visit_item(&mut self, item: &hir::Item) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if let hir::ItemUse(ref path, _) = item.node {
|
if let hir::ItemUse(ref path, _) = item.node {
|
||||||
|
|
|
@ -3464,7 +3464,7 @@ impl Span {
|
||||||
|
|
||||||
impl Clean<Span> for syntax_pos::Span {
|
impl Clean<Span> for syntax_pos::Span {
|
||||||
fn clean(&self, cx: &DocContext) -> Span {
|
fn clean(&self, cx: &DocContext) -> Span {
|
||||||
if *self == DUMMY_SP {
|
if self.is_dummy() {
|
||||||
return Span::empty();
|
return Span::empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -443,7 +443,7 @@ impl CodeMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_to_string(&self, sp: Span) -> String {
|
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();
|
return "no-location".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;`).
|
// 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`).
|
// 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.
|
// 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 inline_module {
|
||||||
if let Some(path) = attr::first_attr_value_str_by_name(&item.attrs, "path") {
|
if let Some(path) = attr::first_attr_value_str_by_name(&item.attrs, "path") {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use feature_gate::{self, emit_feature_err, Features, GateIssue};
|
||||||
use parse::{token, ParseSess};
|
use parse::{token, ParseSess};
|
||||||
use print::pprust;
|
use print::pprust;
|
||||||
use symbol::keywords;
|
use symbol::keywords;
|
||||||
use syntax_pos::{BytePos, Span, DUMMY_SP};
|
use syntax_pos::{BytePos, Span};
|
||||||
use tokenstream;
|
use tokenstream;
|
||||||
|
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
|
@ -41,8 +41,8 @@ impl Delimited {
|
||||||
|
|
||||||
/// Return a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
|
/// Return a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
|
||||||
pub fn open_tt(&self, span: Span) -> TokenTree {
|
pub fn open_tt(&self, span: Span) -> TokenTree {
|
||||||
let open_span = if span == DUMMY_SP {
|
let open_span = if span.is_dummy() {
|
||||||
DUMMY_SP
|
span
|
||||||
} else {
|
} else {
|
||||||
span.with_lo(span.lo() + BytePos(self.delim.len() as u32))
|
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.
|
/// Return a `self::TokenTree` with a `Span` corresponding to the closing delimiter.
|
||||||
pub fn close_tt(&self, span: Span) -> TokenTree {
|
pub fn close_tt(&self, span: Span) -> TokenTree {
|
||||||
let close_span = if span == DUMMY_SP {
|
let close_span = if span.is_dummy() {
|
||||||
DUMMY_SP
|
span
|
||||||
} else {
|
} else {
|
||||||
span.with_lo(span.hi() - BytePos(self.delim.len() as u32))
|
span.with_lo(span.hi() - BytePos(self.delim.len() as u32))
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
use rustc_data_structures::sync::{Lrc, Lock};
|
use rustc_data_structures::sync::{Lrc, Lock};
|
||||||
use ast::{self, CrateConfig};
|
use ast::{self, CrateConfig};
|
||||||
use codemap::{CodeMap, FilePathMapping};
|
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 errors::{Handler, ColorConfig, DiagnosticBuilder};
|
||||||
use feature_gate::UnstableFeatures;
|
use feature_gate::UnstableFeatures;
|
||||||
use parse::parser::Parser;
|
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 end_pos = filemap.end_pos;
|
||||||
let mut parser = stream_to_parser(sess, filemap_to_stream(sess, filemap, None));
|
let mut parser = stream_to_parser(sess, filemap_to_stream(sess, filemap, None));
|
||||||
|
|
||||||
if parser.token == token::Eof && parser.span == syntax_pos::DUMMY_SP {
|
if parser.token == token::Eof && parser.span.is_dummy() {
|
||||||
parser.span = Span::new(end_pos, end_pos, NO_EXPANSION);
|
parser.span = Span::new(end_pos, end_pos, parser.span.ctxt());
|
||||||
}
|
}
|
||||||
|
|
||||||
parser
|
parser
|
||||||
|
|
|
@ -43,7 +43,7 @@ use ast::{BinOpKind, UnOp};
|
||||||
use ast::{RangeEnd, RangeSyntax};
|
use ast::{RangeEnd, RangeSyntax};
|
||||||
use {ast, attr};
|
use {ast, attr};
|
||||||
use codemap::{self, CodeMap, Spanned, respan};
|
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 errors::{self, Applicability, DiagnosticBuilder};
|
||||||
use parse::{self, SeqSep, classify, token};
|
use parse::{self, SeqSep, classify, token};
|
||||||
use parse::lexer::TokenAndSpan;
|
use parse::lexer::TokenAndSpan;
|
||||||
|
@ -567,7 +567,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
if let Some(directory) = directory {
|
if let Some(directory) = directory {
|
||||||
parser.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) {
|
if let FileName::Real(mut path) = sess.codemap().span_to_unmapped_path(parser.span) {
|
||||||
path.pop();
|
path.pop();
|
||||||
parser.directory.path = Cow::from(path);
|
parser.directory.path = Cow::from(path);
|
||||||
|
@ -584,7 +584,7 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
self.token_cursor.next()
|
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.
|
// Tweak the location for better diagnostics, but keep syntactic context intact.
|
||||||
next.sp = self.prev_span.with_ctxt(next.sp.ctxt());
|
next.sp = self.prev_span.with_ctxt(next.sp.ctxt());
|
||||||
}
|
}
|
||||||
|
@ -6137,7 +6137,7 @@ impl<'a> Parser<'a> {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hi = if self.span == syntax_pos::DUMMY_SP {
|
let hi = if self.span.is_dummy() {
|
||||||
inner_lo
|
inner_lo
|
||||||
} else {
|
} else {
|
||||||
self.prev_span
|
self.prev_span
|
||||||
|
@ -6368,7 +6368,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
let mut err = self.diagnostic().struct_span_err(id_sp,
|
let mut err = self.diagnostic().struct_span_err(id_sp,
|
||||||
"cannot declare a new module at this location");
|
"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);
|
let src_path = self.sess.codemap().span_to_filename(id_sp);
|
||||||
if let FileName::Real(src_path) = src_path {
|
if let FileName::Real(src_path) = src_path {
|
||||||
if let Some(stem) = src_path.file_stem() {
|
if let Some(stem) = src_path.file_stem() {
|
||||||
|
|
|
@ -57,8 +57,8 @@ impl Delimited {
|
||||||
|
|
||||||
/// Returns the opening delimiter as a token tree.
|
/// Returns the opening delimiter as a token tree.
|
||||||
pub fn open_tt(&self, span: Span) -> TokenTree {
|
pub fn open_tt(&self, span: Span) -> TokenTree {
|
||||||
let open_span = if span == DUMMY_SP {
|
let open_span = if span.is_dummy() {
|
||||||
DUMMY_SP
|
span
|
||||||
} else {
|
} else {
|
||||||
span.with_hi(span.lo() + BytePos(self.delim.len() as u32))
|
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.
|
/// Returns the closing delimiter as a token tree.
|
||||||
pub fn close_tt(&self, span: Span) -> TokenTree {
|
pub fn close_tt(&self, span: Span) -> TokenTree {
|
||||||
let close_span = if span == DUMMY_SP {
|
let close_span = if span.is_dummy() {
|
||||||
DUMMY_SP
|
span
|
||||||
} else {
|
} else {
|
||||||
span.with_lo(span.hi() - BytePos(self.delim.len() as u32))
|
span.with_lo(span.hi() - BytePos(self.delim.len() as u32))
|
||||||
};
|
};
|
||||||
|
|
|
@ -248,6 +248,13 @@ impl Span {
|
||||||
self.data().with_ctxt(ctxt)
|
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
|
/// Returns a new span representing an empty span at the beginning of this span
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn shrink_to_lo(self) -> Span {
|
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.
|
/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
|
||||||
pub fn substitute_dummy(self, other: Span) -> Span {
|
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`.
|
/// Return true if `self` fully encloses `other`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue