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.
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(),
}))
}
}
};
- 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(|| {
sp: Span,
tts: TokenStream,
) -> 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) {
Ok(cfg) => {
} 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)))
}
}
}
- 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 }
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));
};
// 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,
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,
})])
}
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).
--- /dev/null
+// 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);
+}
+// run-pass
+
#![feature(concat_idents)]
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");
}
+++ /dev/null
-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`.