about summary refs log tree commit diff
path: root/tests/ui/macros/metavar-expressions/concat-usage-errors.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-01 05:31:05 +0000
committerbors <bors@rust-lang.org>2025-07-01 05:31:05 +0000
commitf46ce66fcc3d6058f90ac5bf0930f940f1e7b0ca (patch)
tree17a06668752fe94c0824b6b9788c02e7fbf56f1e /tests/ui/macros/metavar-expressions/concat-usage-errors.rs
parent6988a8fea774a2a20ebebddb7dbf15dd6ef594f9 (diff)
parent3944c8ce447404dc45c00e125baf6bbbd728b501 (diff)
downloadrust-f46ce66fcc3d6058f90ac5bf0930f940f1e7b0ca.tar.gz
rust-f46ce66fcc3d6058f90ac5bf0930f940f1e7b0ca.zip
Auto merge of #143267 - matthiaskrgr:rollup-suvzar6, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#143125 (Disable f16 on Aarch64 without neon for llvm < 20.1.1)
 - rust-lang/rust#143156 (inherit `#[align]` from trait method prototypes)
 - rust-lang/rust#143178 (rustdoc default faviocon)
 - rust-lang/rust#143234 (Replace `ItemCtxt::report_placeholder_type_error` match with a call to `TyCtxt::def_descr`)
 - rust-lang/rust#143245 (mbe: Add tests and restructure metavariable expressions)
 - rust-lang/rust#143257 (Upgrade dependencies in run-make-support)
 - rust-lang/rust#143263 (linkify CodeSuggestion in doc comments)
 - rust-lang/rust#143264 (fix: Emit suggestion filename if primary diagnostic span is dummy)

Failed merges:

 - rust-lang/rust#143251 (bootstrap: add build.tidy-extra-checks option)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests/ui/macros/metavar-expressions/concat-usage-errors.rs')
-rw-r--r--tests/ui/macros/metavar-expressions/concat-usage-errors.rs190
1 files changed, 190 insertions, 0 deletions
diff --git a/tests/ui/macros/metavar-expressions/concat-usage-errors.rs b/tests/ui/macros/metavar-expressions/concat-usage-errors.rs
new file mode 100644
index 00000000000..7d8756de9e2
--- /dev/null
+++ b/tests/ui/macros/metavar-expressions/concat-usage-errors.rs
@@ -0,0 +1,190 @@
+//@ edition: 2021
+
+#![feature(macro_metavar_expr_concat)]
+
+macro_rules! syntax_errors {
+    ($ex:expr) => {
+        ${concat()}
+        //~^ ERROR expected identifier
+
+        ${concat(aaaa)}
+        //~^ ERROR `concat` must have at least two elements
+
+        ${concat(aaaa,)}
+        //~^ ERROR expected identifier
+
+        ${concat(_, aaaa)}
+
+        ${concat(aaaa aaaa)}
+        //~^ ERROR expected comma
+
+        ${concat($ex)}
+        //~^ ERROR `concat` must have at least two elements
+
+        ${concat($ex, aaaa)}
+        //~^ ERROR metavariables of `${concat(..)}` must be of type
+
+        ${concat($ex, aaaa 123)}
+        //~^ ERROR expected comma
+
+        ${concat($ex, aaaa,)}
+        //~^ ERROR expected identifier
+    };
+}
+
+macro_rules! dollar_sign_without_referenced_ident {
+    ($ident:ident) => {
+        const ${concat(FOO, $foo)}: i32 = 2;
+        //~^ ERROR variable `foo` is not recognized in meta-variable expression
+    };
+}
+
+macro_rules! starting_number {
+    ($ident:ident) => {{
+        let ${concat("1", $ident)}: () = ();
+        //~^ ERROR `${concat(..)}` is not generating a valid identifier
+    }};
+}
+
+macro_rules! starting_valid_unicode {
+    ($ident:ident) => {{
+        let ${concat("Ý", $ident)}: () = ();
+    }};
+}
+
+macro_rules! starting_invalid_unicode {
+    ($ident:ident) => {{
+        let ${concat("\u{00BD}", $ident)}: () = ();
+        //~^ ERROR `${concat(..)}` is not generating a valid identifier
+    }};
+}
+
+macro_rules! ending_number {
+    ($ident:ident) => {{
+        let ${concat($ident, "1")}: () = ();
+    }};
+}
+
+macro_rules! ending_valid_unicode {
+    ($ident:ident) => {{
+        let ${concat($ident, "Ý")}: () = ();
+    }};
+}
+
+macro_rules! ending_invalid_unicode {
+    ($ident:ident) => {{
+        let ${concat($ident, "\u{00BD}")}: () = ();
+        //~^ ERROR `${concat(..)}` is not generating a valid identifier
+    }};
+}
+
+macro_rules! empty {
+    () => {{
+        let ${concat("", "")}: () = ();
+        //~^ ERROR `${concat(..)}` is not generating a valid identifier
+    }};
+}
+
+macro_rules! unsupported_literals {
+    ($ident:ident) => {{
+        let ${concat(_a, 'b')}: () = ();
+        //~^ ERROR expected identifier or string literal
+        //~| ERROR expected pattern
+        let ${concat(_a, 1)}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat(_a, 1.5)}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat(_a, c"hi")}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat(_a, b"hi")}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat(_a, b'b')}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat(_a, b'b')}: () = ();
+        //~^ ERROR expected identifier or string literal
+
+        let ${concat($ident, 'b')}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat($ident, 1)}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat($ident, 1.5)}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat($ident, c"hi")}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat($ident, b"hi")}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat($ident, b'b')}: () = ();
+        //~^ ERROR expected identifier or string literal
+        let ${concat($ident, b'b')}: () = ();
+        //~^ ERROR expected identifier or string literal
+    }};
+}
+
+macro_rules! bad_literal_string {
+    ($literal:literal) => {
+        const ${concat(_foo, $literal)}: () = ();
+        //~^ ERROR `${concat(..)}` is not generating a valid identifier
+        //~| ERROR `${concat(..)}` is not generating a valid identifier
+        //~| ERROR `${concat(..)}` is not generating a valid identifier
+        //~| ERROR `${concat(..)}` is not generating a valid identifier
+        //~| ERROR `${concat(..)}` is not generating a valid identifier
+        //~| ERROR `${concat(..)}` is not generating a valid identifier
+        //~| ERROR `${concat(..)}` is not generating a valid identifier
+    }
+}
+
+macro_rules! bad_literal_non_string {
+    ($literal:literal) => {
+        const ${concat(_foo, $literal)}: () = ();
+        //~^ ERROR metavariables of `${concat(..)}` must be of type
+        //~| ERROR metavariables of `${concat(..)}` must be of type
+        //~| ERROR metavariables of `${concat(..)}` must be of type
+        //~| ERROR metavariables of `${concat(..)}` must be of type
+        //~| ERROR metavariables of `${concat(..)}` must be of type
+    }
+}
+
+macro_rules! bad_tt_literal {
+    ($tt:tt) => {
+        const ${concat(_foo, $tt)}: () = ();
+        //~^ ERROR metavariables of `${concat(..)}` must be of type
+        //~| ERROR metavariables of `${concat(..)}` must be of type
+        //~| ERROR metavariables of `${concat(..)}` must be of type
+    }
+}
+
+fn main() {
+    syntax_errors!(1);
+
+    dollar_sign_without_referenced_ident!(VAR);
+
+    starting_number!(_abc);
+    starting_valid_unicode!(_abc);
+    starting_invalid_unicode!(_abc);
+
+    ending_number!(_abc);
+    ending_valid_unicode!(_abc);
+    ending_invalid_unicode!(_abc);
+    unsupported_literals!(_abc);
+
+    empty!();
+
+    bad_literal_string!("\u{00BD}");
+    bad_literal_string!("\x41");
+    bad_literal_string!("🤷");
+    bad_literal_string!("d[-_-]b");
+
+    bad_literal_string!("-1");
+    bad_literal_string!("1.0");
+    bad_literal_string!("'1'");
+
+    bad_literal_non_string!(1);
+    bad_literal_non_string!(-1);
+    bad_literal_non_string!(1.0);
+    bad_literal_non_string!('1');
+    bad_literal_non_string!(false);
+
+    bad_tt_literal!(1);
+    bad_tt_literal!(1.0);
+    bad_tt_literal!('1');
+}