Skip to content

Commit 34eae07

Browse files
committedFeb 25, 2024
Remove ast:: & base:: prefixes from some builtin macros
1 parent c440a5b commit 34eae07

File tree

7 files changed

+116
-118
lines changed

7 files changed

+116
-118
lines changed
 

‎compiler/rustc_builtin_macros/src/cfg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use rustc_ast::token;
88
use rustc_ast::tokenstream::TokenStream;
99
use rustc_attr as attr;
1010
use rustc_errors::PResult;
11-
use rustc_expand::base::{self, *};
11+
use rustc_expand::base::{DummyResult, ExtCtxt, MacEager, MacResult};
1212
use rustc_span::Span;
1313

1414
pub fn expand_cfg(
1515
cx: &mut ExtCtxt<'_>,
1616
sp: Span,
1717
tts: TokenStream,
18-
) -> Box<dyn base::MacResult + 'static> {
18+
) -> Box<dyn MacResult + 'static> {
1919
let sp = cx.with_def_site_ctxt(sp);
2020

2121
match parse_cfg(cx, sp, tts) {

‎compiler/rustc_builtin_macros/src/compile_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// The compiler code necessary to support the compile_error! extension.
22

33
use rustc_ast::tokenstream::TokenStream;
4-
use rustc_expand::base::{self, *};
4+
use rustc_expand::base::{get_single_str_from_tts, DummyResult, ExtCtxt, MacResult};
55
use rustc_span::Span;
66

77
pub fn expand_compile_error<'cx>(
88
cx: &'cx mut ExtCtxt<'_>,
99
sp: Span,
1010
tts: TokenStream,
11-
) -> Box<dyn base::MacResult + 'cx> {
11+
) -> Box<dyn MacResult + 'cx> {
1212
let var = match get_single_str_from_tts(cx, sp, tts, "compile_error!") {
1313
Ok(var) => var,
1414
Err(guar) => return DummyResult::any(sp, guar),
+21-23
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use rustc_ast as ast;
21
use rustc_ast::tokenstream::TokenStream;
3-
use rustc_expand::base::{self, DummyResult};
2+
use rustc_ast::{ExprKind, LitKind, UnOp};
3+
use rustc_expand::base::{get_exprs_from_tts, DummyResult, ExtCtxt, MacEager, MacResult};
44
use rustc_session::errors::report_lit_error;
55
use rustc_span::symbol::Symbol;
66

77
use crate::errors;
88

99
pub fn expand_concat(
10-
cx: &mut base::ExtCtxt<'_>,
10+
cx: &mut ExtCtxt<'_>,
1111
sp: rustc_span::Span,
1212
tts: TokenStream,
13-
) -> Box<dyn base::MacResult + 'static> {
14-
let es = match base::get_exprs_from_tts(cx, tts) {
13+
) -> Box<dyn MacResult + 'static> {
14+
let es = match get_exprs_from_tts(cx, tts) {
1515
Ok(es) => es,
1616
Err(guar) => return DummyResult::any(sp, guar),
1717
};
@@ -20,52 +20,50 @@ pub fn expand_concat(
2020
let mut guar = None;
2121
for e in es {
2222
match e.kind {
23-
ast::ExprKind::Lit(token_lit) => match ast::LitKind::from_token_lit(token_lit) {
24-
Ok(ast::LitKind::Str(s, _) | ast::LitKind::Float(s, _)) => {
23+
ExprKind::Lit(token_lit) => match LitKind::from_token_lit(token_lit) {
24+
Ok(LitKind::Str(s, _) | LitKind::Float(s, _)) => {
2525
accumulator.push_str(s.as_str());
2626
}
27-
Ok(ast::LitKind::Char(c)) => {
27+
Ok(LitKind::Char(c)) => {
2828
accumulator.push(c);
2929
}
30-
Ok(ast::LitKind::Int(i, _)) => {
30+
Ok(LitKind::Int(i, _)) => {
3131
accumulator.push_str(&i.to_string());
3232
}
33-
Ok(ast::LitKind::Bool(b)) => {
33+
Ok(LitKind::Bool(b)) => {
3434
accumulator.push_str(&b.to_string());
3535
}
36-
Ok(ast::LitKind::CStr(..)) => {
36+
Ok(LitKind::CStr(..)) => {
3737
guar = Some(cx.dcx().emit_err(errors::ConcatCStrLit { span: e.span }));
3838
}
39-
Ok(ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..)) => {
39+
Ok(LitKind::Byte(..) | LitKind::ByteStr(..)) => {
4040
guar = Some(cx.dcx().emit_err(errors::ConcatBytestr { span: e.span }));
4141
}
42-
Ok(ast::LitKind::Err(guarantee)) => {
42+
Ok(LitKind::Err(guarantee)) => {
4343
guar = Some(guarantee);
4444
}
4545
Err(err) => {
4646
guar = Some(report_lit_error(&cx.sess.parse_sess, err, token_lit, e.span));
4747
}
4848
},
4949
// We also want to allow negative numeric literals.
50-
ast::ExprKind::Unary(ast::UnOp::Neg, ref expr)
51-
if let ast::ExprKind::Lit(token_lit) = expr.kind =>
52-
{
53-
match ast::LitKind::from_token_lit(token_lit) {
54-
Ok(ast::LitKind::Int(i, _)) => accumulator.push_str(&format!("-{i}")),
55-
Ok(ast::LitKind::Float(f, _)) => accumulator.push_str(&format!("-{f}")),
50+
ExprKind::Unary(UnOp::Neg, ref expr) if let ExprKind::Lit(token_lit) = expr.kind => {
51+
match LitKind::from_token_lit(token_lit) {
52+
Ok(LitKind::Int(i, _)) => accumulator.push_str(&format!("-{i}")),
53+
Ok(LitKind::Float(f, _)) => accumulator.push_str(&format!("-{f}")),
5654
Err(err) => {
5755
guar = Some(report_lit_error(&cx.sess.parse_sess, err, token_lit, e.span));
5856
}
5957
_ => missing_literal.push(e.span),
6058
}
6159
}
62-
ast::ExprKind::IncludedBytes(..) => {
60+
ExprKind::IncludedBytes(..) => {
6361
cx.dcx().emit_err(errors::ConcatBytestr { span: e.span });
6462
}
65-
ast::ExprKind::Err(guarantee) => {
63+
ExprKind::Err(guarantee) => {
6664
guar = Some(guarantee);
6765
}
68-
ast::ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
66+
ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
6967
_ => {
7068
missing_literal.push(e.span);
7169
}
@@ -79,5 +77,5 @@ pub fn expand_concat(
7977
return DummyResult::any(sp, guar);
8078
}
8179
let sp = cx.with_def_site_ctxt(sp);
82-
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
80+
MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
8381
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
use rustc_ast as ast;
2-
use rustc_ast::{ptr::P, tokenstream::TokenStream};
3-
use rustc_expand::base::{self, DummyResult};
1+
use rustc_ast::{ptr::P, token, tokenstream::TokenStream, ExprKind, LitIntType, LitKind, UintTy};
2+
use rustc_expand::base::{get_exprs_from_tts, DummyResult, ExtCtxt, MacEager, MacResult};
43
use rustc_session::errors::report_lit_error;
54
use rustc_span::{ErrorGuaranteed, Span};
65

76
use crate::errors;
87

98
/// Emits errors for literal expressions that are invalid inside and outside of an array.
109
fn invalid_type_err(
11-
cx: &mut base::ExtCtxt<'_>,
12-
token_lit: ast::token::Lit,
10+
cx: &mut ExtCtxt<'_>,
11+
token_lit: token::Lit,
1312
span: Span,
1413
is_nested: bool,
1514
) -> ErrorGuaranteed {
@@ -18,18 +17,18 @@ fn invalid_type_err(
1817
};
1918
let snippet = cx.sess.source_map().span_to_snippet(span).ok();
2019
let dcx = cx.dcx();
21-
match ast::LitKind::from_token_lit(token_lit) {
22-
Ok(ast::LitKind::CStr(_, _)) => {
20+
match LitKind::from_token_lit(token_lit) {
21+
Ok(LitKind::CStr(_, _)) => {
2322
// Avoid ambiguity in handling of terminal `NUL` by refusing to
2423
// concatenate C string literals as bytes.
2524
dcx.emit_err(errors::ConcatCStrLit { span })
2625
}
27-
Ok(ast::LitKind::Char(_)) => {
26+
Ok(LitKind::Char(_)) => {
2827
let sugg =
2928
snippet.map(|snippet| ConcatBytesInvalidSuggestion::CharLit { span, snippet });
3029
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "character", sugg })
3130
}
32-
Ok(ast::LitKind::Str(_, _)) => {
31+
Ok(LitKind::Str(_, _)) => {
3332
// suggestion would be invalid if we are nested
3433
let sugg = if !is_nested {
3534
snippet.map(|snippet| ConcatBytesInvalidSuggestion::StrLit { span, snippet })
@@ -38,27 +37,24 @@ fn invalid_type_err(
3837
};
3938
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "string", sugg })
4039
}
41-
Ok(ast::LitKind::Float(_, _)) => {
40+
Ok(LitKind::Float(_, _)) => {
4241
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "float", sugg: None })
4342
}
44-
Ok(ast::LitKind::Bool(_)) => {
43+
Ok(LitKind::Bool(_)) => {
4544
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "boolean", sugg: None })
4645
}
47-
Ok(ast::LitKind::Int(_, _)) if !is_nested => {
46+
Ok(LitKind::Int(_, _)) if !is_nested => {
4847
let sugg =
49-
snippet.map(|snippet| ConcatBytesInvalidSuggestion::IntLit { span: span, snippet });
48+
snippet.map(|snippet| ConcatBytesInvalidSuggestion::IntLit { span, snippet });
5049
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "numeric", sugg })
5150
}
52-
Ok(ast::LitKind::Int(
53-
val,
54-
ast::LitIntType::Unsuffixed | ast::LitIntType::Unsigned(ast::UintTy::U8),
55-
)) => {
51+
Ok(LitKind::Int(val, LitIntType::Unsuffixed | LitIntType::Unsigned(UintTy::U8))) => {
5652
assert!(val.get() > u8::MAX.into()); // must be an error
5753
dcx.emit_err(ConcatBytesOob { span })
5854
}
59-
Ok(ast::LitKind::Int(_, _)) => dcx.emit_err(ConcatBytesNonU8 { span }),
60-
Ok(ast::LitKind::ByteStr(..) | ast::LitKind::Byte(_)) => unreachable!(),
61-
Ok(ast::LitKind::Err(guar)) => guar,
55+
Ok(LitKind::Int(_, _)) => dcx.emit_err(ConcatBytesNonU8 { span }),
56+
Ok(LitKind::ByteStr(..) | LitKind::Byte(_)) => unreachable!(),
57+
Ok(LitKind::Err(guar)) => guar,
6258
Err(err) => report_lit_error(&cx.sess.parse_sess, err, token_lit, span),
6359
}
6460
}
@@ -68,24 +64,24 @@ fn invalid_type_err(
6864
/// Otherwise, returns `None`, and either pushes the `expr`'s span to `missing_literals` or
6965
/// updates `guar` accordingly.
7066
fn handle_array_element(
71-
cx: &mut base::ExtCtxt<'_>,
67+
cx: &mut ExtCtxt<'_>,
7268
guar: &mut Option<ErrorGuaranteed>,
7369
missing_literals: &mut Vec<rustc_span::Span>,
7470
expr: &P<rustc_ast::Expr>,
7571
) -> Option<u8> {
7672
let dcx = cx.dcx();
7773

7874
match expr.kind {
79-
ast::ExprKind::Lit(token_lit) => {
80-
match ast::LitKind::from_token_lit(token_lit) {
81-
Ok(ast::LitKind::Int(
75+
ExprKind::Lit(token_lit) => {
76+
match LitKind::from_token_lit(token_lit) {
77+
Ok(LitKind::Int(
8278
val,
83-
ast::LitIntType::Unsuffixed | ast::LitIntType::Unsigned(ast::UintTy::U8),
79+
LitIntType::Unsuffixed | LitIntType::Unsigned(UintTy::U8),
8480
)) if let Ok(val) = u8::try_from(val.get()) => {
8581
return Some(val);
8682
}
87-
Ok(ast::LitKind::Byte(val)) => return Some(val),
88-
Ok(ast::LitKind::ByteStr(..)) => {
83+
Ok(LitKind::Byte(val)) => return Some(val),
84+
Ok(LitKind::ByteStr(..)) => {
8985
guar.get_or_insert_with(|| {
9086
dcx.emit_err(errors::ConcatBytesArray { span: expr.span, bytestr: true })
9187
});
@@ -95,12 +91,12 @@ fn handle_array_element(
9591
}
9692
};
9793
}
98-
ast::ExprKind::Array(_) | ast::ExprKind::Repeat(_, _) => {
94+
ExprKind::Array(_) | ExprKind::Repeat(_, _) => {
9995
guar.get_or_insert_with(|| {
10096
dcx.emit_err(errors::ConcatBytesArray { span: expr.span, bytestr: false })
10197
});
10298
}
103-
ast::ExprKind::IncludedBytes(..) => {
99+
ExprKind::IncludedBytes(..) => {
104100
guar.get_or_insert_with(|| {
105101
dcx.emit_err(errors::ConcatBytesArray { span: expr.span, bytestr: false })
106102
});
@@ -112,11 +108,11 @@ fn handle_array_element(
112108
}
113109

114110
pub fn expand_concat_bytes(
115-
cx: &mut base::ExtCtxt<'_>,
116-
sp: rustc_span::Span,
111+
cx: &mut ExtCtxt<'_>,
112+
sp: Span,
117113
tts: TokenStream,
118-
) -> Box<dyn base::MacResult + 'static> {
119-
let es = match base::get_exprs_from_tts(cx, tts) {
114+
) -> Box<dyn MacResult + 'static> {
115+
let es = match get_exprs_from_tts(cx, tts) {
120116
Ok(es) => es,
121117
Err(guar) => return DummyResult::any(sp, guar),
122118
};
@@ -125,7 +121,7 @@ pub fn expand_concat_bytes(
125121
let mut guar = None;
126122
for e in es {
127123
match &e.kind {
128-
ast::ExprKind::Array(exprs) => {
124+
ExprKind::Array(exprs) => {
129125
for expr in exprs {
130126
if let Some(elem) =
131127
handle_array_element(cx, &mut guar, &mut missing_literals, expr)
@@ -134,10 +130,9 @@ pub fn expand_concat_bytes(
134130
}
135131
}
136132
}
137-
ast::ExprKind::Repeat(expr, count) => {
138-
if let ast::ExprKind::Lit(token_lit) = count.value.kind
139-
&& let Ok(ast::LitKind::Int(count_val, _)) =
140-
ast::LitKind::from_token_lit(token_lit)
133+
ExprKind::Repeat(expr, count) => {
134+
if let ExprKind::Lit(token_lit) = count.value.kind
135+
&& let Ok(LitKind::Int(count_val, _)) = LitKind::from_token_lit(token_lit)
141136
{
142137
if let Some(elem) =
143138
handle_array_element(cx, &mut guar, &mut missing_literals, expr)
@@ -152,35 +147,35 @@ pub fn expand_concat_bytes(
152147
);
153148
}
154149
}
155-
&ast::ExprKind::Lit(token_lit) => match ast::LitKind::from_token_lit(token_lit) {
156-
Ok(ast::LitKind::Byte(val)) => {
150+
&ExprKind::Lit(token_lit) => match LitKind::from_token_lit(token_lit) {
151+
Ok(LitKind::Byte(val)) => {
157152
accumulator.push(val);
158153
}
159-
Ok(ast::LitKind::ByteStr(ref bytes, _)) => {
154+
Ok(LitKind::ByteStr(ref bytes, _)) => {
160155
accumulator.extend_from_slice(bytes);
161156
}
162157
_ => {
163158
guar.get_or_insert_with(|| invalid_type_err(cx, token_lit, e.span, false));
164159
}
165160
},
166-
ast::ExprKind::IncludedBytes(bytes) => {
161+
ExprKind::IncludedBytes(bytes) => {
167162
accumulator.extend_from_slice(bytes);
168163
}
169-
ast::ExprKind::Err(guarantee) => {
164+
ExprKind::Err(guarantee) => {
170165
guar = Some(*guarantee);
171166
}
172-
ast::ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
167+
ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
173168
_ => {
174169
missing_literals.push(e.span);
175170
}
176171
}
177172
}
178173
if !missing_literals.is_empty() {
179174
let guar = cx.dcx().emit_err(errors::ConcatBytesMissingLiteral { spans: missing_literals });
180-
return base::MacEager::expr(DummyResult::raw_expr(sp, Some(guar)));
175+
return MacEager::expr(DummyResult::raw_expr(sp, Some(guar)));
181176
} else if let Some(guar) = guar {
182-
return base::MacEager::expr(DummyResult::raw_expr(sp, Some(guar)));
177+
return MacEager::expr(DummyResult::raw_expr(sp, Some(guar)));
183178
}
184179
let sp = cx.with_def_site_ctxt(sp);
185-
base::MacEager::expr(cx.expr_byte_str(sp, accumulator))
180+
MacEager::expr(cx.expr_byte_str(sp, accumulator))
186181
}

‎compiler/rustc_builtin_macros/src/concat_idents.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use rustc_ast as ast;
21
use rustc_ast::ptr::P;
32
use rustc_ast::token::{self, Token};
43
use rustc_ast::tokenstream::{TokenStream, TokenTree};
5-
use rustc_expand::base::{self, *};
4+
use rustc_ast::{AttrVec, Expr, ExprKind, Path, Ty, TyKind, DUMMY_NODE_ID};
5+
use rustc_expand::base::{DummyResult, ExtCtxt, MacResult};
66
use rustc_span::symbol::{Ident, Symbol};
77
use rustc_span::Span;
88

@@ -12,7 +12,7 @@ pub fn expand_concat_idents<'cx>(
1212
cx: &'cx mut ExtCtxt<'_>,
1313
sp: Span,
1414
tts: TokenStream,
15-
) -> Box<dyn base::MacResult + 'cx> {
15+
) -> Box<dyn MacResult + 'cx> {
1616
if tts.is_empty() {
1717
let guar = cx.dcx().emit_err(errors::ConcatIdentsMissingArgs { span: sp });
1818
return DummyResult::any(sp, guar);
@@ -47,21 +47,21 @@ pub fn expand_concat_idents<'cx>(
4747
ident: Ident,
4848
}
4949

50-
impl base::MacResult for ConcatIdentsResult {
51-
fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
52-
Some(P(ast::Expr {
53-
id: ast::DUMMY_NODE_ID,
54-
kind: ast::ExprKind::Path(None, ast::Path::from_ident(self.ident)),
50+
impl MacResult for ConcatIdentsResult {
51+
fn make_expr(self: Box<Self>) -> Option<P<Expr>> {
52+
Some(P(Expr {
53+
id: DUMMY_NODE_ID,
54+
kind: ExprKind::Path(None, Path::from_ident(self.ident)),
5555
span: self.ident.span,
56-
attrs: ast::AttrVec::new(),
56+
attrs: AttrVec::new(),
5757
tokens: None,
5858
}))
5959
}
6060

61-
fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
62-
Some(P(ast::Ty {
63-
id: ast::DUMMY_NODE_ID,
64-
kind: ast::TyKind::Path(None, ast::Path::from_ident(self.ident)),
61+
fn make_ty(self: Box<Self>) -> Option<P<Ty>> {
62+
Some(P(Ty {
63+
id: DUMMY_NODE_ID,
64+
kind: TyKind::Path(None, Path::from_ident(self.ident)),
6565
span: self.ident.span,
6666
tokens: None,
6767
}))

‎compiler/rustc_builtin_macros/src/env.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
// interface.
44
//
55

6+
use rustc_ast::token::{self, LitKind};
67
use rustc_ast::tokenstream::TokenStream;
7-
use rustc_ast::{self as ast, AstDeref, GenericArg};
8-
use rustc_expand::base::{self, *};
8+
use rustc_ast::{AstDeref, ExprKind, GenericArg, Mutability};
9+
use rustc_expand::base::{
10+
expr_to_string, get_exprs_from_tts, get_single_str_from_tts, DummyResult, ExtCtxt, MacEager,
11+
MacResult,
12+
};
913
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1014
use rustc_span::Span;
1115
use std::env;
@@ -27,7 +31,7 @@ pub fn expand_option_env<'cx>(
2731
cx: &'cx mut ExtCtxt<'_>,
2832
sp: Span,
2933
tts: TokenStream,
30-
) -> Box<dyn base::MacResult + 'cx> {
34+
) -> Box<dyn MacResult + 'cx> {
3135
let var = match get_single_str_from_tts(cx, sp, tts, "option_env!") {
3236
Ok(var) => var,
3337
Err(guar) => return DummyResult::any(sp, guar),
@@ -47,7 +51,7 @@ pub fn expand_option_env<'cx>(
4751
sp,
4852
cx.ty_ident(sp, Ident::new(sym::str, sp)),
4953
Some(lt),
50-
ast::Mutability::Not,
54+
Mutability::Not,
5155
))],
5256
))
5357
}
@@ -64,7 +68,7 @@ pub fn expand_env<'cx>(
6468
cx: &'cx mut ExtCtxt<'_>,
6569
sp: Span,
6670
tts: TokenStream,
67-
) -> Box<dyn base::MacResult + 'cx> {
71+
) -> Box<dyn MacResult + 'cx> {
6872
let mut exprs = match get_exprs_from_tts(cx, tts) {
6973
Ok(exprs) if exprs.is_empty() || exprs.len() > 2 => {
7074
let guar = cx.dcx().emit_err(errors::EnvTakesArgs { span: sp });
@@ -93,10 +97,8 @@ pub fn expand_env<'cx>(
9397
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value));
9498
let e = match value {
9599
None => {
96-
let ast::ExprKind::Lit(ast::token::Lit {
97-
kind: ast::token::LitKind::Str | ast::token::LitKind::StrRaw(..),
98-
symbol,
99-
..
100+
let ExprKind::Lit(token::Lit {
101+
kind: LitKind::Str | LitKind::StrRaw(..), symbol, ..
100102
}) = &var_expr.kind
101103
else {
102104
unreachable!("`expr_to_string` ensures this is a string lit")

‎compiler/rustc_builtin_macros/src/source_util.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use rustc_ast::ptr::P;
33
use rustc_ast::token;
44
use rustc_ast::tokenstream::TokenStream;
55
use rustc_ast_pretty::pprust;
6-
use rustc_expand::base::{self, *};
6+
use rustc_expand::base::{
7+
check_zero_tts, get_single_str_from_tts, parse_expr, resolve_path, DummyResult, ExtCtxt,
8+
MacEager, MacResult,
9+
};
710
use rustc_expand::module::DirOwnership;
811
use rustc_parse::new_parser_from_file;
912
use rustc_parse::parser::{ForceCollect, Parser};
@@ -23,29 +26,29 @@ pub fn expand_line(
2326
cx: &mut ExtCtxt<'_>,
2427
sp: Span,
2528
tts: TokenStream,
26-
) -> Box<dyn base::MacResult + 'static> {
29+
) -> Box<dyn MacResult + 'static> {
2730
let sp = cx.with_def_site_ctxt(sp);
28-
base::check_zero_tts(cx, sp, tts, "line!");
31+
check_zero_tts(cx, sp, tts, "line!");
2932

3033
let topmost = cx.expansion_cause().unwrap_or(sp);
3134
let loc = cx.source_map().lookup_char_pos(topmost.lo());
3235

33-
base::MacEager::expr(cx.expr_u32(topmost, loc.line as u32))
36+
MacEager::expr(cx.expr_u32(topmost, loc.line as u32))
3437
}
3538

3639
/* column!(): expands to the current column number */
3740
pub fn expand_column(
3841
cx: &mut ExtCtxt<'_>,
3942
sp: Span,
4043
tts: TokenStream,
41-
) -> Box<dyn base::MacResult + 'static> {
44+
) -> Box<dyn MacResult + 'static> {
4245
let sp = cx.with_def_site_ctxt(sp);
43-
base::check_zero_tts(cx, sp, tts, "column!");
46+
check_zero_tts(cx, sp, tts, "column!");
4447

4548
let topmost = cx.expansion_cause().unwrap_or(sp);
4649
let loc = cx.source_map().lookup_char_pos(topmost.lo());
4750

48-
base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32 + 1))
51+
MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32 + 1))
4952
}
5053

5154
/// file!(): expands to the current filename */
@@ -55,15 +58,15 @@ pub fn expand_file(
5558
cx: &mut ExtCtxt<'_>,
5659
sp: Span,
5760
tts: TokenStream,
58-
) -> Box<dyn base::MacResult + 'static> {
61+
) -> Box<dyn MacResult + 'static> {
5962
let sp = cx.with_def_site_ctxt(sp);
60-
base::check_zero_tts(cx, sp, tts, "file!");
63+
check_zero_tts(cx, sp, tts, "file!");
6164

6265
let topmost = cx.expansion_cause().unwrap_or(sp);
6366
let loc = cx.source_map().lookup_char_pos(topmost.lo());
6467

6568
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
66-
base::MacEager::expr(cx.expr_str(
69+
MacEager::expr(cx.expr_str(
6770
topmost,
6871
Symbol::intern(
6972
&loc.file.name.for_scope(cx.sess, RemapPathScopeComponents::MACRO).to_string_lossy(),
@@ -75,23 +78,23 @@ pub fn expand_stringify(
7578
cx: &mut ExtCtxt<'_>,
7679
sp: Span,
7780
tts: TokenStream,
78-
) -> Box<dyn base::MacResult + 'static> {
81+
) -> Box<dyn MacResult + 'static> {
7982
let sp = cx.with_def_site_ctxt(sp);
8083
let s = pprust::tts_to_string(&tts);
81-
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&s)))
84+
MacEager::expr(cx.expr_str(sp, Symbol::intern(&s)))
8285
}
8386

8487
pub fn expand_mod(
8588
cx: &mut ExtCtxt<'_>,
8689
sp: Span,
8790
tts: TokenStream,
88-
) -> Box<dyn base::MacResult + 'static> {
91+
) -> Box<dyn MacResult + 'static> {
8992
let sp = cx.with_def_site_ctxt(sp);
90-
base::check_zero_tts(cx, sp, tts, "module_path!");
93+
check_zero_tts(cx, sp, tts, "module_path!");
9194
let mod_path = &cx.current_expansion.module.mod_path;
9295
let string = mod_path.iter().map(|x| x.to_string()).collect::<Vec<String>>().join("::");
9396

94-
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&string)))
97+
MacEager::expr(cx.expr_str(sp, Symbol::intern(&string)))
9598
}
9699

97100
/// include! : parse the given file as an expr
@@ -101,7 +104,7 @@ pub fn expand_include<'cx>(
101104
cx: &'cx mut ExtCtxt<'_>,
102105
sp: Span,
103106
tts: TokenStream,
104-
) -> Box<dyn base::MacResult + 'cx> {
107+
) -> Box<dyn MacResult + 'cx> {
105108
let sp = cx.with_def_site_ctxt(sp);
106109
let file = match get_single_str_from_tts(cx, sp, tts, "include!") {
107110
Ok(file) => file,
@@ -129,9 +132,9 @@ pub fn expand_include<'cx>(
129132
p: Parser<'a>,
130133
node_id: ast::NodeId,
131134
}
132-
impl<'a> base::MacResult for ExpandResult<'a> {
135+
impl<'a> MacResult for ExpandResult<'a> {
133136
fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
134-
let expr = base::parse_expr(&mut self.p).ok()?;
137+
let expr = parse_expr(&mut self.p).ok()?;
135138
if self.p.token != token::Eof {
136139
self.p.sess.buffer_lint(
137140
INCOMPLETE_INCLUDE,
@@ -175,7 +178,7 @@ pub fn expand_include_str(
175178
cx: &mut ExtCtxt<'_>,
176179
sp: Span,
177180
tts: TokenStream,
178-
) -> Box<dyn base::MacResult + 'static> {
181+
) -> Box<dyn MacResult + 'static> {
179182
let sp = cx.with_def_site_ctxt(sp);
180183
let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") {
181184
Ok(file) => file,
@@ -192,7 +195,7 @@ pub fn expand_include_str(
192195
Ok(bytes) => match std::str::from_utf8(&bytes) {
193196
Ok(src) => {
194197
let interned_src = Symbol::intern(src);
195-
base::MacEager::expr(cx.expr_str(sp, interned_src))
198+
MacEager::expr(cx.expr_str(sp, interned_src))
196199
}
197200
Err(_) => {
198201
let guar = cx.dcx().span_err(sp, format!("{} wasn't a utf-8 file", file.display()));
@@ -210,7 +213,7 @@ pub fn expand_include_bytes(
210213
cx: &mut ExtCtxt<'_>,
211214
sp: Span,
212215
tts: TokenStream,
213-
) -> Box<dyn base::MacResult + 'static> {
216+
) -> Box<dyn MacResult + 'static> {
214217
let sp = cx.with_def_site_ctxt(sp);
215218
let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {
216219
Ok(file) => file,
@@ -226,7 +229,7 @@ pub fn expand_include_bytes(
226229
match cx.source_map().load_binary_file(&file) {
227230
Ok(bytes) => {
228231
let expr = cx.expr(sp, ast::ExprKind::IncludedBytes(bytes));
229-
base::MacEager::expr(expr)
232+
MacEager::expr(expr)
230233
}
231234
Err(e) => {
232235
let guar = cx.dcx().span_err(sp, format!("couldn't read {}: {}", file.display(), e));

0 commit comments

Comments
 (0)
Please sign in to comment.