Add with_{def_site,call_site,legacy}_ctxt, methods to Span
Use these to create call-site spans for AST passes when needed.
This commit is contained in:
committed by
Matthew Jasper
parent
0b86782058
commit
c8cf9f5a02
@@ -326,12 +326,13 @@ fn mk_decls(
|
||||
custom_attrs: &[ProcMacroDef],
|
||||
custom_macros: &[ProcMacroDef],
|
||||
) -> P<ast::Item> {
|
||||
let span = cx.resolver.span_for_ast_pass(
|
||||
let expn_id = cx.resolver.expansion_for_ast_pass(
|
||||
DUMMY_SP,
|
||||
AstPass::ProcMacroHarness,
|
||||
&[sym::rustc_attrs, sym::proc_macro_internals],
|
||||
None,
|
||||
);
|
||||
let span = DUMMY_SP.with_def_site_ctxt(expn_id);
|
||||
|
||||
let proc_macro = Ident::new(sym::proc_macro, span);
|
||||
let krate = cx.item(span,
|
||||
|
||||
@@ -28,19 +28,21 @@ pub fn inject(
|
||||
&[sym::std]
|
||||
};
|
||||
|
||||
let span = resolver.span_for_ast_pass(
|
||||
let expn_id = resolver.expansion_for_ast_pass(
|
||||
DUMMY_SP,
|
||||
AstPass::StdImports,
|
||||
&[sym::prelude_import],
|
||||
None,
|
||||
);
|
||||
let span = DUMMY_SP.with_def_site_ctxt(expn_id);
|
||||
let call_site = DUMMY_SP.with_call_site_ctxt(expn_id);
|
||||
|
||||
// .rev() to preserve ordering above in combination with insert(0, ...)
|
||||
for &orig_name_sym in names.iter().rev() {
|
||||
let (rename, orig_name) = if rust_2018 {
|
||||
(Ident::new(kw::Underscore, span), Some(orig_name_sym))
|
||||
} else {
|
||||
(Ident::with_dummy_span(orig_name_sym), None)
|
||||
(Ident::new(orig_name_sym, call_site), None)
|
||||
};
|
||||
krate.module.items.insert(0, P(ast::Item {
|
||||
attrs: vec![attr::mk_attr_outer(
|
||||
@@ -65,7 +67,7 @@ pub fn inject(
|
||||
.collect()
|
||||
} else {
|
||||
[kw::PathRoot, name, sym::prelude, sym::v1].iter()
|
||||
.map(|symbol| ast::PathSegment::from_ident(ast::Ident::with_dummy_span(*symbol)))
|
||||
.map(|symbol| ast::PathSegment::from_ident(ast::Ident::new(*symbol, call_site)))
|
||||
.collect()
|
||||
};
|
||||
|
||||
|
||||
@@ -97,15 +97,16 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
|
||||
};
|
||||
// Create an identifier that will hygienically resolve the test
|
||||
// case name, even in another module.
|
||||
let sp = self.cx.ext_cx.resolver.span_for_ast_pass(
|
||||
let expn_id = self.cx.ext_cx.resolver.expansion_for_ast_pass(
|
||||
module.inner,
|
||||
AstPass::TestHarness,
|
||||
&[],
|
||||
Some(parent),
|
||||
);
|
||||
let expn = sp.ctxt().outer_expn();
|
||||
for test in &mut tests {
|
||||
test.ident.span = test.ident.span.apply_mark(expn, Transparency::Opaque);
|
||||
// See the comment on `mk_main` for why we're using
|
||||
// `apply_mark` directly.
|
||||
test.ident.span = test.ident.span.apply_mark(expn_id, Transparency::Opaque);
|
||||
}
|
||||
self.cx.test_cases.extend(tests);
|
||||
}
|
||||
@@ -207,12 +208,13 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
||||
// #![main]
|
||||
// test::test_main_static(&[..tests]);
|
||||
// }
|
||||
let sp = cx.ext_cx.resolver.span_for_ast_pass(
|
||||
let expn_id = cx.ext_cx.resolver.expansion_for_ast_pass(
|
||||
DUMMY_SP,
|
||||
AstPass::TestHarness,
|
||||
&[sym::main, sym::test, sym::rustc_attrs],
|
||||
None,
|
||||
);
|
||||
let sp = DUMMY_SP.with_def_site_ctxt(expn_id);
|
||||
let ecx = &cx.ext_cx;
|
||||
let test_id = Ident::new(sym::test, sp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user