Remove ast::
& base::
prefixes from some builtin macros
This commit is contained in:
parent
c440a5b814
commit
34eae07ee5
7 changed files with 116 additions and 118 deletions
|
@ -1,17 +1,17 @@
|
|||
use rustc_ast as ast;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_expand::base::{self, DummyResult};
|
||||
use rustc_ast::{ExprKind, LitKind, UnOp};
|
||||
use rustc_expand::base::{get_exprs_from_tts, DummyResult, ExtCtxt, MacEager, MacResult};
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::symbol::Symbol;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
pub fn expand_concat(
|
||||
cx: &mut base::ExtCtxt<'_>,
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: rustc_span::Span,
|
||||
tts: TokenStream,
|
||||
) -> Box<dyn base::MacResult + 'static> {
|
||||
let es = match base::get_exprs_from_tts(cx, tts) {
|
||||
) -> Box<dyn MacResult + 'static> {
|
||||
let es = match get_exprs_from_tts(cx, tts) {
|
||||
Ok(es) => es,
|
||||
Err(guar) => return DummyResult::any(sp, guar),
|
||||
};
|
||||
|
@ -20,26 +20,26 @@ pub fn expand_concat(
|
|||
let mut guar = None;
|
||||
for e in es {
|
||||
match e.kind {
|
||||
ast::ExprKind::Lit(token_lit) => match ast::LitKind::from_token_lit(token_lit) {
|
||||
Ok(ast::LitKind::Str(s, _) | ast::LitKind::Float(s, _)) => {
|
||||
ExprKind::Lit(token_lit) => match LitKind::from_token_lit(token_lit) {
|
||||
Ok(LitKind::Str(s, _) | LitKind::Float(s, _)) => {
|
||||
accumulator.push_str(s.as_str());
|
||||
}
|
||||
Ok(ast::LitKind::Char(c)) => {
|
||||
Ok(LitKind::Char(c)) => {
|
||||
accumulator.push(c);
|
||||
}
|
||||
Ok(ast::LitKind::Int(i, _)) => {
|
||||
Ok(LitKind::Int(i, _)) => {
|
||||
accumulator.push_str(&i.to_string());
|
||||
}
|
||||
Ok(ast::LitKind::Bool(b)) => {
|
||||
Ok(LitKind::Bool(b)) => {
|
||||
accumulator.push_str(&b.to_string());
|
||||
}
|
||||
Ok(ast::LitKind::CStr(..)) => {
|
||||
Ok(LitKind::CStr(..)) => {
|
||||
guar = Some(cx.dcx().emit_err(errors::ConcatCStrLit { span: e.span }));
|
||||
}
|
||||
Ok(ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..)) => {
|
||||
Ok(LitKind::Byte(..) | LitKind::ByteStr(..)) => {
|
||||
guar = Some(cx.dcx().emit_err(errors::ConcatBytestr { span: e.span }));
|
||||
}
|
||||
Ok(ast::LitKind::Err(guarantee)) => {
|
||||
Ok(LitKind::Err(guarantee)) => {
|
||||
guar = Some(guarantee);
|
||||
}
|
||||
Err(err) => {
|
||||
|
@ -47,25 +47,23 @@ pub fn expand_concat(
|
|||
}
|
||||
},
|
||||
// We also want to allow negative numeric literals.
|
||||
ast::ExprKind::Unary(ast::UnOp::Neg, ref expr)
|
||||
if let ast::ExprKind::Lit(token_lit) = expr.kind =>
|
||||
{
|
||||
match ast::LitKind::from_token_lit(token_lit) {
|
||||
Ok(ast::LitKind::Int(i, _)) => accumulator.push_str(&format!("-{i}")),
|
||||
Ok(ast::LitKind::Float(f, _)) => accumulator.push_str(&format!("-{f}")),
|
||||
ExprKind::Unary(UnOp::Neg, ref expr) if let ExprKind::Lit(token_lit) = expr.kind => {
|
||||
match LitKind::from_token_lit(token_lit) {
|
||||
Ok(LitKind::Int(i, _)) => accumulator.push_str(&format!("-{i}")),
|
||||
Ok(LitKind::Float(f, _)) => accumulator.push_str(&format!("-{f}")),
|
||||
Err(err) => {
|
||||
guar = Some(report_lit_error(&cx.sess.parse_sess, err, token_lit, e.span));
|
||||
}
|
||||
_ => missing_literal.push(e.span),
|
||||
}
|
||||
}
|
||||
ast::ExprKind::IncludedBytes(..) => {
|
||||
ExprKind::IncludedBytes(..) => {
|
||||
cx.dcx().emit_err(errors::ConcatBytestr { span: e.span });
|
||||
}
|
||||
ast::ExprKind::Err(guarantee) => {
|
||||
ExprKind::Err(guarantee) => {
|
||||
guar = Some(guarantee);
|
||||
}
|
||||
ast::ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
|
||||
ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
|
||||
_ => {
|
||||
missing_literal.push(e.span);
|
||||
}
|
||||
|
@ -79,5 +77,5 @@ pub fn expand_concat(
|
|||
return DummyResult::any(sp, guar);
|
||||
}
|
||||
let sp = cx.with_def_site_ctxt(sp);
|
||||
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
|
||||
MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue