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:
parent
01760265cb
commit
358a603f11
45 changed files with 701 additions and 581 deletions
|
@ -49,10 +49,12 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta
|
|||
MetaItemKind::List(nmis)
|
||||
}
|
||||
MacArgs::Eq(_, MacArgsEq::Ast(expr)) => {
|
||||
if let ast::ExprKind::Lit(lit) = &expr.kind {
|
||||
if !lit.kind.is_unsuffixed() {
|
||||
if let ast::ExprKind::Lit(token_lit) = expr.kind
|
||||
&& let Ok(lit) = ast::Lit::from_token_lit(token_lit, expr.span)
|
||||
{
|
||||
if token_lit.suffix.is_some() {
|
||||
let mut err = sess.span_diagnostic.struct_span_err(
|
||||
lit.span,
|
||||
expr.span,
|
||||
"suffixed literals are not allowed in attributes",
|
||||
);
|
||||
err.help(
|
||||
|
@ -61,7 +63,7 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta
|
|||
);
|
||||
return Err(err);
|
||||
} else {
|
||||
MetaItemKind::NameValue(lit.clone())
|
||||
MetaItemKind::NameValue(lit)
|
||||
}
|
||||
} else {
|
||||
// The non-error case can happen with e.g. `#[foo = 1+1]`. The error case can
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue