diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-09-12 20:02:11 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-12 20:02:11 +1000 |
| commit | 40520c635728968693f59808d48ee6baf17dfaac (patch) | |
| tree | a0edfb2592f9418ce1c2ecbbaf3601ba58d30f11 /compiler/rustc_expand | |
| parent | 1037c082bc7d3ccd803b3eb0d48fc7fd81ddc733 (diff) | |
| parent | 1cb749aa3b421db4f918e8befca569166e8ba6ab (diff) | |
| download | rust-40520c635728968693f59808d48ee6baf17dfaac.tar.gz rust-40520c635728968693f59808d48ee6baf17dfaac.zip | |
Rollup merge of #146308 - cyrgani:concat-integer-literals, r=jackh726
support integer literals in `${concat()}`
Tracking issue: rust-lang/rust#124225
Adds support for using integer literals as arguments to `${concat()}` macro expressions.
Integer formatting such as `1_000` is preserved by this.
Diffstat (limited to 'compiler/rustc_expand')
| -rw-r--r-- | compiler/rustc_expand/src/mbe/transcribe.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index e4e4866b64c..ed8aa71d59d 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -940,11 +940,27 @@ fn extract_symbol_from_pnr<'a>( { Ok(*symbol) } + ParseNtResult::Literal(expr) + if let ExprKind::Lit(lit @ Lit { kind: LitKind::Integer, symbol, suffix }) = + &expr.kind => + { + if lit.is_semantic_float() { + Err(dcx + .struct_err("floats are not supported as metavariables of `${concat(..)}`") + .with_span(span_err)) + } else if suffix.is_none() { + Ok(*symbol) + } else { + Err(dcx + .struct_err("integer metavariables of `${concat(..)}` must not be suffixed") + .with_span(span_err)) + } + } _ => Err(dcx .struct_err( "metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt`", ) - .with_note("currently only string literals are supported") + .with_note("currently only string and integer literals are supported") .with_span(span_err)), } } |
