提交 b5099a70 编写于 作者: S Seiichi Uchida

Replace dummy spans with empty spans

上级 d6bdf296
Subproject commit 56444a4545bd71430d64b86b8a71714cfdbe9f5d Subproject commit 2b4cd1016bdba92becb4f982a4dcb18fe6653bc4
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
use syntax::ast::{Unsafety, Constness, Generics, Mutability, Ty, Mac, Arg}; use syntax::ast::{Unsafety, Constness, Generics, Mutability, Ty, Mac, Arg};
use syntax::ast::{self, Ident, Item, ItemKind, TyKind, VisibilityKind, Expr}; use syntax::ast::{self, Ident, Item, ItemKind, TyKind, VisibilityKind, Expr};
use syntax::attr; use syntax::attr;
use syntax::codemap::dummy_spanned; use syntax::codemap::{dummy_spanned, respan};
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute}; use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute};
use syntax::ext::base::ExtCtxt; use syntax::ext::base::ExtCtxt;
use syntax::ext::base::Resolver; use syntax::ext::base::Resolver;
...@@ -97,7 +97,7 @@ fn fold_item(&mut self, item: P<Item>) -> SmallVector<P<Item>> { ...@@ -97,7 +97,7 @@ fn fold_item(&mut self, item: P<Item>) -> SmallVector<P<Item>> {
]); ]);
let mut items = vec![ let mut items = vec![
f.cx.item_extern_crate(f.span, f.alloc), 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 { for method in ALLOCATOR_METHODS {
items.push(f.allocator_fn(method)); items.push(f.allocator_fn(method));
......
...@@ -497,7 +497,7 @@ fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro { ...@@ -497,7 +497,7 @@ fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
tokens: body.into(), tokens: body.into(),
legacy: def.legacy, legacy: def.legacy,
}), }),
vis: codemap::dummy_spanned(ast::VisibilityKind::Inherited), vis: codemap::respan(local_span.empty(), ast::VisibilityKind::Inherited),
tokens: None, tokens: None,
}) })
} }
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
ty_to_string ty_to_string
}; };
use syntax::ptr::P; use syntax::ptr::P;
use syntax::codemap::{Spanned, DUMMY_SP, dummy_spanned}; use syntax::codemap::{Spanned, DUMMY_SP, respan};
use syntax_pos::*; use syntax_pos::*;
use {escape, generated_code, lower_attributes, PathCollector, SaveContext}; use {escape, generated_code, lower_attributes, PathCollector, SaveContext};
...@@ -1134,6 +1134,7 @@ fn process_macro_use(&mut self, span: Span) { ...@@ -1134,6 +1134,7 @@ fn process_macro_use(&mut self, span: Span) {
fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) { fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) {
self.process_macro_use(trait_item.span); self.process_macro_use(trait_item.span);
let vis_span = trait_item.span.empty();
match trait_item.node { match trait_item.node {
ast::TraitItemKind::Const(ref ty, ref expr) => { ast::TraitItemKind::Const(ref ty, ref expr) => {
self.process_assoc_const( self.process_assoc_const(
...@@ -1143,7 +1144,7 @@ fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId ...@@ -1143,7 +1144,7 @@ fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId
&ty, &ty,
expr.as_ref().map(|e| &**e), expr.as_ref().map(|e| &**e),
trait_id, trait_id,
dummy_spanned(ast::VisibilityKind::Public), respan(vis_span, ast::VisibilityKind::Public),
&trait_item.attrs, &trait_item.attrs,
); );
} }
...@@ -1154,7 +1155,7 @@ fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId ...@@ -1154,7 +1155,7 @@ fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId
trait_item.id, trait_item.id,
trait_item.ident, trait_item.ident,
&trait_item.generics, &trait_item.generics,
dummy_spanned(ast::VisibilityKind::Public), respan(vis_span, ast::VisibilityKind::Public),
trait_item.span, trait_item.span,
); );
} }
......
...@@ -235,7 +235,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, ...@@ -235,7 +235,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
ty, ty,
expr, expr,
), ),
vis: codemap::dummy_spanned(ast::VisibilityKind::Public), vis: codemap::respan(span.empty(), ast::VisibilityKind::Public),
span, span,
tokens: None, tokens: None,
}) })
......
...@@ -987,7 +987,7 @@ fn item(&self, span: Span, name: Ident, ...@@ -987,7 +987,7 @@ fn item(&self, span: Span, name: Ident,
attrs, attrs,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node, node,
vis: dummy_spanned(ast::VisibilityKind::Inherited), vis: respan(span.empty(), ast::VisibilityKind::Inherited),
span, span,
tokens: None, tokens: None,
}) })
...@@ -1033,7 +1033,7 @@ fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>> ) -> ast::Varian ...@@ -1033,7 +1033,7 @@ fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>> ) -> ast::Varian
span: ty.span, span: ty.span,
ty, ty,
ident: None, ident: None,
vis: dummy_spanned(ast::VisibilityKind::Inherited), vis: respan(span.empty(), ast::VisibilityKind::Inherited),
attrs: Vec::new(), attrs: Vec::new(),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
} }
......
...@@ -238,7 +238,7 @@ pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate { ...@@ -238,7 +238,7 @@ pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
node: ast::ItemKind::Mod(krate.module), node: ast::ItemKind::Mod(krate.module),
ident: keywords::Invalid.ident(), ident: keywords::Invalid.ident(),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
vis: dummy_spanned(ast::VisibilityKind::Public), vis: respan(krate.span.empty(), ast::VisibilityKind::Public),
tokens: None, tokens: None,
}))); })));
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use ast::{self, Arg, Arm, Block, Expr, Item, Pat, Stmt, Ty}; use ast::{self, Arg, Arm, Block, Expr, Item, Pat, Stmt, Ty};
use codemap::dummy_spanned; use codemap::respan;
use syntax_pos::Span; use syntax_pos::Span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::base; use ext::base;
...@@ -858,7 +858,7 @@ fn expand_wrapper(cx: &ExtCtxt, ...@@ -858,7 +858,7 @@ fn expand_wrapper(cx: &ExtCtxt,
let path = path.iter().map(|s| s.to_string()).collect(); let path = path.iter().map(|s| s.to_string()).collect();
let use_item = cx.item_use_glob( let use_item = cx.item_use_glob(
sp, sp,
dummy_spanned(ast::VisibilityKind::Inherited), respan(sp.empty(), ast::VisibilityKind::Inherited),
ids_ext(path), ids_ext(path),
); );
cx.stmt_item(sp, use_item) cx.stmt_item(sp, use_item)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
use ast::*; use ast::*;
use ast; use ast;
use syntax_pos::Span; use syntax_pos::Span;
use codemap::{Spanned, respan, dummy_spanned}; use codemap::{Spanned, respan};
use parse::token::{self, Token}; use parse::token::{self, Token};
use ptr::P; use ptr::P;
use symbol::keywords; use symbol::keywords;
...@@ -1018,7 +1018,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, span}: Crate, ...@@ -1018,7 +1018,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, span}: Crate,
ident: keywords::Invalid.ident(), ident: keywords::Invalid.ident(),
attrs, attrs,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
vis: dummy_spanned(ast::VisibilityKind::Public), vis: respan(span.empty(), ast::VisibilityKind::Public),
span, span,
node: ast::ItemKind::Mod(module), node: ast::ItemKind::Mod(module),
tokens: None, tokens: None,
......
...@@ -932,7 +932,7 @@ fn parser_done(p: Parser){ ...@@ -932,7 +932,7 @@ fn parser_done(p: Parser){
span: sp(15,21), span: sp(15,21),
recovered: false, recovered: false,
})), })),
vis: codemap::dummy_spanned(ast::VisibilityKind::Inherited), vis: codemap::respan(sp(0, 0), ast::VisibilityKind::Inherited),
span: sp(0,21)}))); span: sp(0,21)})));
} }
......
...@@ -1573,7 +1573,7 @@ pub fn print_trait_item(&mut self, ti: &ast::TraitItem) ...@@ -1573,7 +1573,7 @@ pub fn print_trait_item(&mut self, ti: &ast::TraitItem)
ti.ident, ti.ident,
ty, ty,
default.as_ref().map(|expr| &**expr), 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) => { ast::TraitItemKind::Method(ref sig, ref body) => {
...@@ -1584,7 +1584,7 @@ pub fn print_trait_item(&mut self, ti: &ast::TraitItem) ...@@ -1584,7 +1584,7 @@ pub fn print_trait_item(&mut self, ti: &ast::TraitItem)
ti.ident, ti.ident,
&ti.generics, &ti.generics,
sig, sig,
&codemap::dummy_spanned(ast::VisibilityKind::Inherited), &codemap::respan(ti.span.empty(), ast::VisibilityKind::Inherited),
)?; )?;
if let Some(ref body) = *body { if let Some(ref body) = *body {
self.nbsp()?; self.nbsp()?;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
use ext::hygiene::{Mark, SyntaxContext}; use ext::hygiene::{Mark, SyntaxContext};
use symbol::{Symbol, keywords}; use symbol::{Symbol, keywords};
use syntax_pos::{DUMMY_SP, Span}; 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 ptr::P;
use tokenstream::TokenStream; use tokenstream::TokenStream;
...@@ -78,7 +78,7 @@ pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<Strin ...@@ -78,7 +78,7 @@ pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<Strin
is_sugared_doc: false, is_sugared_doc: false,
span, span,
}], }],
vis: dummy_spanned(ast::VisibilityKind::Inherited), vis: respan(span.empty(), ast::VisibilityKind::Inherited),
node: ast::ItemKind::Use(P(ast::UseTree { node: ast::ItemKind::Use(P(ast::UseTree {
prefix: ast::Path { prefix: ast::Path {
segments: ["{{root}}", name, "prelude", "v1"].into_iter().map(|name| { segments: ["{{root}}", name, "prelude", "v1"].into_iter().map(|name| {
......
...@@ -530,7 +530,7 @@ fn create_derived_impl(&self, ...@@ -530,7 +530,7 @@ fn create_derived_impl(&self,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: self.span, span: self.span,
ident, ident,
vis: dummy_spanned(ast::VisibilityKind::Inherited), vis: respan(self.span.empty(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final, defaultness: ast::Defaultness::Final,
attrs: Vec::new(), attrs: Vec::new(),
generics: Generics::default(), generics: Generics::default(),
...@@ -977,7 +977,7 @@ fn create_method(&self, ...@@ -977,7 +977,7 @@ fn create_method(&self,
attrs: self.attributes.clone(), attrs: self.attributes.clone(),
generics: fn_generics, generics: fn_generics,
span: trait_.span, span: trait_.span,
vis: dummy_spanned(ast::VisibilityKind::Inherited), vis: respan(trait_.span.empty(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final, defaultness: ast::Defaultness::Final,
ident: method_ident, ident: method_ident,
node: ast::ImplItemKind::Method(ast::MethodSig { node: ast::ImplItemKind::Method(ast::MethodSig {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
/// therefore apply. /// therefore apply.
use syntax::ast; use syntax::ast;
use syntax::codemap::dummy_spanned; use syntax::codemap::respan;
use syntax::ext::base; use syntax::ext::base;
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::feature_gate; use syntax::feature_gate;
...@@ -60,7 +60,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt, ...@@ -60,7 +60,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
asm, asm,
ctxt: cx.backtrace(), ctxt: cx.backtrace(),
})), })),
vis: dummy_spanned(ast::VisibilityKind::Inherited), vis: respan(sp.empty(), ast::VisibilityKind::Inherited),
span: sp, span: sp,
tokens: None, tokens: None,
}))) })))
......
...@@ -216,6 +216,12 @@ pub fn with_ctxt(self, ctxt: SyntaxContext) -> Span { ...@@ -216,6 +216,12 @@ pub fn with_ctxt(self, ctxt: SyntaxContext) -> Span {
self.data().with_ctxt(ctxt) 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. /// 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.source_equal(&DUMMY_SP) { other } else { self }
......
Subproject commit 1d6dfea44f97199d5d5c177c7dadcde393eaff9a Subproject commit 91e36aa86c7037de50642f2fec1cf47c3d18af02
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册