Replace dummy spans with empty spans

This commit is contained in:
Seiichi Uchida 2018-02-04 21:19:14 +09:00
parent d6bdf296a4
commit b5099a708d
16 changed files with 32 additions and 25 deletions

@ -1 +1 @@
Subproject commit 56444a4545bd71430d64b86b8a71714cfdbe9f5d
Subproject commit 2b4cd1016bdba92becb4f982a4dcb18fe6653bc4

View File

@ -15,7 +15,7 @@ use syntax::ast::{Crate, Attribute, LitKind, StrStyle, ExprKind};
use syntax::ast::{Unsafety, Constness, Generics, Mutability, Ty, Mac, Arg};
use syntax::ast::{self, Ident, Item, ItemKind, TyKind, VisibilityKind, Expr};
use syntax::attr;
use syntax::codemap::dummy_spanned;
use syntax::codemap::{dummy_spanned, respan};
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute};
use syntax::ext::base::ExtCtxt;
use syntax::ext::base::Resolver;
@ -97,7 +97,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
]);
let mut items = vec![
f.cx.item_extern_crate(f.span, f.alloc),
f.cx.item_use_simple(f.span, dummy_spanned(VisibilityKind::Inherited), super_path),
f.cx.item_use_simple(f.span, respan(f.span.empty(), VisibilityKind::Inherited), super_path),
];
for method in ALLOCATOR_METHODS {
items.push(f.allocator_fn(method));

View File

@ -497,7 +497,7 @@ impl CrateStore for cstore::CStore {
tokens: body.into(),
legacy: def.legacy,
}),
vis: codemap::dummy_spanned(ast::VisibilityKind::Inherited),
vis: codemap::respan(local_span.empty(), ast::VisibilityKind::Inherited),
tokens: None,
})
}

View File

@ -43,7 +43,7 @@ use syntax::print::pprust::{
ty_to_string
};
use syntax::ptr::P;
use syntax::codemap::{Spanned, DUMMY_SP, dummy_spanned};
use syntax::codemap::{Spanned, DUMMY_SP, respan};
use syntax_pos::*;
use {escape, generated_code, lower_attributes, PathCollector, SaveContext};
@ -1134,6 +1134,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) {
self.process_macro_use(trait_item.span);
let vis_span = trait_item.span.empty();
match trait_item.node {
ast::TraitItemKind::Const(ref ty, ref expr) => {
self.process_assoc_const(
@ -1143,7 +1144,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
&ty,
expr.as_ref().map(|e| &**e),
trait_id,
dummy_spanned(ast::VisibilityKind::Public),
respan(vis_span, ast::VisibilityKind::Public),
&trait_item.attrs,
);
}
@ -1154,7 +1155,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
trait_item.id,
trait_item.ident,
&trait_item.generics,
dummy_spanned(ast::VisibilityKind::Public),
respan(vis_span, ast::VisibilityKind::Public),
trait_item.span,
);
}

View File

@ -235,7 +235,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
ty,
expr,
),
vis: codemap::dummy_spanned(ast::VisibilityKind::Public),
vis: codemap::respan(span.empty(), ast::VisibilityKind::Public),
span,
tokens: None,
})

View File

@ -987,7 +987,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
attrs,
id: ast::DUMMY_NODE_ID,
node,
vis: dummy_spanned(ast::VisibilityKind::Inherited),
vis: respan(span.empty(), ast::VisibilityKind::Inherited),
span,
tokens: None,
})
@ -1033,7 +1033,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
span: ty.span,
ty,
ident: None,
vis: dummy_spanned(ast::VisibilityKind::Inherited),
vis: respan(span.empty(), ast::VisibilityKind::Inherited),
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
}

View File

@ -238,7 +238,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
node: ast::ItemKind::Mod(krate.module),
ident: keywords::Invalid.ident(),
id: ast::DUMMY_NODE_ID,
vis: dummy_spanned(ast::VisibilityKind::Public),
vis: respan(krate.span.empty(), ast::VisibilityKind::Public),
tokens: None,
})));

View File

