mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Remove with_legacy_ctxt
This commit is contained in:
parent
5ae3830d58
commit
8ab67c8f56
@ -977,13 +977,6 @@ impl<'a> ExtCtxt<'a> {
|
||||
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.
|
||||
|
@ -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(),
|
||||
}))
|
||||
}
|
||||
|
@ -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(|| {
|
||||
|
@ -16,7 +16,7 @@ pub fn expand_cfg(
|
||||
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) => {
|
||||
|
@ -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)))
|
||||
}
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
})])
|
||||
}
|
||||
|
@ -526,13 +526,6 @@ impl 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).
|
||||
|
31
src/test/ui/allocator/hygiene.rs
Normal file
31
src/test/ui/allocator/hygiene.rs
Normal 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);
|
||||
}
|
@ -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");
|
||||
}
|
||||
|
@ -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`.
|
Loading…
Reference in New Issue
Block a user