Remove with_legacy_ctxt

This commit is contained in:
Matthew Jasper 2019-09-14 21:17:11 +01:00
parent 5ae3830d58
commit 8ab67c8f56
13 changed files with 44 additions and 34 deletions

View File

@ -977,13 +977,6 @@ impl<'a> ExtCtxt<'a> {
span.with_call_site_ctxt(self.current_expansion.id) span.with_call_site_ctxt(self.current_expansion.id)
} }
/// Span with a context reproducing `macro_rules` hygiene (hygienic locals, unhygienic items).
/// FIXME: This should be eventually replaced either with `with_def_site_ctxt` (preferably),
/// or with `with_call_site_ctxt` (where necessary).
pub fn with_legacy_ctxt(&self, span: Span) -> Span {
span.with_legacy_ctxt(self.current_expansion.id)
}
/// Returns span for the macro which originally caused the current expansion to happen. /// Returns span for the macro which originally caused the current expansion to happen.
/// ///
/// Stops backtracing at include! boundary. /// Stops backtracing at include! boundary.

View File

@ -62,7 +62,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
MacEager::expr(P(ast::Expr { MacEager::expr(P(ast::Expr {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::InlineAsm(P(inline_asm)), node: ast::ExprKind::InlineAsm(P(inline_asm)),
span: cx.with_legacy_ctxt(sp), span: cx.with_def_site_ctxt(sp),
attrs: ThinVec::new(), attrs: ThinVec::new(),
})) }))
} }

View File

@ -23,7 +23,9 @@ pub fn expand_assert<'cx>(
} }
}; };
let sp = cx.with_legacy_ctxt(sp); // `core::panic` and `std::panic` are different macros, so we use call-site
// context to pick up whichever is currently in scope.
let sp = cx.with_call_site_ctxt(sp);
let panic_call = Mac { let panic_call = Mac {
path: Path::from_ident(Ident::new(sym::panic, sp)), path: Path::from_ident(Ident::new(sym::panic, sp)),
tts: custom_message.unwrap_or_else(|| { tts: custom_message.unwrap_or_else(|| {

View File

@ -16,7 +16,7 @@ pub fn expand_cfg(
sp: Span, sp: Span,
tts: TokenStream, tts: TokenStream,
) -> Box<dyn base::MacResult + 'static> { ) -> Box<dyn base::MacResult + 'static> {
let sp = cx.with_legacy_ctxt(sp); let sp = cx.with_def_site_ctxt(sp);
match parse_cfg(cx, sp, tts) { match parse_cfg(cx, sp, tts) {
Ok(cfg) => { Ok(cfg) => {

View File

@ -59,6 +59,6 @@ pub fn expand_concat(
} else if has_errors { } else if has_errors {
return DummyResult::any(sp); return DummyResult::any(sp);
} }
let sp = cx.with_legacy_ctxt(sp); let sp = cx.with_def_site_ctxt(sp);
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator))) base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
} }

View File

@ -39,7 +39,7 @@ pub fn expand_concat_idents<'cx>(cx: &'cx mut ExtCtxt<'_>,
} }
} }
let ident = ast::Ident::new(Symbol::intern(&res_str), cx.with_legacy_ctxt(sp)); let ident = ast::Ident::new(Symbol::intern(&res_str), cx.with_call_site_ctxt(sp));
struct ConcatIdentsResult { ident: ast::Ident } struct ConcatIdentsResult { ident: ast::Ident }

View File

@ -20,7 +20,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
Some(v) => v, Some(v) => v,
}; };
let sp = cx.with_legacy_ctxt(sp); let sp = cx.with_def_site_ctxt(sp);
let e = match env::var(&*var.as_str()) { let e = match env::var(&*var.as_str()) {
Err(..) => { Err(..) => {
let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp)); let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp));

View File

@ -28,7 +28,7 @@ pub fn expand(
}; };
// Generate a bunch of new items using the AllocFnFactory // Generate a bunch of new items using the AllocFnFactory
let span = ecx.with_legacy_ctxt(item.span); let span = ecx.with_def_site_ctxt(item.span);
let f = AllocFnFactory { let f = AllocFnFactory {
span, span,
kind: AllocatorKind::Global, kind: AllocatorKind::Global,

View File

@ -30,7 +30,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: ast::ItemKind::GlobalAsm(P(global_asm)), node: ast::ItemKind::GlobalAsm(P(global_asm)),
vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited), vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
span: cx.with_legacy_ctxt(sp), span: cx.with_def_site_ctxt(sp),
tokens: None, tokens: None,
})]) })])
} }

View File

@ -526,13 +526,6 @@ impl Span {
self.with_ctxt_from_mark(expn_id, Transparency::Transparent) self.with_ctxt_from_mark(expn_id, Transparency::Transparent)
} }
/// Span with a context reproducing `macro_rules` hygiene (hygienic locals, unhygienic items).
/// FIXME: This should be eventually replaced either with `with_def_site_ctxt` (preferably),
/// or with `with_call_site_ctxt` (where necessary).
pub fn with_legacy_ctxt(&self, expn_id: ExpnId) -> Span {
self.with_ctxt_from_mark(expn_id, Transparency::SemiTransparent)
}
/// Produces a span with the same location as `self` and context produced by a macro with the /// Produces a span with the same location as `self` and context produced by a macro with the
/// given ID and transparency, assuming that macro was defined directly and not produced by /// given ID and transparency, assuming that macro was defined directly and not produced by
/// some other macro (which is the case for built-in and procedural macros). /// some other macro (which is the case for built-in and procedural macros).

View File

@ -0,0 +1,31 @@
// run-pass
// no-prefer-dynamic
// aux-build:custom.rs
// aux-build:helper.rs
#![allow(nonstandard_style)]
extern crate custom;
extern crate helper;
use custom::A;
use std::sync::atomic::{AtomicUsize, Ordering};
#[allow(dead_code)]
struct u8;
#[allow(dead_code)]
struct usize;
#[allow(dead_code)]
static arg0: () = ();
#[global_allocator]
pub static GLOBAL: A = A(AtomicUsize::new(0));
fn main() {
let n = GLOBAL.0.load(Ordering::SeqCst);
let s = Box::new(0);
helper::work_with(&s);
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 1);
drop(s);
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
}

View File

@ -1,3 +1,5 @@
// run-pass
#![feature(concat_idents)] #![feature(concat_idents)]
pub fn main() { pub fn main() {
@ -5,10 +7,8 @@ pub fn main() {
let _: concat_idents!(F, oo) = Foo; // Test that `concat_idents!` can be used in type positions let _: concat_idents!(F, oo) = Foo; // Test that `concat_idents!` can be used in type positions
let asdf_fdsa = "<.<".to_string(); let asdf_fdsa = "<.<".to_string();
// this now fails (correctly, I claim) because hygiene prevents // concat_idents should have call-site hygiene.
// the assembled identifier from being a reference to the binding.
assert!(concat_idents!(asd, f_f, dsa) == "<.<".to_string()); assert!(concat_idents!(asd, f_f, dsa) == "<.<".to_string());
//~^ ERROR cannot find value `asdf_fdsa` in this scope
assert_eq!(stringify!(use_mention_distinction), "use_mention_distinction"); assert_eq!(stringify!(use_mention_distinction), "use_mention_distinction");
} }

View File

@ -1,9 +0,0 @@
error[E0425]: cannot find value `asdf_fdsa` in this scope
--> $DIR/syntax-extension-minor.rs:10:13
|
LL | assert!(concat_idents!(asd, f_f, dsa) == "<.<".to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error: aborting due to previous error
For more information about this error, try `rustc --explain E0425`.