Use token::Lit in ast::ExprKind::Lit.
Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_expand::base::{self, DummyResult};
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::symbol::Symbol;
|
||||
|
||||
use std::string::String;
|
||||
@@ -18,28 +19,28 @@ pub fn expand_concat(
|
||||
let mut has_errors = false;
|
||||
for e in es {
|
||||
match e.kind {
|
||||
ast::ExprKind::Lit(ref lit) => match lit.kind {
|
||||
ast::LitKind::Str(ref s, _) | ast::LitKind::Float(ref s, _) => {
|
||||
ast::ExprKind::Lit(token_lit) => match ast::LitKind::from_token_lit(token_lit) {
|
||||
Ok(ast::LitKind::Str(ref s, _) | ast::LitKind::Float(ref s, _)) => {
|
||||
accumulator.push_str(s.as_str());
|
||||
}
|
||||
ast::LitKind::Char(c) => {
|
||||
Ok(ast::LitKind::Char(c)) => {
|
||||
accumulator.push(c);
|
||||
}
|
||||
ast::LitKind::Int(
|
||||
i,
|
||||
ast::LitIntType::Unsigned(_)
|
||||
| ast::LitIntType::Signed(_)
|
||||
| ast::LitIntType::Unsuffixed,
|
||||
) => {
|
||||
Ok(ast::LitKind::Int(i, _)) => {
|
||||
accumulator.push_str(&i.to_string());
|
||||
}
|
||||
ast::LitKind::Bool(b) => {
|
||||
Ok(ast::LitKind::Bool(b)) => {
|
||||
accumulator.push_str(&b.to_string());
|
||||
}
|
||||
ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..) => {
|
||||
Ok(ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..)) => {
|
||||
cx.span_err(e.span, "cannot concatenate a byte string literal");
|
||||
has_errors = true;
|
||||
}
|
||||
ast::LitKind::Err => {
|
||||
Ok(ast::LitKind::Err) => {
|
||||
has_errors = true;
|
||||
}
|
||||
Err(err) => {
|
||||
report_lit_error(&cx.sess.parse_sess, err, token_lit, e.span);
|
||||
has_errors = true;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user