Skip to content

Commit 8ab67c8

Browse files
committed
Remove with_legacy_ctxt
1 parent 5ae3830 commit 8ab67c8

File tree

13 files changed

+44
-34
lines changed

13 files changed

+44
-34
lines changed

src/libsyntax/ext/base.rs

-7
Original file line numberDiff line numberDiff line change
@@ -977,13 +977,6 @@ impl<'a> ExtCtxt<'a> {
977977
span.with_call_site_ctxt(self.current_expansion.id)
978978
}
979979

980-
/// Span with a context reproducing `macro_rules` hygiene (hygienic locals, unhygienic items).
981-
/// FIXME: This should be eventually replaced either with `with_def_site_ctxt` (preferably),
982-
/// or with `with_call_site_ctxt` (where necessary).
983-
pub fn with_legacy_ctxt(&self, span: Span) -> Span {
984-
span.with_legacy_ctxt(self.current_expansion.id)
985-
}
986-
987980
/// Returns span for the macro which originally caused the current expansion to happen.
988981
///
989982
/// Stops backtracing at include! boundary.

src/libsyntax_ext/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
6262
MacEager::expr(P(ast::Expr {
6363
id: ast::DUMMY_NODE_ID,
6464
node: ast::ExprKind::InlineAsm(P(inline_asm)),
65-
span: cx.with_legacy_ctxt(sp),
65+
span: cx.with_def_site_ctxt(sp),
6666
attrs: ThinVec::new(),
6767
}))
6868
}

src/libsyntax_ext/assert.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ pub fn expand_assert<'cx>(
2323
}
2424
};
2525

26-
let sp = cx.with_legacy_ctxt(sp);
26+
// `core::panic` and `std::panic` are different macros, so we use call-site
27+
// context to pick up whichever is currently in scope.
28+
let sp = cx.with_call_site_ctxt(sp);
2729
let panic_call = Mac {
2830
path: Path::from_ident(Ident::new(sym::panic, sp)),
2931
tts: custom_message.unwrap_or_else(|| {

src/libsyntax_ext/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn expand_cfg(
1616
sp: Span,
1717
tts: TokenStream,
1818
) -> Box<dyn base::MacResult + 'static> {
19-
let sp = cx.with_legacy_ctxt(sp);
19+
let sp = cx.with_def_site_ctxt(sp);
2020

2121
match parse_cfg(cx, sp, tts) {
2222
Ok(cfg) => {

src/libsyntax_ext/concat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ pub fn expand_concat(
5959
} else if has_errors {
6060
return DummyResult::any(sp);
6161
}
62-
let sp = cx.with_legacy_ctxt(sp);
62+
let sp = cx.with_def_site_ctxt(sp);
6363
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
6464
}

src/libsyntax_ext/concat_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn expand_concat_idents<'cx>(cx: &'cx mut ExtCtxt<'_>,
3939
}
4040
}
4141

42-
let ident = ast::Ident::new(Symbol::intern(&res_str), cx.with_legacy_ctxt(sp));
42+
let ident = ast::Ident::new(Symbol::intern(&res_str), cx.with_call_site_ctxt(sp));
4343

4444
struct ConcatIdentsResult { ident: ast::Ident }
4545

src/libsyntax_ext/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
2020
Some(v) => v,
2121
};
2222

23-
let sp = cx.with_legacy_ctxt(sp);
23+
let sp = cx.with_def_site_ctxt(sp);
2424
let e = match env::var(&*var.as_str()) {
2525
Err(..) => {
2626
let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp));

src/libsyntax_ext/global_allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn expand(
2828
};
2929

3030
// Generate a bunch of new items using the AllocFnFactory
31-
let span = ecx.with_legacy_ctxt(item.span);
31+
let span = ecx.with_def_site_ctxt(item.span);
3232
let f = AllocFnFactory {
3333
span,
3434
kind: AllocatorKind::Global,

src/libsyntax_ext/global_asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
3030
id: ast::DUMMY_NODE_ID,
3131
node: ast::ItemKind::GlobalAsm(P(global_asm)),
3232
vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
33-
span: cx.with_legacy_ctxt(sp),
33+
span: cx.with_def_site_ctxt(sp),
3434
tokens: None,
3535
})])
3636
}

src/libsyntax_pos/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -526,13 +526,6 @@ impl Span {
526526
self.with_ctxt_from_mark(expn_id, Transparency::Transparent)
527527
}
528528

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

src/test/ui/allocator/hygiene.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// run-pass
2+
// no-prefer-dynamic
3+
// aux-build:custom.rs
4+
// aux-build:helper.rs
5+
6+
#![allow(nonstandard_style)]
7+
8+
extern crate custom;
9+
extern crate helper;
10+
11+
use custom::A;
12+
use std::sync::atomic::{AtomicUsize, Ordering};
13+
14+
#[allow(dead_code)]
15+
struct u8;
16+
#[allow(dead_code)]
17+
struct usize;
18+
#[allow(dead_code)]
19+
static arg0: () = ();
20+
21+
#[global_allocator]
22+
pub static GLOBAL: A = A(AtomicUsize::new(0));
23+
24+
fn main() {
25+
let n = GLOBAL.0.load(Ordering::SeqCst);
26+
let s = Box::new(0);
27+
helper::work_with(&s);
28+
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 1);
29+
drop(s);
30+
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
31+
}

src/test/ui/syntax-extension-minor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
// run-pass
2+
13
#![feature(concat_idents)]
24

35
pub fn main() {
46
struct Foo;
57
let _: concat_idents!(F, oo) = Foo; // Test that `concat_idents!` can be used in type positions
68

79
let asdf_fdsa = "<.<".to_string();
8-
// this now fails (correctly, I claim) because hygiene prevents
9-
// the assembled identifier from being a reference to the binding.
10+
// concat_idents should have call-site hygiene.
1011
assert!(concat_idents!(asd, f_f, dsa) == "<.<".to_string());
11-
//~^ ERROR cannot find value `asdf_fdsa` in this scope
1212

1313
assert_eq!(stringify!(use_mention_distinction), "use_mention_distinction");
1414
}

src/test/ui/syntax-extension-minor.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)