Skip to content

Commit 2acbd3d

Browse files
authored
Rollup merge of #66349 - euclio:def-site-builtins, r=petrochenkov
expand source_util macros with def-site context cc @petrochenkov See https://internals.rust-lang.org/t/spans-from-built-in-macro-expansions-are-not-from-expansion/11276/2 for context.
2 parents 187e911 + fe4b709 commit 2acbd3d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libsyntax_ext/source_util.rs

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_data_structures::sync::Lrc;
2121
/// line!(): expands to the current line number
2222
pub fn expand_line(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
2323
-> Box<dyn base::MacResult+'static> {
24+
let sp = cx.with_def_site_ctxt(sp);
2425
base::check_zero_tts(cx, sp, tts, "line!");
2526

2627
let topmost = cx.expansion_cause().unwrap_or(sp);
@@ -32,6 +33,7 @@ pub fn expand_line(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
3233
/* column!(): expands to the current column number */
3334
pub fn expand_column(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
3435
-> Box<dyn base::MacResult+'static> {
36+
let sp = cx.with_def_site_ctxt(sp);
3537
base::check_zero_tts(cx, sp, tts, "column!");
3638

3739
let topmost = cx.expansion_cause().unwrap_or(sp);
@@ -45,6 +47,7 @@ pub fn expand_column(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
4547
/// out if we wanted.
4648
pub fn expand_file(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
4749
-> Box<dyn base::MacResult+'static> {
50+
let sp = cx.with_def_site_ctxt(sp);
4851
base::check_zero_tts(cx, sp, tts, "file!");
4952

5053
let topmost = cx.expansion_cause().unwrap_or(sp);
@@ -54,12 +57,14 @@ pub fn expand_file(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
5457

5558
pub fn expand_stringify(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
5659
-> Box<dyn base::MacResult+'static> {
60+
let sp = cx.with_def_site_ctxt(sp);
5761
let s = pprust::tts_to_string(tts);
5862
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&s)))
5963
}
6064

6165
pub fn expand_mod(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
6266
-> Box<dyn base::MacResult+'static> {
67+
let sp = cx.with_def_site_ctxt(sp);
6368
base::check_zero_tts(cx, sp, tts, "module_path!");
6469
let mod_path = &cx.current_expansion.module.mod_path;
6570
let string = mod_path.iter().map(|x| x.to_string()).collect::<Vec<String>>().join("::");
@@ -72,6 +77,7 @@ pub fn expand_mod(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
7277
/// unhygienically.
7378
pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
7479
-> Box<dyn base::MacResult+'cx> {
80+
let sp = cx.with_def_site_ctxt(sp);
7581
let file = match get_single_str_from_tts(cx, sp, tts, "include!") {
7682
Some(f) => f,
7783
None => return DummyResult::any(sp),
@@ -125,6 +131,7 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
125131
// include_str! : read the given file, insert it as a literal string expr
126132
pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
127133
-> Box<dyn base::MacResult+'static> {
134+
let sp = cx.with_def_site_ctxt(sp);
128135
let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") {
129136
Some(f) => f,
130137
None => return DummyResult::any(sp)
@@ -156,6 +163,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
156163

157164
pub fn expand_include_bytes(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
158165
-> Box<dyn base::MacResult+'static> {
166+
let sp = cx.with_def_site_ctxt(sp);
159167
let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {
160168
Some(f) => f,
161169
None => return DummyResult::any(sp)

0 commit comments

Comments
 (0)