From 8ab67c8f560a730b8978f4a42deb70d01ca1cdfc Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 14 Sep 2019 21:17:11 +0100 Subject: [PATCH] Remove `with_legacy_ctxt` --- src/libsyntax/ext/base.rs | 7 ----- src/libsyntax_ext/asm.rs | 2 +- src/libsyntax_ext/assert.rs | 4 ++- src/libsyntax_ext/cfg.rs | 2 +- src/libsyntax_ext/concat.rs | 2 +- src/libsyntax_ext/concat_idents.rs | 2 +- src/libsyntax_ext/env.rs | 2 +- src/libsyntax_ext/global_allocator.rs | 2 +- src/libsyntax_ext/global_asm.rs | 2 +- src/libsyntax_pos/lib.rs | 7 ----- src/test/ui/allocator/hygiene.rs | 31 +++++++++++++++++++++++ src/test/ui/syntax-extension-minor.rs | 6 ++--- src/test/ui/syntax-extension-minor.stderr | 9 ------- 13 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 src/test/ui/allocator/hygiene.rs delete mode 100644 src/test/ui/syntax-extension-minor.stderr diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index d3f6717ee87..384c0555c85 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -977,13 +977,6 @@ pub fn with_call_site_ctxt(&self, span: Span) -> Span { 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. /// /// Stops backtracing at include! boundary. diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 328b307361d..75d727b9fb6 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -62,7 +62,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>, MacEager::expr(P(ast::Expr { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::InlineAsm(P(inline_asm)), - span: cx.with_legacy_ctxt(sp), + span: cx.with_def_site_ctxt(sp), attrs: ThinVec::new(), })) } diff --git a/src/libsyntax_ext/assert.rs b/src/libsyntax_ext/assert.rs index 001996e1db7..cbfe14fa439 100644 --- a/src/libsyntax_ext/assert.rs +++ b/src/libsyntax_ext/assert.rs @@ -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 { path: Path::from_ident(Ident::new(sym::panic, sp)), tts: custom_message.unwrap_or_else(|| { diff --git a/src/libsyntax_ext/cfg.rs b/src/libsyntax_ext/cfg.rs index 0342e442df2..3c33baf95a5 100644 --- a/src/libsyntax_ext/cfg.rs +++ b/src/libsyntax_ext/cfg.rs @@ -16,7 +16,7 @@ pub fn expand_cfg( sp: Span, tts: TokenStream, ) -> Box { - let sp = cx.with_legacy_ctxt(sp); + let sp = cx.with_def_site_ctxt(sp); match parse_cfg(cx, sp, tts) { Ok(cfg) => { diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs index fc56dff65e4..16f016036ea 100644 --- a/src/libsyntax_ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -59,6 +59,6 @@ pub fn expand_concat( } else if has_errors { 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))) } diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index 6391b62b58d..f344706d4eb 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -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 } diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index 3b0ddeeea2d..70e1fbe6af7 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -20,7 +20,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>, 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()) { Err(..) => { let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp)); diff --git a/src/libsyntax_ext/global_allocator.rs b/src/libsyntax_ext/global_allocator.rs index c57e5eec0b6..19a87e6dc6d 100644 --- a/src/libsyntax_ext/global_allocator.rs +++ b/src/libsyntax_ext/global_allocator.rs @@ -28,7 +28,7 @@ pub fn expand( }; // 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 { span, kind: AllocatorKind::Global, diff --git a/src/libsyntax_ext/global_asm.rs b/src/libsyntax_ext/global_asm.rs index 6140f0df58a..c56b3f3fc80 100644 --- a/src/libsyntax_ext/global_asm.rs +++ b/src/libsyntax_ext/global_asm.rs @@ -30,7 +30,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>, id: ast::DUMMY_NODE_ID, node: ast::ItemKind::GlobalAsm(P(global_asm)), vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited), - span: cx.with_legacy_ctxt(sp), + span: cx.with_def_site_ctxt(sp), tokens: None, })]) } diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 9a296f17aaf..ca177eb4a36 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -526,13 +526,6 @@ pub fn with_call_site_ctxt(&self, expn_id: ExpnId) -> Span { 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 /// 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). diff --git a/src/test/ui/allocator/hygiene.rs b/src/test/ui/allocator/hygiene.rs new file mode 100644 index 00000000000..9bd8406a276 --- /dev/null +++ b/src/test/ui/allocator/hygiene.rs @@ -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); +} diff --git a/src/test/ui/syntax-extension-minor.rs b/src/test/ui/syntax-extension-minor.rs index 0206a769937..2d6710af392 100644 --- a/src/test/ui/syntax-extension-minor.rs +++ b/src/test/ui/syntax-extension-minor.rs @@ -1,3 +1,5 @@ +// run-pass + #![feature(concat_idents)] 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 asdf_fdsa = "<.<".to_string(); - // this now fails (correctly, I claim) because hygiene prevents - // the assembled identifier from being a reference to the binding. + // concat_idents should have call-site hygiene. 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"); } diff --git a/src/test/ui/syntax-extension-minor.stderr b/src/test/ui/syntax-extension-minor.stderr deleted file mode 100644 index 2d8056da527..00000000000 --- a/src/test/ui/syntax-extension-minor.stderr +++ /dev/null @@ -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`. -- 2.44.0