@ -9,7 +9,7 @@
// except according to those terms.
use ast::{self, Arg, Arm, Block, Expr, Item, Pat, Stmt, Ty};
use codemap::dummy_spanned;
use codemap::respan;
use syntax_pos::Span;
use ext::base::ExtCtxt;
use ext::base;
@ -858,7 +858,7 @@ fn expand_wrapper(cx: &ExtCtxt,
let path = path.iter().map(|s| s.to_string()).collect();
let use_item = cx.item_use_glob(
sp,
dummy_spanned(ast::VisibilityKind::Inherited),
respan(sp.empty(), ast::VisibilityKind::Inherited),
ids_ext(path),
);
cx.stmt_item(sp, use_item)

View File

@ -21,7 +21,7 @@
use ast::*;
use ast;
use syntax_pos::Span;
use codemap::{Spanned, respan, dummy_spanned};
use codemap::{Spanned, respan};
use parse::token::{self, Token};
use ptr::P;
use symbol::keywords;
@ -1018,7 +1018,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, span}: Crate,
ident: keywords::Invalid.ident(),
attrs,
id: ast::DUMMY_NODE_ID,
vis: dummy_spanned(ast::VisibilityKind::Public),
vis: respan(span.empty(), ast::VisibilityKind::Public),
span,
node: ast::ItemKind::Mod(module),
tokens: None,

View File

@ -932,7 +932,7 @@ mod tests {
span: sp(15,21),
recovered: false,
})),
vis: codemap::dummy_spanned(ast::VisibilityKind::Inherited),
vis: codemap::respan(sp(0, 0), ast::VisibilityKind::Inherited),
span: sp(0,21)})));
}

View File

@ -1573,7 +1573,7 @@ impl<'a> State<'a> {
ti.ident,
ty,
default.as_ref().map(|expr| &**expr),
&codemap::dummy_spanned(ast::VisibilityKind::Inherited),
&codemap::respan(ti.span.empty(), ast::VisibilityKind::Inherited),
)?;
}
ast::TraitItemKind::Method(ref sig, ref body) => {
@ -1584,7 +1584,7 @@ impl<'a> State<'a> {
ti.ident,
&ti.generics,
sig,
&codemap::dummy_spanned(ast::VisibilityKind::Inherited),
&codemap::respan(ti.span.empty(), ast::VisibilityKind::Inherited),
)?;
if let Some(ref body) = *body {
self.nbsp()?;

View File

@ -14,7 +14,7 @@ use std::cell::Cell;
use ext::hygiene::{Mark, SyntaxContext};
use symbol::{Symbol, keywords};
use syntax_pos::{DUMMY_SP, Span};
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned};
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, respan};
use ptr::P;
use tokenstream::TokenStream;
@ -78,7 +78,7 @@ pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<Strin
is_sugared_doc: false,
span,
}],
vis: dummy_spanned(ast::VisibilityKind::Inherited),
vis: respan(span.empty(), ast::VisibilityKind::Inherited),
node: ast::ItemKind::Use(P(ast::UseTree {
prefix: ast::Path {
segments: ["{{root}}", name, "prelude", "v1"].into_iter().map(|name| {

View File

@ -530,7 +530,7 @@ impl<'a> TraitDef<'a> {
id: ast::DUMMY_NODE_ID,
span: self.span,
ident,
vis: dummy_spanned(ast::VisibilityKind::Inherited),
vis: respan(self.span.empty(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
attrs: Vec::new(),
generics: Generics::default(),
@ -977,7 +977,7 @@ impl<'a> MethodDef<'a> {
attrs: self.attributes.clone(),
generics: fn_generics,
span: trait_.span,
vis: dummy_spanned(ast::VisibilityKind::Inherited),
vis: respan(trait_.span.empty(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
ident: method_ident,
node: ast::ImplItemKind::Method(ast::MethodSig {

View File

@ -19,7 +19,7 @@
/// therefore apply.
use syntax::ast;
use syntax::codemap::dummy_spanned;
use syntax::codemap::respan;
use syntax::ext::base;
use syntax::ext::base::*;
use syntax::feature_gate;
@ -60,7 +60,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
asm,
ctxt: cx.backtrace(),
})),
vis: dummy_spanned(ast::VisibilityKind::Inherited),
vis: respan(sp.empty(), ast::VisibilityKind::Inherited),
span: sp,
tokens: None,
})))

View File

@ -216,6 +216,12 @@ impl Span {
self.data().with_ctxt(ctxt)
}
/// Returns a new span representing an empty span at the beginning of this span
#[inline]
pub fn empty(self) -> Span {
span.with_hi(self.lo())
}
/// 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 }

@ -1 +1 @@
Subproject commit 1d6dfea44f97199d5d5c177c7dadcde393eaff9a
Subproject commit 91e36aa86c7037de50642f2fec1cf47c3d18af02