From cf5eb279101511fa9ee38988adab7cac9a57f0da Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 20 Jun 2025 16:50:20 -0400 Subject: mbe: Restructure `macro_metavar_expr` tests These tests have expanded beyond the RFC, so rename the directory `rfc-3086-metavar-expr` to `metavar-expressions`. `concat` (which wasn't part of the RFC) now fits in this group, so merge its tests into the `metavar-expressions` directory. Additionally rename some related `issue-*` tests. --- src/tools/tidy/src/issues.txt | 1 - .../allowed-operations.rs | 115 ------- .../ui/macros/macro-metavar-expr-concat/hygiene.rs | 13 - .../macro-metavar-expr-concat/hygiene.stderr | 14 - .../macro-metavar-expr-concat/raw-identifiers.rs | 81 ----- .../raw-identifiers.stderr | 95 ----- .../macro-metavar-expr-concat/repetitions.rs | 36 -- .../macro-metavar-expr-concat/repetitions.stderr | 22 -- .../macro-metavar-expr-concat/syntax-errors.rs | 168 --------- .../macro-metavar-expr-concat/syntax-errors.stderr | 284 --------------- .../macro-metavar-expr-concat/unicode-expansion.rs | 19 - .../concat-allowed-operations.rs | 115 +++++++ .../macros/metavar-expressions/concat-hygiene.rs | 13 + .../metavar-expressions/concat-hygiene.stderr | 14 + .../metavar-expressions/concat-raw-identifiers.rs | 81 +++++ .../concat-raw-identifiers.stderr | 95 +++++ .../metavar-expressions/concat-repetitions.rs | 36 ++ .../metavar-expressions/concat-repetitions.stderr | 22 ++ .../metavar-expressions/concat-syntax-errors.rs | 168 +++++++++ .../concat-syntax-errors.stderr | 284 +++++++++++++++ .../concat-unicode-expansion.rs | 19 + .../count-and-length-are-distinct.rs | 283 +++++++++++++++ .../metavar-expressions/count-empty-index-arg.rs | 16 + .../count-empty-index-arg.stderr | 19 + .../dollar-dollar-has-correct-behavior.rs | 28 ++ .../feature-gate-macro_metavar_expr.rs | 147 ++++++++ .../macros/metavar-expressions/macro-expansion.rs | 102 ++++++ .../metavar-expressions/out-of-bounds-arguments.rs | 43 +++ .../out-of-bounds-arguments.stderr | 20 ++ .../macros/metavar-expressions/required-feature.rs | 43 +++ .../metavar-expressions/required-feature.stderr | 103 ++++++ .../ui/macros/metavar-expressions/syntax-errors.rs | 164 +++++++++ .../metavar-expressions/syntax-errors.stderr | 382 +++++++++++++++++++++ .../count-and-length-are-distinct.rs | 283 --------------- .../dollar-dollar-has-correct-behavior.rs | 28 -- .../feature-gate-macro_metavar_expr.rs | 147 -------- .../macros/rfc-3086-metavar-expr/issue-111904.rs | 14 - .../rfc-3086-metavar-expr/issue-111904.stderr | 19 - .../rfc-3086-metavar-expr/macro-expansion.rs | 102 ------ .../out-of-bounds-arguments.rs | 43 --- .../out-of-bounds-arguments.stderr | 20 -- .../rfc-3086-metavar-expr/required-feature.rs | 43 --- .../rfc-3086-metavar-expr/required-feature.stderr | 103 ------ .../macros/rfc-3086-metavar-expr/syntax-errors.rs | 164 --------- .../rfc-3086-metavar-expr/syntax-errors.stderr | 382 --------------------- 45 files changed, 2197 insertions(+), 2196 deletions(-) delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/allowed-operations.rs delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/hygiene.rs delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/hygiene.stderr delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/repetitions.rs delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/repetitions.stderr delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr delete mode 100644 tests/ui/macros/macro-metavar-expr-concat/unicode-expansion.rs create mode 100644 tests/ui/macros/metavar-expressions/concat-allowed-operations.rs create mode 100644 tests/ui/macros/metavar-expressions/concat-hygiene.rs create mode 100644 tests/ui/macros/metavar-expressions/concat-hygiene.stderr create mode 100644 tests/ui/macros/metavar-expressions/concat-raw-identifiers.rs create mode 100644 tests/ui/macros/metavar-expressions/concat-raw-identifiers.stderr create mode 100644 tests/ui/macros/metavar-expressions/concat-repetitions.rs create mode 100644 tests/ui/macros/metavar-expressions/concat-repetitions.stderr create mode 100644 tests/ui/macros/metavar-expressions/concat-syntax-errors.rs create mode 100644 tests/ui/macros/metavar-expressions/concat-syntax-errors.stderr create mode 100644 tests/ui/macros/metavar-expressions/concat-unicode-expansion.rs create mode 100644 tests/ui/macros/metavar-expressions/count-and-length-are-distinct.rs create mode 100644 tests/ui/macros/metavar-expressions/count-empty-index-arg.rs create mode 100644 tests/ui/macros/metavar-expressions/count-empty-index-arg.stderr create mode 100644 tests/ui/macros/metavar-expressions/dollar-dollar-has-correct-behavior.rs create mode 100644 tests/ui/macros/metavar-expressions/feature-gate-macro_metavar_expr.rs create mode 100644 tests/ui/macros/metavar-expressions/macro-expansion.rs create mode 100644 tests/ui/macros/metavar-expressions/out-of-bounds-arguments.rs create mode 100644 tests/ui/macros/metavar-expressions/out-of-bounds-arguments.stderr create mode 100644 tests/ui/macros/metavar-expressions/required-feature.rs create mode 100644 tests/ui/macros/metavar-expressions/required-feature.stderr create mode 100644 tests/ui/macros/metavar-expressions/syntax-errors.rs create mode 100644 tests/ui/macros/metavar-expressions/syntax-errors.stderr delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/count-and-length-are-distinct.rs delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/dollar-dollar-has-correct-behavior.rs delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/issue-111904.rs delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/issue-111904.stderr delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/macro-expansion.rs delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.rs delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.stderr delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/required-feature.rs delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/required-feature.stderr delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs delete mode 100644 tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index b3517b2e9da..0f908e4f551 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -2849,7 +2849,6 @@ ui/macros/issue-98466.rs ui/macros/issue-99261.rs ui/macros/issue-99265.rs ui/macros/issue-99907.rs -ui/macros/rfc-3086-metavar-expr/issue-111904.rs ui/malformed/issue-107423-unused-delim-only-one-no-pair.rs ui/malformed/issue-69341-malformed-derive-inert.rs ui/marker_trait_attr/issue-61651-type-mismatch.rs diff --git a/tests/ui/macros/macro-metavar-expr-concat/allowed-operations.rs b/tests/ui/macros/macro-metavar-expr-concat/allowed-operations.rs deleted file mode 100644 index 695a752fe17..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/allowed-operations.rs +++ /dev/null @@ -1,115 +0,0 @@ -//@ run-pass - -#![allow(dead_code, non_camel_case_types, non_upper_case_globals, unused_variables)] -#![feature(macro_metavar_expr_concat)] - -macro_rules! create_things { - ($lhs:ident) => { - struct ${concat($lhs, _separated_idents_in_a_struct)} { - foo: i32, - ${concat($lhs, _separated_idents_in_a_field)}: i32, - } - - mod ${concat($lhs, _separated_idents_in_a_module)} { - pub const FOO: () = (); - } - - fn ${concat($lhs, _separated_idents_in_a_fn)}() {} - }; -} - -macro_rules! many_idents { - ($a:ident, $c:ident) => { - const ${concat($a, B, $c, D)}: i32 = 1; - }; -} - -macro_rules! valid_tts { - ($_0:tt, $_1:tt) => { - const ${concat($_0, $_1)}: i32 = 1; - } -} - -macro_rules! without_dollar_sign_is_an_ident { - ($ident:ident) => { - const ${concat(VAR, ident)}: i32 = 1; - const ${concat(VAR, $ident)}: i32 = 2; - }; -} - -macro_rules! combinations { - ($ident:ident, $literal:literal, $tt_ident:tt, $tt_literal:tt) => {{ - // tt ident - let ${concat($tt_ident, b)} = (); - let ${concat($tt_ident, _b)} = (); - let ${concat($tt_ident, "b")} = (); - let ${concat($tt_ident, $tt_ident)} = (); - let ${concat($tt_ident, $tt_literal)} = (); - let ${concat($tt_ident, $ident)} = (); - let ${concat($tt_ident, $literal)} = (); - // tt literal - let ${concat($tt_literal, b)} = (); - let ${concat($tt_literal, _b)} = (); - let ${concat($tt_literal, "b")} = (); - let ${concat($tt_literal, $tt_ident)} = (); - let ${concat($tt_literal, $tt_literal)} = (); - let ${concat($tt_literal, $ident)} = (); - let ${concat($tt_literal, $literal)} = (); - - // ident (adhoc) - let ${concat(_b, b)} = (); - let ${concat(_b, _b)} = (); - let ${concat(_b, "b")} = (); - let ${concat(_b, $tt_ident)} = (); - let ${concat(_b, $tt_literal)} = (); - let ${concat(_b, $ident)} = (); - let ${concat(_b, $literal)} = (); - // ident (param) - let ${concat($ident, b)} = (); - let ${concat($ident, _b)} = (); - let ${concat($ident, "b")} = (); - let ${concat($ident, $tt_ident)} = (); - let ${concat($ident, $tt_literal)} = (); - let ${concat($ident, $ident)} = (); - let ${concat($ident, $literal)} = (); - - // literal (adhoc) - let ${concat("a", b)} = (); - let ${concat("a", _b)} = (); - let ${concat("a", "b")} = (); - let ${concat("a", $tt_ident)} = (); - let ${concat("a", $tt_literal)} = (); - let ${concat("a", $ident)} = (); - let ${concat("a", $literal)} = (); - // literal (param) - let ${concat($literal, b)} = (); - let ${concat($literal, _b)} = (); - let ${concat($literal, "b")} = (); - let ${concat($literal, $tt_ident)} = (); - let ${concat($literal, $tt_literal)} = (); - let ${concat($literal, $ident)} = (); - let ${concat($literal, $literal)} = (); - }}; -} - -fn main() { - create_things!(behold); - behold_separated_idents_in_a_fn(); - let _ = behold_separated_idents_in_a_module::FOO; - let _ = behold_separated_idents_in_a_struct { - foo: 1, - behold_separated_idents_in_a_field: 2, - }; - - many_idents!(A, C); - assert_eq!(ABCD, 1); - - valid_tts!(X, YZ); - assert_eq!(XYZ, 1); - - without_dollar_sign_is_an_ident!(_123); - assert_eq!(VARident, 1); - assert_eq!(VAR_123, 2); - - combinations!(_hello, "a", b, "b"); -} diff --git a/tests/ui/macros/macro-metavar-expr-concat/hygiene.rs b/tests/ui/macros/macro-metavar-expr-concat/hygiene.rs deleted file mode 100644 index 24b0e36498a..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/hygiene.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![feature(macro_metavar_expr_concat)] - -macro_rules! join { - ($lhs:ident, $rhs:ident) => { - ${concat($lhs, $rhs)} - //~^ ERROR cannot find value `abcdef` in this scope - }; -} - -fn main() { - let abcdef = 1; - let _another = join!(abc, def); -} diff --git a/tests/ui/macros/macro-metavar-expr-concat/hygiene.stderr b/tests/ui/macros/macro-metavar-expr-concat/hygiene.stderr deleted file mode 100644 index ef2326dce85..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/hygiene.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0425]: cannot find value `abcdef` in this scope - --> $DIR/hygiene.rs:5:10 - | -LL | ${concat($lhs, $rhs)} - | ^^^^^^^^^^^^^^^^^^^^ not found in this scope -... -LL | let _another = join!(abc, def); - | --------------- in this macro invocation - | - = note: this error originates in the macro `join` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs b/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs deleted file mode 100644 index b1cb2141cc4..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs +++ /dev/null @@ -1,81 +0,0 @@ -#![feature(macro_metavar_expr_concat)] - -macro_rules! idents_01 { - ($rhs:ident) => { - let ${concat(abc, $rhs)}: () = (); - //~^ ERROR `${concat(..)}` currently does not support raw identifiers - }; -} - -macro_rules! idents_10 { - ($lhs:ident) => { - let ${concat($lhs, abc)}: () = (); - //~^ ERROR `${concat(..)}` currently does not support raw identifiers - }; -} - -macro_rules! idents_11 { - ($lhs:ident, $rhs:ident) => { - let ${concat($lhs, $rhs)}: () = (); - //~^ ERROR `${concat(..)}` currently does not support raw identifiers - //~| ERROR `${concat(..)}` currently does not support raw identifiers - //~| ERROR `${concat(..)}` currently does not support raw identifiers - }; -} - -macro_rules! no_params { - () => { - let ${concat(r#abc, abc)}: () = (); - //~^ ERROR expected identifier or string literal - //~| ERROR expected pattern, found `$` - - let ${concat(abc, r#abc)}: () = (); - //~^ ERROR expected identifier or string literal - - let ${concat(r#abc, r#abc)}: () = (); - //~^ ERROR expected identifier or string literal - }; -} - -macro_rules! tts_01 { - ($rhs:tt) => { - let ${concat(abc, $rhs)}: () = (); - //~^ ERROR `${concat(..)}` currently does not support raw identifiers - }; -} - -macro_rules! tts_10 { - ($lhs:tt) => { - let ${concat($lhs, abc)}: () = (); - //~^ ERROR `${concat(..)}` currently does not support raw identifiers - }; -} - -macro_rules! tts_11 { - ($lhs:tt, $rhs:tt) => { - let ${concat($lhs, $rhs)}: () = (); - //~^ ERROR `${concat(..)}` currently does not support raw identifiers - //~| ERROR `${concat(..)}` currently does not support raw identifiers - //~| ERROR `${concat(..)}` currently does not support raw identifiers - }; -} - -fn main() { - idents_01!(r#_c); - - idents_10!(r#_c); - - idents_11!(r#_c, d); - idents_11!(_e, r#f); - idents_11!(r#_g, r#h); - - tts_01!(r#_c); - - tts_10!(r#_c); - - tts_11!(r#_c, d); - tts_11!(_e, r#f); - tts_11!(r#_g, r#h); - - no_params!(); -} diff --git a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr b/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr deleted file mode 100644 index 4e11e20acc5..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr +++ /dev/null @@ -1,95 +0,0 @@ -error: expected identifier or string literal - --> $DIR/raw-identifiers.rs:28:22 - | -LL | let ${concat(r#abc, abc)}: () = (); - | ^^^^^ - -error: expected identifier or string literal - --> $DIR/raw-identifiers.rs:32:27 - | -LL | let ${concat(abc, r#abc)}: () = (); - | ^^^^^ - -error: expected identifier or string literal - --> $DIR/raw-identifiers.rs:35:22 - | -LL | let ${concat(r#abc, r#abc)}: () = (); - | ^^^^^ - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:5:28 - | -LL | let ${concat(abc, $rhs)}: () = (); - | ^^^ - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:12:23 - | -LL | let ${concat($lhs, abc)}: () = (); - | ^^^ - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:19:23 - | -LL | let ${concat($lhs, $rhs)}: () = (); - | ^^^ - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:19:29 - | -LL | let ${concat($lhs, $rhs)}: () = (); - | ^^^ - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:19:23 - | -LL | let ${concat($lhs, $rhs)}: () = (); - | ^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:42:28 - | -LL | let ${concat(abc, $rhs)}: () = (); - | ^^^ - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:49:23 - | -LL | let ${concat($lhs, abc)}: () = (); - | ^^^ - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:56:23 - | -LL | let ${concat($lhs, $rhs)}: () = (); - | ^^^ - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:56:29 - | -LL | let ${concat($lhs, $rhs)}: () = (); - | ^^^ - -error: `${concat(..)}` currently does not support raw identifiers - --> $DIR/raw-identifiers.rs:56:23 - | -LL | let ${concat($lhs, $rhs)}: () = (); - | ^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: expected pattern, found `$` - --> $DIR/raw-identifiers.rs:28:13 - | -LL | let ${concat(r#abc, abc)}: () = (); - | ^ expected pattern -... -LL | no_params!(); - | ------------ in this macro invocation - | - = note: this error originates in the macro `no_params` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 14 previous errors - diff --git a/tests/ui/macros/macro-metavar-expr-concat/repetitions.rs b/tests/ui/macros/macro-metavar-expr-concat/repetitions.rs deleted file mode 100644 index 52a7d5cd8a7..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/repetitions.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![feature(macro_metavar_expr_concat)] - -macro_rules! one_rep { - ( $($a:ident)* ) => { - $( - const ${concat($a, Z)}: i32 = 3; - )* - }; -} - -macro_rules! issue_128346 { - ( $($a:ident)* ) => { - A( - const ${concat($a, Z)}: i32 = 3; - //~^ ERROR invalid syntax - )* - }; -} - -macro_rules! issue_131393 { - ($t:ident $($en:ident)?) => { - read::<${concat($t, $en)}>() - //~^ ERROR invalid syntax - //~| ERROR invalid syntax - } -} - -fn main() { - one_rep!(A B C); - assert_eq!(AZ, 3); - assert_eq!(BZ, 3); - assert_eq!(CZ, 3); - issue_128346!(A B C); - issue_131393!(u8); - issue_131393!(u16 le); -} diff --git a/tests/ui/macros/macro-metavar-expr-concat/repetitions.stderr b/tests/ui/macros/macro-metavar-expr-concat/repetitions.stderr deleted file mode 100644 index c3006c4be5d..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/repetitions.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: invalid syntax - --> $DIR/repetitions.rs:14:20 - | -LL | const ${concat($a, Z)}: i32 = 3; - | ^^^^^^^^^^^^^^^ - -error: invalid syntax - --> $DIR/repetitions.rs:22:17 - | -LL | read::<${concat($t, $en)}>() - | ^^^^^^^^^^^^^^^^^ - -error: invalid syntax - --> $DIR/repetitions.rs:22:17 - | -LL | read::<${concat($t, $en)}>() - | ^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs b/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs deleted file mode 100644 index 7673bd3200f..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs +++ /dev/null @@ -1,168 +0,0 @@ -#![feature(macro_metavar_expr_concat)] - -macro_rules! wrong_concat_declarations { - ($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($ident, 'b')}: () = (); - //~^ ERROR expected identifier or string literal - let ${concat($ident, 1)}: () = (); - //~^ 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() { - wrong_concat_declarations!(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'); -} diff --git a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr b/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr deleted file mode 100644 index 2de6d2b3ce3..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr +++ /dev/null @@ -1,284 +0,0 @@ -error: expected identifier or string literal - --> $DIR/syntax-errors.rs:5:10 - | -LL | ${concat()} - | ^^^^^^^^^^ - -error: `concat` must have at least two elements - --> $DIR/syntax-errors.rs:8:11 - | -LL | ${concat(aaaa)} - | ^^^^^^ - -error: expected identifier or string literal - --> $DIR/syntax-errors.rs:11:10 - | -LL | ${concat(aaaa,)} - | ^^^^^^^^^^^^^^^ - -error: expected comma - --> $DIR/syntax-errors.rs:16:10 - | -LL | ${concat(aaaa aaaa)} - | ^^^^^^^^^^^^^^^^^^^ - -error: `concat` must have at least two elements - --> $DIR/syntax-errors.rs:19:11 - | -LL | ${concat($ex)} - | ^^^^^^ - -error: expected comma - --> $DIR/syntax-errors.rs:25:10 - | -LL | ${concat($ex, aaaa 123)} - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: expected identifier or string literal - --> $DIR/syntax-errors.rs:28:10 - | -LL | ${concat($ex, aaaa,)} - | ^^^^^^^^^^^^^^^^^^^^ - -error: expected identifier or string literal - --> $DIR/syntax-errors.rs:88:26 - | -LL | let ${concat(_a, 'b')}: () = (); - | ^^^ - -error: expected identifier or string literal - --> $DIR/syntax-errors.rs:91:26 - | -LL | let ${concat(_a, 1)}: () = (); - | ^ - -error: expected identifier or string literal - --> $DIR/syntax-errors.rs:94:30 - | -LL | let ${concat($ident, 'b')}: () = (); - | ^^^ - -error: expected identifier or string literal - --> $DIR/syntax-errors.rs:96:30 - | -LL | let ${concat($ident, 1)}: () = (); - | ^ - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:22:19 - | -LL | ${concat($ex, aaaa)} - | ^^ - | - = note: currently only string literals are supported - -error: variable `foo` is not recognized in meta-variable expression - --> $DIR/syntax-errors.rs:35:30 - | -LL | const ${concat(FOO, $foo)}: i32 = 2; - | ^^^ - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:42:14 - | -LL | let ${concat("1", $ident)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^ -... -LL | starting_number!(_abc); - | ---------------------- in this macro invocation - | - = note: this error originates in the macro `starting_number` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:55:14 - | -LL | let ${concat("\u{00BD}", $ident)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | starting_invalid_unicode!(_abc); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `starting_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:74:14 - | -LL | let ${concat($ident, "\u{00BD}")}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | ending_invalid_unicode!(_abc); - | ----------------------------- in this macro invocation - | - = note: this error originates in the macro `ending_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected pattern, found `$` - --> $DIR/syntax-errors.rs:88:13 - | -LL | let ${concat(_a, 'b')}: () = (); - | ^ expected pattern -... -LL | unsupported_literals!(_abc); - | --------------------------- in this macro invocation - | - = note: this error originates in the macro `unsupported_literals` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:81:14 - | -LL | let ${concat("", "")}: () = (); - | ^^^^^^^^^^^^^^^^ -... -LL | empty!(); - | -------- in this macro invocation - | - = note: this error originates in the macro `empty` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("\u{00BD}"); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("\x41"); - | --------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("🤷"); - | ------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("d[-_-]b"); - | ------------------------------ in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("-1"); - | ------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("1.0"); - | -------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("'1'"); - | -------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:127:31 - | -LL | const ${concat(_foo, $tt)}: () = (); - | ^^ - | - = note: currently only string literals are supported - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:127:31 - | -LL | const ${concat(_foo, $tt)}: () = (); - | ^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/syntax-errors.rs:127:31 - | -LL | const ${concat(_foo, $tt)}: () = (); - | ^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 33 previous errors - diff --git a/tests/ui/macros/macro-metavar-expr-concat/unicode-expansion.rs b/tests/ui/macros/macro-metavar-expr-concat/unicode-expansion.rs deleted file mode 100644 index 4eeb2384deb..00000000000 --- a/tests/ui/macros/macro-metavar-expr-concat/unicode-expansion.rs +++ /dev/null @@ -1,19 +0,0 @@ -//@ run-pass - -#![feature(macro_metavar_expr_concat)] - -macro_rules! turn_to_page { - ($ident:ident, $literal:literal, $tt:tt) => { - const ${concat("Ḧ", $ident)}: i32 = 394; - const ${concat("Ḧ", $literal)}: i32 = 394; - const ${concat("Ḧ", $tt)}: i32 = 394; - }; -} - -fn main() { - turn_to_page!(P1, "Ṕ2", Ṕ); - assert_eq!(ḦṔ, 394); - assert_eq!(ḦP1, 394); - assert_eq!(ḦṔ2, 394); - -} diff --git a/tests/ui/macros/metavar-expressions/concat-allowed-operations.rs b/tests/ui/macros/metavar-expressions/concat-allowed-operations.rs new file mode 100644 index 00000000000..695a752fe17 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-allowed-operations.rs @@ -0,0 +1,115 @@ +//@ run-pass + +#![allow(dead_code, non_camel_case_types, non_upper_case_globals, unused_variables)] +#![feature(macro_metavar_expr_concat)] + +macro_rules! create_things { + ($lhs:ident) => { + struct ${concat($lhs, _separated_idents_in_a_struct)} { + foo: i32, + ${concat($lhs, _separated_idents_in_a_field)}: i32, + } + + mod ${concat($lhs, _separated_idents_in_a_module)} { + pub const FOO: () = (); + } + + fn ${concat($lhs, _separated_idents_in_a_fn)}() {} + }; +} + +macro_rules! many_idents { + ($a:ident, $c:ident) => { + const ${concat($a, B, $c, D)}: i32 = 1; + }; +} + +macro_rules! valid_tts { + ($_0:tt, $_1:tt) => { + const ${concat($_0, $_1)}: i32 = 1; + } +} + +macro_rules! without_dollar_sign_is_an_ident { + ($ident:ident) => { + const ${concat(VAR, ident)}: i32 = 1; + const ${concat(VAR, $ident)}: i32 = 2; + }; +} + +macro_rules! combinations { + ($ident:ident, $literal:literal, $tt_ident:tt, $tt_literal:tt) => {{ + // tt ident + let ${concat($tt_ident, b)} = (); + let ${concat($tt_ident, _b)} = (); + let ${concat($tt_ident, "b")} = (); + let ${concat($tt_ident, $tt_ident)} = (); + let ${concat($tt_ident, $tt_literal)} = (); + let ${concat($tt_ident, $ident)} = (); + let ${concat($tt_ident, $literal)} = (); + // tt literal + let ${concat($tt_literal, b)} = (); + let ${concat($tt_literal, _b)} = (); + let ${concat($tt_literal, "b")} = (); + let ${concat($tt_literal, $tt_ident)} = (); + let ${concat($tt_literal, $tt_literal)} = (); + let ${concat($tt_literal, $ident)} = (); + let ${concat($tt_literal, $literal)} = (); + + // ident (adhoc) + let ${concat(_b, b)} = (); + let ${concat(_b, _b)} = (); + let ${concat(_b, "b")} = (); + let ${concat(_b, $tt_ident)} = (); + let ${concat(_b, $tt_literal)} = (); + let ${concat(_b, $ident)} = (); + let ${concat(_b, $literal)} = (); + // ident (param) + let ${concat($ident, b)} = (); + let ${concat($ident, _b)} = (); + let ${concat($ident, "b")} = (); + let ${concat($ident, $tt_ident)} = (); + let ${concat($ident, $tt_literal)} = (); + let ${concat($ident, $ident)} = (); + let ${concat($ident, $literal)} = (); + + // literal (adhoc) + let ${concat("a", b)} = (); + let ${concat("a", _b)} = (); + let ${concat("a", "b")} = (); + let ${concat("a", $tt_ident)} = (); + let ${concat("a", $tt_literal)} = (); + let ${concat("a", $ident)} = (); + let ${concat("a", $literal)} = (); + // literal (param) + let ${concat($literal, b)} = (); + let ${concat($literal, _b)} = (); + let ${concat($literal, "b")} = (); + let ${concat($literal, $tt_ident)} = (); + let ${concat($literal, $tt_literal)} = (); + let ${concat($literal, $ident)} = (); + let ${concat($literal, $literal)} = (); + }}; +} + +fn main() { + create_things!(behold); + behold_separated_idents_in_a_fn(); + let _ = behold_separated_idents_in_a_module::FOO; + let _ = behold_separated_idents_in_a_struct { + foo: 1, + behold_separated_idents_in_a_field: 2, + }; + + many_idents!(A, C); + assert_eq!(ABCD, 1); + + valid_tts!(X, YZ); + assert_eq!(XYZ, 1); + + without_dollar_sign_is_an_ident!(_123); + assert_eq!(VARident, 1); + assert_eq!(VAR_123, 2); + + combinations!(_hello, "a", b, "b"); +} diff --git a/tests/ui/macros/metavar-expressions/concat-hygiene.rs b/tests/ui/macros/metavar-expressions/concat-hygiene.rs new file mode 100644 index 00000000000..24b0e36498a --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-hygiene.rs @@ -0,0 +1,13 @@ +#![feature(macro_metavar_expr_concat)] + +macro_rules! join { + ($lhs:ident, $rhs:ident) => { + ${concat($lhs, $rhs)} + //~^ ERROR cannot find value `abcdef` in this scope + }; +} + +fn main() { + let abcdef = 1; + let _another = join!(abc, def); +} diff --git a/tests/ui/macros/metavar-expressions/concat-hygiene.stderr b/tests/ui/macros/metavar-expressions/concat-hygiene.stderr new file mode 100644 index 00000000000..f3150d385ee --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-hygiene.stderr @@ -0,0 +1,14 @@ +error[E0425]: cannot find value `abcdef` in this scope + --> $DIR/concat-hygiene.rs:5:10 + | +LL | ${concat($lhs, $rhs)} + | ^^^^^^^^^^^^^^^^^^^^ not found in this scope +... +LL | let _another = join!(abc, def); + | --------------- in this macro invocation + | + = note: this error originates in the macro `join` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/macros/metavar-expressions/concat-raw-identifiers.rs b/tests/ui/macros/metavar-expressions/concat-raw-identifiers.rs new file mode 100644 index 00000000000..b1cb2141cc4 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-raw-identifiers.rs @@ -0,0 +1,81 @@ +#![feature(macro_metavar_expr_concat)] + +macro_rules! idents_01 { + ($rhs:ident) => { + let ${concat(abc, $rhs)}: () = (); + //~^ ERROR `${concat(..)}` currently does not support raw identifiers + }; +} + +macro_rules! idents_10 { + ($lhs:ident) => { + let ${concat($lhs, abc)}: () = (); + //~^ ERROR `${concat(..)}` currently does not support raw identifiers + }; +} + +macro_rules! idents_11 { + ($lhs:ident, $rhs:ident) => { + let ${concat($lhs, $rhs)}: () = (); + //~^ ERROR `${concat(..)}` currently does not support raw identifiers + //~| ERROR `${concat(..)}` currently does not support raw identifiers + //~| ERROR `${concat(..)}` currently does not support raw identifiers + }; +} + +macro_rules! no_params { + () => { + let ${concat(r#abc, abc)}: () = (); + //~^ ERROR expected identifier or string literal + //~| ERROR expected pattern, found `$` + + let ${concat(abc, r#abc)}: () = (); + //~^ ERROR expected identifier or string literal + + let ${concat(r#abc, r#abc)}: () = (); + //~^ ERROR expected identifier or string literal + }; +} + +macro_rules! tts_01 { + ($rhs:tt) => { + let ${concat(abc, $rhs)}: () = (); + //~^ ERROR `${concat(..)}` currently does not support raw identifiers + }; +} + +macro_rules! tts_10 { + ($lhs:tt) => { + let ${concat($lhs, abc)}: () = (); + //~^ ERROR `${concat(..)}` currently does not support raw identifiers + }; +} + +macro_rules! tts_11 { + ($lhs:tt, $rhs:tt) => { + let ${concat($lhs, $rhs)}: () = (); + //~^ ERROR `${concat(..)}` currently does not support raw identifiers + //~| ERROR `${concat(..)}` currently does not support raw identifiers + //~| ERROR `${concat(..)}` currently does not support raw identifiers + }; +} + +fn main() { + idents_01!(r#_c); + + idents_10!(r#_c); + + idents_11!(r#_c, d); + idents_11!(_e, r#f); + idents_11!(r#_g, r#h); + + tts_01!(r#_c); + + tts_10!(r#_c); + + tts_11!(r#_c, d); + tts_11!(_e, r#f); + tts_11!(r#_g, r#h); + + no_params!(); +} diff --git a/tests/ui/macros/metavar-expressions/concat-raw-identifiers.stderr b/tests/ui/macros/metavar-expressions/concat-raw-identifiers.stderr new file mode 100644 index 00000000000..7abab6a5103 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-raw-identifiers.stderr @@ -0,0 +1,95 @@ +error: expected identifier or string literal + --> $DIR/concat-raw-identifiers.rs:28:22 + | +LL | let ${concat(r#abc, abc)}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-raw-identifiers.rs:32:27 + | +LL | let ${concat(abc, r#abc)}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-raw-identifiers.rs:35:22 + | +LL | let ${concat(r#abc, r#abc)}: () = (); + | ^^^^^ + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:5:28 + | +LL | let ${concat(abc, $rhs)}: () = (); + | ^^^ + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:12:23 + | +LL | let ${concat($lhs, abc)}: () = (); + | ^^^ + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:19:23 + | +LL | let ${concat($lhs, $rhs)}: () = (); + | ^^^ + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:19:29 + | +LL | let ${concat($lhs, $rhs)}: () = (); + | ^^^ + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:19:23 + | +LL | let ${concat($lhs, $rhs)}: () = (); + | ^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:42:28 + | +LL | let ${concat(abc, $rhs)}: () = (); + | ^^^ + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:49:23 + | +LL | let ${concat($lhs, abc)}: () = (); + | ^^^ + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:56:23 + | +LL | let ${concat($lhs, $rhs)}: () = (); + | ^^^ + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:56:29 + | +LL | let ${concat($lhs, $rhs)}: () = (); + | ^^^ + +error: `${concat(..)}` currently does not support raw identifiers + --> $DIR/concat-raw-identifiers.rs:56:23 + | +LL | let ${concat($lhs, $rhs)}: () = (); + | ^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: expected pattern, found `$` + --> $DIR/concat-raw-identifiers.rs:28:13 + | +LL | let ${concat(r#abc, abc)}: () = (); + | ^ expected pattern +... +LL | no_params!(); + | ------------ in this macro invocation + | + = note: this error originates in the macro `no_params` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 14 previous errors + diff --git a/tests/ui/macros/metavar-expressions/concat-repetitions.rs b/tests/ui/macros/metavar-expressions/concat-repetitions.rs new file mode 100644 index 00000000000..52a7d5cd8a7 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-repetitions.rs @@ -0,0 +1,36 @@ +#![feature(macro_metavar_expr_concat)] + +macro_rules! one_rep { + ( $($a:ident)* ) => { + $( + const ${concat($a, Z)}: i32 = 3; + )* + }; +} + +macro_rules! issue_128346 { + ( $($a:ident)* ) => { + A( + const ${concat($a, Z)}: i32 = 3; + //~^ ERROR invalid syntax + )* + }; +} + +macro_rules! issue_131393 { + ($t:ident $($en:ident)?) => { + read::<${concat($t, $en)}>() + //~^ ERROR invalid syntax + //~| ERROR invalid syntax + } +} + +fn main() { + one_rep!(A B C); + assert_eq!(AZ, 3); + assert_eq!(BZ, 3); + assert_eq!(CZ, 3); + issue_128346!(A B C); + issue_131393!(u8); + issue_131393!(u16 le); +} diff --git a/tests/ui/macros/metavar-expressions/concat-repetitions.stderr b/tests/ui/macros/metavar-expressions/concat-repetitions.stderr new file mode 100644 index 00000000000..18b0a90c1c8 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-repetitions.stderr @@ -0,0 +1,22 @@ +error: invalid syntax + --> $DIR/concat-repetitions.rs:14:20 + | +LL | const ${concat($a, Z)}: i32 = 3; + | ^^^^^^^^^^^^^^^ + +error: invalid syntax + --> $DIR/concat-repetitions.rs:22:17 + | +LL | read::<${concat($t, $en)}>() + | ^^^^^^^^^^^^^^^^^ + +error: invalid syntax + --> $DIR/concat-repetitions.rs:22:17 + | +LL | read::<${concat($t, $en)}>() + | ^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 3 previous errors + diff --git a/tests/ui/macros/metavar-expressions/concat-syntax-errors.rs b/tests/ui/macros/metavar-expressions/concat-syntax-errors.rs new file mode 100644 index 00000000000..7673bd3200f --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-syntax-errors.rs @@ -0,0 +1,168 @@ +#![feature(macro_metavar_expr_concat)] + +macro_rules! wrong_concat_declarations { + ($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($ident, 'b')}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat($ident, 1)}: () = (); + //~^ 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() { + wrong_concat_declarations!(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'); +} diff --git a/tests/ui/macros/metavar-expressions/concat-syntax-errors.stderr b/tests/ui/macros/metavar-expressions/concat-syntax-errors.stderr new file mode 100644 index 00000000000..3297de80186 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-syntax-errors.stderr @@ -0,0 +1,284 @@ +error: expected identifier or string literal + --> $DIR/concat-syntax-errors.rs:5:10 + | +LL | ${concat()} + | ^^^^^^^^^^ + +error: `concat` must have at least two elements + --> $DIR/concat-syntax-errors.rs:8:11 + | +LL | ${concat(aaaa)} + | ^^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-syntax-errors.rs:11:10 + | +LL | ${concat(aaaa,)} + | ^^^^^^^^^^^^^^^ + +error: expected comma + --> $DIR/concat-syntax-errors.rs:16:10 + | +LL | ${concat(aaaa aaaa)} + | ^^^^^^^^^^^^^^^^^^^ + +error: `concat` must have at least two elements + --> $DIR/concat-syntax-errors.rs:19:11 + | +LL | ${concat($ex)} + | ^^^^^^ + +error: expected comma + --> $DIR/concat-syntax-errors.rs:25:10 + | +LL | ${concat($ex, aaaa 123)} + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-syntax-errors.rs:28:10 + | +LL | ${concat($ex, aaaa,)} + | ^^^^^^^^^^^^^^^^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-syntax-errors.rs:88:26 + | +LL | let ${concat(_a, 'b')}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/concat-syntax-errors.rs:91:26 + | +LL | let ${concat(_a, 1)}: () = (); + | ^ + +error: expected identifier or string literal + --> $DIR/concat-syntax-errors.rs:94:30 + | +LL | let ${concat($ident, 'b')}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/concat-syntax-errors.rs:96:30 + | +LL | let ${concat($ident, 1)}: () = (); + | ^ + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-syntax-errors.rs:22:19 + | +LL | ${concat($ex, aaaa)} + | ^^ + | + = note: currently only string literals are supported + +error: variable `foo` is not recognized in meta-variable expression + --> $DIR/concat-syntax-errors.rs:35:30 + | +LL | const ${concat(FOO, $foo)}: i32 = 2; + | ^^^ + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:42:14 + | +LL | let ${concat("1", $ident)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^ +... +LL | starting_number!(_abc); + | ---------------------- in this macro invocation + | + = note: this error originates in the macro `starting_number` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:55:14 + | +LL | let ${concat("\u{00BD}", $ident)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | starting_invalid_unicode!(_abc); + | ------------------------------- in this macro invocation + | + = note: this error originates in the macro `starting_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:74:14 + | +LL | let ${concat($ident, "\u{00BD}")}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | ending_invalid_unicode!(_abc); + | ----------------------------- in this macro invocation + | + = note: this error originates in the macro `ending_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected pattern, found `$` + --> $DIR/concat-syntax-errors.rs:88:13 + | +LL | let ${concat(_a, 'b')}: () = (); + | ^ expected pattern +... +LL | unsupported_literals!(_abc); + | --------------------------- in this macro invocation + | + = note: this error originates in the macro `unsupported_literals` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:81:14 + | +LL | let ${concat("", "")}: () = (); + | ^^^^^^^^^^^^^^^^ +... +LL | empty!(); + | -------- in this macro invocation + | + = note: this error originates in the macro `empty` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("\u{00BD}"); + | ------------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("\x41"); + | --------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("🤷"); + | ------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("d[-_-]b"); + | ------------------------------ in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("-1"); + | ------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("1.0"); + | -------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-syntax-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("'1'"); + | -------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-syntax-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-syntax-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-syntax-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-syntax-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-syntax-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-syntax-errors.rs:127:31 + | +LL | const ${concat(_foo, $tt)}: () = (); + | ^^ + | + = note: currently only string literals are supported + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-syntax-errors.rs:127:31 + | +LL | const ${concat(_foo, $tt)}: () = (); + | ^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-syntax-errors.rs:127:31 + | +LL | const ${concat(_foo, $tt)}: () = (); + | ^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 33 previous errors + diff --git a/tests/ui/macros/metavar-expressions/concat-unicode-expansion.rs b/tests/ui/macros/metavar-expressions/concat-unicode-expansion.rs new file mode 100644 index 00000000000..4eeb2384deb --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-unicode-expansion.rs @@ -0,0 +1,19 @@ +//@ run-pass + +#![feature(macro_metavar_expr_concat)] + +macro_rules! turn_to_page { + ($ident:ident, $literal:literal, $tt:tt) => { + const ${concat("Ḧ", $ident)}: i32 = 394; + const ${concat("Ḧ", $literal)}: i32 = 394; + const ${concat("Ḧ", $tt)}: i32 = 394; + }; +} + +fn main() { + turn_to_page!(P1, "Ṕ2", Ṕ); + assert_eq!(ḦṔ, 394); + assert_eq!(ḦP1, 394); + assert_eq!(ḦṔ2, 394); + +} diff --git a/tests/ui/macros/metavar-expressions/count-and-length-are-distinct.rs b/tests/ui/macros/metavar-expressions/count-and-length-are-distinct.rs new file mode 100644 index 00000000000..8ca453273cd --- /dev/null +++ b/tests/ui/macros/metavar-expressions/count-and-length-are-distinct.rs @@ -0,0 +1,283 @@ +//@ run-pass + +#![feature(macro_metavar_expr)] + +fn main() { + macro_rules! one_nested_count_and_len { + ( $( [ $( $l:literal ),* ] ),* ) => { + [ + // outermost repetition + $( + // innermost repetition + $( + ${ignore($l)} ${index()}, ${len()}, + )* + ${count($l)}, ${index()}, ${len()}, + )* + ${count($l)}, + ] + }; + } + assert_eq!( + one_nested_count_and_len!(["foo"], ["bar", "baz"]), + [ + // # ["foo"] + + // ## innermost repetition (first iteration) + // + // `index` is 0 because this is the first innermost iteration. + // `len` is 1 because there is only one innermost repetition, "foo". + 0, 1, + // ## outermost repetition (first iteration) + // + // `count` is 1 because of "foo", i,e, `$l` has only one repetition, + // `index` is 0 because this is the first outermost iteration. + // `len` is 2 because there are 2 outermost repetitions, ["foo"] and ["bar", "baz"] + 1, 0, 2, + // # ["bar", "baz"] + + // ## innermost repetition (first iteration) + // + // `index` is 0 because this is the first innermost iteration + // `len` is 2 because there are repetitions, "bar" and "baz" + 0, 2, + // ## innermost repetition (second iteration) + // + // `index` is 1 because this is the second innermost iteration + // `len` is 2 because there are repetitions, "bar" and "baz" + 1, 2, + // ## outermost repetition (second iteration) + // + // `count` is 2 because of "bar" and "baz", i,e, `$l` has two repetitions, + // `index` is 1 because this is the second outermost iteration + // `len` is 2 because there are 2 outermost repetitions, ["foo"] and ["bar", "baz"] + 2, 1, 2, + // # last count + + // Because there are a total of 3 repetitions of `$l`, "foo", "bar" and "baz" + 3, + ] + ); + + // Based on the above explanation, the following macros should be straightforward + + // Grouped from the outermost to the innermost + macro_rules! three_nested_count { + ( $( { $( [ $( ( $( $i:ident )* ) )* ] )* } )* ) => { + &[ + $( $( $( + &[ + ${ignore($i)} ${count($i, 0)}, + ][..], + )* )* )* + + $( $( + &[ + ${ignore($i)} ${count($i, 0)}, + ${ignore($i)} ${count($i, 1)}, + ][..], + )* )* + + $( + &[ + ${ignore($i)} ${count($i, 0)}, + ${ignore($i)} ${count($i, 1)}, + ${ignore($i)} ${count($i, 2)}, + ][..], + )* + + &[ + ${count($i, 0)}, + ${count($i, 1)}, + ${count($i, 2)}, + ${count($i, 3)}, + ][..] + ][..] + } + } + assert_eq!( + three_nested_count!( + { + [ (a b c) (d e f) ] + [ (g h) (i j k l m) ] + [ (n) ] + } + { + [ (o) (p q) (r s) ] + [ (t u v w x y z) ] + } + ), + &[ + // a b c + &[3][..], + // d e f + &[3][..], + // g h + &[2][..], + // i j k l m + &[5][..], + // n + &[1][..], + // o + &[1][..], + // p q + &[2][..], + // r s + &[2][..], + // t u v w x y z + &[7][..], + // (a b c) (d e f) + &[6, 2][..], + // (g h) (i j k l m) + &[7, 2][..], + // (n) + &[1, 1][..], + // (o) (p q) (r s) + &[5, 3][..], + // (t u v w x y z) + &[7, 1][..], + // [ (a b c) (d e f) ] + // [ (g h) (i j k l m) ] + // [ (n) ] + &[14, 5, 3][..], + // [ (o) (p q) (r s) ] + // [ (t u v w x y z) ] + &[12, 4, 2][..], + // { + // [ (a b c) (d e f) ] + // [ (g h) (i j k l m) ] + // [ (n) ] + // } + // { + // [ (o) (p q) (r s) ] + // [ (t u v w x y z) ] + // } + &[26, 9, 5, 2][..] + ][..] + ); + + // Grouped from the outermost to the innermost + macro_rules! three_nested_len { + ( $( { $( [ $( ( $( $i:ident )* ) )* ] )* } )* ) => { + &[ + $( $( $( $( + &[ + ${ignore($i)} ${len(3)}, + ${ignore($i)} ${len(2)}, + ${ignore($i)} ${len(1)}, + ${ignore($i)} ${len(0)}, + ][..], + )* )* )* )* + + $( $( $( + &[ + ${ignore($i)} ${len(2)}, + ${ignore($i)} ${len(1)}, + ${ignore($i)} ${len(0)}, + ][..], + )* )* )* + + $( $( + &[ + ${ignore($i)} ${len(1)}, + ${ignore($i)} ${len(0)}, + ][..], + )* )* + + $( + &[ + ${ignore($i)} ${len(0)}, + ][..], + )* + ][..] + } + } + assert_eq!( + three_nested_len!( + { + [ (a b c) (d e f) ] + [ (g h) (i j k l m) ] + [ (n) ] + } + { + [ (o) (p q) (r s) ] + [ (t u v w x y z) ] + } + ), + &[ + // a b c + &[2, 3, 2, 3][..], + &[2, 3, 2, 3][..], + &[2, 3, 2, 3][..], + // d e f + &[2, 3, 2, 3][..], + &[2, 3, 2, 3][..], + &[2, 3, 2, 3][..], + // g h + &[2, 3, 2, 2][..], + &[2, 3, 2, 2][..], + // i j k l m + &[2, 3, 2, 5][..], + &[2, 3, 2, 5][..], + &[2, 3, 2, 5][..], + &[2, 3, 2, 5][..], + &[2, 3, 2, 5][..], + // n + &[2, 3, 1, 1][..], + // o + &[2, 2, 3, 1][..], + // p q + &[2, 2, 3, 2][..], + &[2, 2, 3, 2][..], + // r s + &[2, 2, 3, 2][..], + &[2, 2, 3, 2][..], + // t u v w x y z + &[2, 2, 1, 7][..], + &[2, 2, 1, 7][..], + &[2, 2, 1, 7][..], + &[2, 2, 1, 7][..], + &[2, 2, 1, 7][..], + &[2, 2, 1, 7][..], + &[2, 2, 1, 7][..], + // (a b c) (d e f) + &[2, 3, 2][..], + &[2, 3, 2][..], + // (g h) (i j k l m) + &[2, 3, 2][..], + &[2, 3, 2][..], + // (n) + &[2, 3, 1][..], + // (o) (p q) (r s) + &[2, 2, 3][..], + &[2, 2, 3][..], + &[2, 2, 3][..], + // (t u v w x y z) + &[2, 2, 1][..], + // [ (a b c) (d e f) ] + // [ (g h) (i j k l m) ] + // [ (n) ] + &[2, 3][..], + &[2, 3][..], + &[2, 3,][..], + // [ (o) (p q) (r s) ] + // [ (t u v w x y z) ] + &[2, 2][..], + &[2, 2][..], + // { + // [ (a b c) (d e f) ] + // [ (g h) (i j k l m) ] + // [ (n) ] + // } + // { + // [ (o) (p q) (r s) ] + // [ (t u v w x y z) ] + // } + &[2][..], + &[2][..] + ][..] + ); + + // It is possible to say, to some degree, that count is an "amalgamation" of len (see + // each len line result and compare them with the count results) +} diff --git a/tests/ui/macros/metavar-expressions/count-empty-index-arg.rs b/tests/ui/macros/metavar-expressions/count-empty-index-arg.rs new file mode 100644 index 00000000000..69880ee7fa9 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/count-empty-index-arg.rs @@ -0,0 +1,16 @@ +// Issue: https://github.com/rust-lang/rust/issues/111904 +// Ensure that a trailing `,` is not interpreted as a `0`. + +#![feature(macro_metavar_expr)] + +macro_rules! foo { + ( $( $($t:ident),* );* ) => { ${count($t,)} } + //~^ ERROR `count` followed by a comma must have an associated + //~| ERROR expected expression, found `$` +} + +fn test() { + foo!(a, a; b, b); +} + +fn main() {} diff --git a/tests/ui/macros/metavar-expressions/count-empty-index-arg.stderr b/tests/ui/macros/metavar-expressions/count-empty-index-arg.stderr new file mode 100644 index 00000000000..e1f9d020b7f --- /dev/null +++ b/tests/ui/macros/metavar-expressions/count-empty-index-arg.stderr @@ -0,0 +1,19 @@ +error: `count` followed by a comma must have an associated index indicating its depth + --> $DIR/count-empty-index-arg.rs:7:37 + | +LL | ( $( $($t:ident),* );* ) => { ${count($t,)} } + | ^^^^^ + +error: expected expression, found `$` + --> $DIR/count-empty-index-arg.rs:7:35 + | +LL | ( $( $($t:ident),* );* ) => { ${count($t,)} } + | ^ expected expression +... +LL | foo!(a, a; b, b); + | ---------------- in this macro invocation + | + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + diff --git a/tests/ui/macros/metavar-expressions/dollar-dollar-has-correct-behavior.rs b/tests/ui/macros/metavar-expressions/dollar-dollar-has-correct-behavior.rs new file mode 100644 index 00000000000..9b8e3216a68 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/dollar-dollar-has-correct-behavior.rs @@ -0,0 +1,28 @@ +//@ run-pass + +#![feature(macro_metavar_expr)] + +macro_rules! nested { + ( $a:ident ) => { + macro_rules! $a { + ( $$( $b:ident ),* ) => { + $$( + macro_rules! $b { + ( $$$$( $c:ident ),* ) => { + $$$$( + fn $c() -> &'static str { stringify!($c) } + ),* + }; + } + )* + }; + } + }; +} + +fn main() { + nested!(a); + a!(b); + b!(c); + assert_eq!(c(), "c"); +} diff --git a/tests/ui/macros/metavar-expressions/feature-gate-macro_metavar_expr.rs b/tests/ui/macros/metavar-expressions/feature-gate-macro_metavar_expr.rs new file mode 100644 index 00000000000..51445221c57 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/feature-gate-macro_metavar_expr.rs @@ -0,0 +1,147 @@ +//@ run-pass + +#![feature(macro_metavar_expr)] + +/// Count the number of idents in a macro repetition. +macro_rules! count_idents { + ( $( $i:ident ),* ) => { + ${count($i)} + }; +} + +/// Count the number of idents in a 2-dimensional macro repetition. +macro_rules! count_idents_2 { + ( $( [ $( $i:ident ),* ] ),* ) => { + ${count($i)} + }; +} + +/// Mostly counts the number of OUTER-MOST repetitions +macro_rules! count_depth_limits { + ( $( { $( [ $( $outer:ident : ( $( $inner:ident )* ) )* ] )* } )* ) => { + ( + ( + ${count($inner)}, + ${count($inner, 0)}, + ${count($inner, 1)}, + ${count($inner, 2)}, + ${count($inner, 3)}, + ), + ( + ${count($outer)}, + ${count($outer, 0)}, + ${count($outer, 1)}, + ${count($outer, 2)}, + ), + ) + }; +} + +/// Produce (index, len) pairs for literals in a macro repetition. +/// The literal is not included in the output, so this macro uses the +/// `ignore` meta-variable expression to create a non-expanding +/// repetition binding. +macro_rules! enumerate_literals { + ( $( ($l:stmt) ),* ) => { + [$( ${ignore($l)} (${index()}, ${len()}) ),*] + }; +} + +/// Produce index and len tuples for literals in a 2-dimensional +/// macro repetition. +macro_rules! enumerate_literals_2 { + ( $( [ $( ($l:literal) ),* ] ),* ) => { + [ + $( + $( + ( + ${index(1)}, + ${len(1)}, + ${index(0)}, + ${len(0)}, + $l + ), + )* + )* + ] + }; +} + +/// Generate macros that count idents and then add a constant number +/// to the count. +/// +/// This macro uses dollar escaping to make it unambiguous as to which +/// macro the repetition belongs to. +macro_rules! make_count_adders { + ( $( $i:ident, $b:literal );* ) => { + $( + macro_rules! $i { + ( $$( $$j:ident ),* ) => { + $b + $${count($j)} + }; + } + )* + }; +} + +make_count_adders! { plus_one, 1; plus_five, 5 } + +/// Generate a macro that allows selection of a particular literal +/// from a sequence of inputs by their identifier. +/// +/// This macro uses dollar escaping to make it unambiguous as to which +/// macro the repetition belongs to, and to allow expansion of an +/// identifier the name of which is not known in the definition +/// of `make_picker`. +macro_rules! make_picker { + ( $m:ident => $( $i:ident ),* ; $p:ident ) => { + macro_rules! $m { + ( $( $$ $i:literal ),* ) => { + $$ $p + }; + } + }; +} + +make_picker!(first => a, b; a); + +make_picker!(second => a, b; b); + +fn main() { + assert_eq!(count_idents!(a, b, c), 3); + assert_eq!(count_idents_2!([a, b, c], [d, e], [f]), 6); + assert_eq!( + count_depth_limits! { + { + [ A: (a b c) D: (d e f) ] + [ G: (g h) I: (i j k l m) ] + [ N: (n) ] + } + { + [ O: (o) P: (p q) R: (r s) ] + [ T: (t u v w x y z) ] + } + }, + ((26, 26, 9, 5, 2), (9, 9, 5, 2)) + ); + assert_eq!(enumerate_literals![("foo"), ("bar")], [(0, 2), (1, 2)]); + assert_eq!( + enumerate_literals_2![ + [("foo"), ("bar"), ("baz")], + [("qux"), ("quux"), ("quuz"), ("xyzzy")] + ], + [ + (0, 2, 0, 3, "foo"), + (0, 2, 1, 3, "bar"), + (0, 2, 2, 3, "baz"), + (1, 2, 0, 4, "qux"), + (1, 2, 1, 4, "quux"), + (1, 2, 2, 4, "quuz"), + (1, 2, 3, 4, "xyzzy"), + ] + ); + assert_eq!(plus_one!(a, b, c), 4); + assert_eq!(plus_five!(a, b), 7); + assert_eq!(first!(1, 2), 1); + assert_eq!(second!(1, 2), 2); +} diff --git a/tests/ui/macros/metavar-expressions/macro-expansion.rs b/tests/ui/macros/metavar-expressions/macro-expansion.rs new file mode 100644 index 00000000000..1d34275874b --- /dev/null +++ b/tests/ui/macros/metavar-expressions/macro-expansion.rs @@ -0,0 +1,102 @@ +//@ run-pass + +#![feature(macro_metavar_expr)] + +#[derive(Debug)] +struct Example<'a> { + _indexes: &'a [(u32, u32)], + _counts: &'a [u32], + _nested: Vec>, +} + +macro_rules! example { + ( $( [ $( ( $( $x:ident )* ) )* ] )* ) => { + Example { + _indexes: &[], + _counts: &[${count($x, 0)}, ${count($x, 1)}, ${count($x, 2)}], + _nested: vec![ + $( + Example { + _indexes: &[(${index()}, ${len()})], + _counts: &[${count($x, 0)}, ${count($x, 1)}], + _nested: vec![ + $( + Example { + _indexes: &[(${index(1)}, ${len(1)}), (${index()}, ${len()})], + _counts: &[${count($x)}], + _nested: vec![ + $( + Example { + _indexes: &[ + (${index(2)}, ${len(2)}), + (${index(1)}, ${len(1)}), + (${index()}, ${len()}) + ], + _counts: &[], + _nested: vec![], + ${ignore($x)} + } + ),* + ] + } + ),* + ] + } + ),* + ] + } + }; +} + +static EXPECTED: &str = concat!( + "Example { _indexes: [], _counts: [13, 4, 2], _nested: [", + concat!( + "Example { _indexes: [(0, 2)], _counts: [10, 3], _nested: [", + concat!( + "Example { _indexes: [(0, 2), (0, 3)], _counts: [4], _nested: [", + concat!( + "Example { _indexes: [(0, 2), (0, 3), (0, 4)], _counts: [], _nested: [] }, ", + "Example { _indexes: [(0, 2), (0, 3), (1, 4)], _counts: [], _nested: [] }, ", + "Example { _indexes: [(0, 2), (0, 3), (2, 4)], _counts: [], _nested: [] }, ", + "Example { _indexes: [(0, 2), (0, 3), (3, 4)], _counts: [], _nested: [] }", + ), + "] }, ", + "Example { _indexes: [(0, 2), (1, 3)], _counts: [4], _nested: [", + concat!( + "Example { _indexes: [(0, 2), (1, 3), (0, 4)], _counts: [], _nested: [] }, ", + "Example { _indexes: [(0, 2), (1, 3), (1, 4)], _counts: [], _nested: [] }, ", + "Example { _indexes: [(0, 2), (1, 3), (2, 4)], _counts: [], _nested: [] }, ", + "Example { _indexes: [(0, 2), (1, 3), (3, 4)], _counts: [], _nested: [] }", + ), + "] }, ", + "Example { _indexes: [(0, 2), (2, 3)], _counts: [2], _nested: [", + concat!( + "Example { _indexes: [(0, 2), (2, 3), (0, 2)], _counts: [], _nested: [] }, ", + "Example { _indexes: [(0, 2), (2, 3), (1, 2)], _counts: [], _nested: [] }", + ), + "] }", + ), + "] }, ", + "Example { _indexes: [(1, 2)], _counts: [3, 1], _nested: [", + concat!( + "Example { _indexes: [(1, 2), (0, 1)], _counts: [3], _nested: [", + concat!( + "Example { _indexes: [(1, 2), (0, 1), (0, 3)], _counts: [], _nested: [] }, ", + "Example { _indexes: [(1, 2), (0, 1), (1, 3)], _counts: [], _nested: [] }, ", + "Example { _indexes: [(1, 2), (0, 1), (2, 3)], _counts: [], _nested: [] }", + ), + "] }", + ), + "] }", + ), + "] }", +); + +fn main() { + let e = example! { + [ ( A B C D ) ( E F G H ) ( I J ) ] + [ ( K L M ) ] + }; + let debug = format!("{:?}", e); + assert_eq!(debug, EXPECTED); +} diff --git a/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.rs b/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.rs new file mode 100644 index 00000000000..0caa3ea89e4 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.rs @@ -0,0 +1,43 @@ +#![feature(macro_metavar_expr)] + +macro_rules! a { + ( $( { $( [ $( ( $( $foo:ident )* ) )* ] )* } )* ) => { + ( + ${count($foo, 0)}, + ${count($foo, 10)}, + //~^ ERROR depth parameter of meta-variable expression `count` must be less than 4 + ) + }; +} + +macro_rules! b { + ( $( { $( [ $( $foo:ident )* ] )* } )* ) => { + ( + $( $( $( + ${ignore($foo)} + ${index(0)}, + ${index(10)}, + //~^ ERROR depth parameter of meta-variable expression `index` must be less than 3 + )* )* )* + ) + }; +} + +macro_rules! c { + ( $( { $( $foo:ident )* } )* ) => { + ( + $( $( + ${ignore($foo)} + ${len(0)} + ${len(10)} + //~^ ERROR depth parameter of meta-variable expression `len` must be less than 2 + )* )* + ) + }; +} + +fn main() { + a!( { [ (a) ] [ (b c) ] } ); + b!( { [ a b ] } ); + c!({ a }); +} diff --git a/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.stderr b/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.stderr new file mode 100644 index 00000000000..0b441cad083 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/out-of-bounds-arguments.stderr @@ -0,0 +1,20 @@ +error: depth parameter of meta-variable expression `count` must be less than 4 + --> $DIR/out-of-bounds-arguments.rs:7:14 + | +LL | ${count($foo, 10)}, + | ^^^^^^^^^^^^^^^^^ + +error: depth parameter of meta-variable expression `index` must be less than 3 + --> $DIR/out-of-bounds-arguments.rs:19:18 + | +LL | ${index(10)}, + | ^^^^^^^^^^^ + +error: depth parameter of meta-variable expression `len` must be less than 2 + --> $DIR/out-of-bounds-arguments.rs:32:18 + | +LL | ${len(10)} + | ^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/macros/metavar-expressions/required-feature.rs b/tests/ui/macros/metavar-expressions/required-feature.rs new file mode 100644 index 00000000000..77c165e3855 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/required-feature.rs @@ -0,0 +1,43 @@ +macro_rules! count { + ( $( $e:stmt ),* ) => { + ${ count($e) } + //~^ ERROR meta-variable expressions are unstable + }; +} + +macro_rules! dollar_dollar { + () => { + macro_rules! bar { + ( $$( $$any:tt )* ) => { $$( $$any )* }; + //~^ ERROR meta-variable expressions are unstable + //~| ERROR meta-variable expressions are unstable + //~| ERROR meta-variable expressions are unstable + //~| ERROR meta-variable expressions are unstable + } + }; +} + +macro_rules! index { + ( $( $e:stmt ),* ) => { + $( ${ignore($e)} ${index()} )* + //~^ ERROR meta-variable expressions are unstable + //~| ERROR meta-variable expressions are unstable + }; +} + +macro_rules! ignore { + ( $( $i:stmt ),* ) => {{ + 0 $( + 1 ${ignore($i)} )* + //~^ ERROR meta-variable expressions are unstable + }}; +} + +macro_rules! len { + ( $( $e:stmt ),* ) => { + $( ${ignore($e)} ${len()} )* + //~^ ERROR meta-variable expressions are unstable + //~| ERROR meta-variable expressions are unstable + }; +} + +fn main() {} diff --git a/tests/ui/macros/metavar-expressions/required-feature.stderr b/tests/ui/macros/metavar-expressions/required-feature.stderr new file mode 100644 index 00000000000..f28f822a058 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/required-feature.stderr @@ -0,0 +1,103 @@ +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:3:10 + | +LL | ${ count($e) } + | ^^^^^^^^^^^^^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:11:16 + | +LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; + | ^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:11:20 + | +LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; + | ^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:11:39 + | +LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; + | ^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:11:43 + | +LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; + | ^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:22:13 + | +LL | $( ${ignore($e)} ${index()} )* + | ^^^^^^^^^^^^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:22:27 + | +LL | $( ${ignore($e)} ${index()} )* + | ^^^^^^^^^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:30:19 + | +LL | 0 $( + 1 ${ignore($i)} )* + | ^^^^^^^^^^^^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:37:13 + | +LL | $( ${ignore($e)} ${len()} )* + | ^^^^^^^^^^^^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:37:27 + | +LL | $( ${ignore($e)} ${len()} )* + | ^^^^^^^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 10 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/macros/metavar-expressions/syntax-errors.rs b/tests/ui/macros/metavar-expressions/syntax-errors.rs new file mode 100644 index 00000000000..78cede92526 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/syntax-errors.rs @@ -0,0 +1,164 @@ +#![feature(macro_metavar_expr)] + +// `curly` = Right hand side curly brackets +// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function" +// `round` = Left hand side round brackets + +macro_rules! curly__no_rhs_dollar__round { + ( $( $i:ident ),* ) => { ${ count($i) } }; +} + +macro_rules! curly__no_rhs_dollar__no_round { + ( $i:ident ) => { ${ count($i) } }; + //~^ ERROR `count` can not be placed inside the innermost repetition +} + +macro_rules! curly__rhs_dollar__no_round { + ( $i:ident ) => { ${ count($i) } }; + //~^ ERROR `count` can not be placed inside the innermost repetition +} + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__no_rhs_dollar__round { + ( $( $i:ident ),* ) => { count(i) }; + //~^ ERROR cannot find function `count` in this scope + //~| ERROR cannot find value `i` in this scope +} + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__no_rhs_dollar__no_round { + ( $i:ident ) => { count(i) }; + //~^ ERROR cannot find function `count` in this scope + //~| ERROR cannot find value `i` in this scope +} + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__rhs_dollar__round { + ( $( $i:ident ),* ) => { count($i) }; + //~^ ERROR variable `i` is still repeating at this depth +} + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__rhs_dollar__no_round { + ( $i:ident ) => { count($i) }; + //~^ ERROR cannot find function `count` in this scope +} + +// Other scenarios + +macro_rules! dollar_dollar_in_the_lhs { + ( $$ $a:ident ) => { + //~^ ERROR unexpected token: $ + }; +} + +macro_rules! extra_garbage_after_metavar { + ( $( $i:ident ),* ) => { + ${count() a b c} + //~^ ERROR unexpected token: a + //~| ERROR expected expression, found `$` + ${count($i a b c)} + //~^ ERROR unexpected token: a + ${count($i, 1 a b c)} + //~^ ERROR unexpected token: a + ${count($i) a b c} + //~^ ERROR unexpected token: a + + ${ignore($i) a b c} + //~^ ERROR unexpected token: a + ${ignore($i a b c)} + //~^ ERROR unexpected token: a + + ${index() a b c} + //~^ ERROR unexpected token: a + ${index(1 a b c)} + //~^ ERROR unexpected token: a + + ${index() a b c} + //~^ ERROR unexpected token: a + ${index(1 a b c)} + //~^ ERROR unexpected token: a + }; +} + +const IDX: usize = 1; +macro_rules! metavar_depth_is_not_literal { + ( $( $i:ident ),* ) => { ${ index(IDX) } }; + //~^ ERROR meta-variable expression depth must be a literal + //~| ERROR expected expression, found `$` +} + +macro_rules! metavar_in_the_lhs { + ( ${ len() } ) => { + //~^ ERROR unexpected token: { + //~| ERROR expected one of: `*`, `+`, or `?` + }; +} + +macro_rules! metavar_token_without_ident { + ( $( $i:ident ),* ) => { ${ ignore() } }; + //~^ ERROR meta-variable expressions must be referenced using a dollar sign + //~| ERROR expected expression +} + +macro_rules! metavar_with_literal_suffix { + ( $( $i:ident ),* ) => { ${ index(1u32) } }; + //~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions + //~| ERROR expected expression, found `$` +} + +macro_rules! metavar_without_parens { + ( $( $i:ident ),* ) => { ${ count{i} } }; + //~^ ERROR meta-variable expression parameter must be wrapped in parentheses + //~| ERROR expected expression, found `$` +} + +#[rustfmt::skip] +macro_rules! open_brackets_without_tokens { + ( $( $i:ident ),* ) => { ${ {} } }; + //~^ ERROR expected expression, found `$` + //~| ERROR expected identifier +} + +macro_rules! unknown_count_ident { + ( $( $i:ident )* ) => { + ${count(foo)} + //~^ ERROR meta-variable expressions must be referenced using a dollar sign + //~| ERROR expected expression + }; +} + +macro_rules! unknown_ignore_ident { + ( $( $i:ident )* ) => { + ${ignore(bar)} + //~^ ERROR meta-variable expressions must be referenced using a dollar sign + //~| ERROR expected expression + }; +} + +macro_rules! unknown_metavar { + ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; + //~^ ERROR unrecognized meta-variable expression + //~| ERROR expected expression +} + +fn main() { + curly__no_rhs_dollar__round!(a, b, c); + curly__no_rhs_dollar__no_round!(a); + curly__rhs_dollar__no_round!(a); + no_curly__no_rhs_dollar__round!(a, b, c); + no_curly__no_rhs_dollar__no_round!(a); + no_curly__rhs_dollar__round!(a, b, c); + no_curly__rhs_dollar__no_round!(a); + //~^ ERROR cannot find value `a` in this scope + + extra_garbage_after_metavar!(a); + metavar_depth_is_not_literal!(a); + metavar_token_without_ident!(a); + metavar_with_literal_suffix!(a); + metavar_without_parens!(a); + open_brackets_without_tokens!(a); + unknown_count_ident!(a); + unknown_ignore_ident!(a); + unknown_metavar!(a); +} diff --git a/tests/ui/macros/metavar-expressions/syntax-errors.stderr b/tests/ui/macros/metavar-expressions/syntax-errors.stderr new file mode 100644 index 00000000000..d9646760cea --- /dev/null +++ b/tests/ui/macros/metavar-expressions/syntax-errors.stderr @@ -0,0 +1,382 @@ +error: unexpected token: $ + --> $DIR/syntax-errors.rs:50:8 + | +LL | ( $$ $a:ident ) => { + | ^ + +note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions + --> $DIR/syntax-errors.rs:50:8 + | +LL | ( $$ $a:ident ) => { + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:57:19 + | +LL | ${count() a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:57:19 + | +LL | ${count() a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:60:20 + | +LL | ${count($i a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:60:20 + | +LL | ${count($i a b c)} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:62:23 + | +LL | ${count($i, 1 a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:62:23 + | +LL | ${count($i, 1 a b c)} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:64:21 + | +LL | ${count($i) a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:64:21 + | +LL | ${count($i) a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:67:22 + | +LL | ${ignore($i) a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:67:22 + | +LL | ${ignore($i) a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:69:21 + | +LL | ${ignore($i a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:69:21 + | +LL | ${ignore($i a b c)} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:72:19 + | +LL | ${index() a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:72:19 + | +LL | ${index() a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:74:19 + | +LL | ${index(1 a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:74:19 + | +LL | ${index(1 a b c)} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:77:19 + | +LL | ${index() a b c} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:77:19 + | +LL | ${index() a b c} + | ^ + +error: unexpected token: a + --> $DIR/syntax-errors.rs:79:19 + | +LL | ${index(1 a b c)} + | ^ + | +note: meta-variable expression must not have trailing tokens + --> $DIR/syntax-errors.rs:79:19 + | +LL | ${index(1 a b c)} + | ^ + +error: meta-variable expression depth must be a literal + --> $DIR/syntax-errors.rs:86:33 + | +LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; + | ^^^^^ + +error: unexpected token: { + --> $DIR/syntax-errors.rs:92:8 + | +LL | ( ${ len() } ) => { + | ^^^^^^^^^ + +note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions + --> $DIR/syntax-errors.rs:92:8 + | +LL | ( ${ len() } ) => { + | ^^^^^^^^^ + +error: expected one of: `*`, `+`, or `?` + --> $DIR/syntax-errors.rs:92:8 + | +LL | ( ${ len() } ) => { + | ^^^^^^^^^ + +error: meta-variables within meta-variable expressions must be referenced using a dollar sign + --> $DIR/syntax-errors.rs:99:33 + | +LL | ( $( $i:ident ),* ) => { ${ ignore() } }; + | ^^^^^^ + +error: only unsuffixes integer literals are supported in meta-variable expressions + --> $DIR/syntax-errors.rs:105:33 + | +LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; + | ^^^^^ + +error: meta-variable expression parameter must be wrapped in parentheses + --> $DIR/syntax-errors.rs:111:33 + | +LL | ( $( $i:ident ),* ) => { ${ count{i} } }; + | ^^^^^ + +error: meta-variables within meta-variable expressions must be referenced using a dollar sign + --> $DIR/syntax-errors.rs:125:11 + | +LL | ${count(foo)} + | ^^^^^ + +error: meta-variables within meta-variable expressions must be referenced using a dollar sign + --> $DIR/syntax-errors.rs:133:11 + | +LL | ${ignore(bar)} + | ^^^^^^ + +error: unrecognized meta-variable expression + --> $DIR/syntax-errors.rs:140:33 + | +LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; + | ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and len + +error: expected identifier or string literal + --> $DIR/syntax-errors.rs:118:33 + | +LL | ( $( $i:ident ),* ) => { ${ {} } }; + | ^^ + +error: `count` can not be placed inside the innermost repetition + --> $DIR/syntax-errors.rs:12:24 + | +LL | ( $i:ident ) => { ${ count($i) } }; + | ^^^^^^^^^^^^^ + +error: `count` can not be placed inside the innermost repetition + --> $DIR/syntax-errors.rs:17:24 + | +LL | ( $i:ident ) => { ${ count($i) } }; + | ^^^^^^^^^^^^^ + +error: variable `i` is still repeating at this depth + --> $DIR/syntax-errors.rs:37:36 + | +LL | ( $( $i:ident ),* ) => { count($i) }; + | ^^ + +error: expected expression, found `$` + --> $DIR/syntax-errors.rs:57:9 + | +LL | ${count() a b c} + | ^ expected expression +... +LL | extra_garbage_after_metavar!(a); + | ------------------------------- in this macro invocation + | + = note: this error originates in the macro `extra_garbage_after_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected expression, found `$` + --> $DIR/syntax-errors.rs:86:30 + | +LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; + | ^ expected expression +... +LL | metavar_depth_is_not_literal!(a); + | -------------------------------- in this macro invocation + | + = note: this error originates in the macro `metavar_depth_is_not_literal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected expression, found `$` + --> $DIR/syntax-errors.rs:99:30 + | +LL | ( $( $i:ident ),* ) => { ${ ignore() } }; + | ^ expected expression +... +LL | metavar_token_without_ident!(a); + | ------------------------------- in this macro invocation + | + = note: this error originates in the macro `metavar_token_without_ident` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected expression, found `$` + --> $DIR/syntax-errors.rs:105:30 + | +LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; + | ^ expected expression +... +LL | metavar_with_literal_suffix!(a); + | ------------------------------- in this macro invocation + | + = note: this error originates in the macro `metavar_with_literal_suffix` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected expression, found `$` + --> $DIR/syntax-errors.rs:111:30 + | +LL | ( $( $i:ident ),* ) => { ${ count{i} } }; + | ^ expected expression +... +LL | metavar_without_parens!(a); + | -------------------------- in this macro invocation + | + = note: this error originates in the macro `metavar_without_parens` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected expression, found `$` + --> $DIR/syntax-errors.rs:118:30 + | +LL | ( $( $i:ident ),* ) => { ${ {} } }; + | ^ expected expression +... +LL | open_brackets_without_tokens!(a); + | -------------------------------- in this macro invocation + | + = note: this error originates in the macro `open_brackets_without_tokens` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected expression, found `$` + --> $DIR/syntax-errors.rs:125:9 + | +LL | ${count(foo)} + | ^ expected expression +... +LL | unknown_count_ident!(a); + | ----------------------- in this macro invocation + | + = note: this error originates in the macro `unknown_count_ident` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected expression, found `$` + --> $DIR/syntax-errors.rs:133:9 + | +LL | ${ignore(bar)} + | ^ expected expression +... +LL | unknown_ignore_ident!(a); + | ------------------------ in this macro invocation + | + = note: this error originates in the macro `unknown_ignore_ident` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected expression, found `$` + --> $DIR/syntax-errors.rs:140:30 + | +LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; + | ^ expected expression +... +LL | unknown_metavar!(a); + | ------------------- in this macro invocation + | + = note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0425]: cannot find value `i` in this scope + --> $DIR/syntax-errors.rs:23:36 + | +LL | ( $( $i:ident ),* ) => { count(i) }; + | ^ not found in this scope +... +LL | no_curly__no_rhs_dollar__round!(a, b, c); + | ---------------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0425]: cannot find value `i` in this scope + --> $DIR/syntax-errors.rs:30:29 + | +LL | ( $i:ident ) => { count(i) }; + | ^ not found in this scope +... +LL | no_curly__no_rhs_dollar__no_round!(a); + | ------------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0425]: cannot find value `a` in this scope + --> $DIR/syntax-errors.rs:152:37 + | +LL | ( $i:ident ) => { count($i) }; + | -- due to this macro variable +... +LL | no_curly__rhs_dollar__no_round!(a); + | ^ not found in this scope + +error[E0425]: cannot find function `count` in this scope + --> $DIR/syntax-errors.rs:23:30 + | +LL | ( $( $i:ident ),* ) => { count(i) }; + | ^^^^^ not found in this scope +... +LL | no_curly__no_rhs_dollar__round!(a, b, c); + | ---------------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0425]: cannot find function `count` in this scope + --> $DIR/syntax-errors.rs:30:23 + | +LL | ( $i:ident ) => { count(i) }; + | ^^^^^ not found in this scope +... +LL | no_curly__no_rhs_dollar__no_round!(a); + | ------------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0425]: cannot find function `count` in this scope + --> $DIR/syntax-errors.rs:43:23 + | +LL | ( $i:ident ) => { count($i) }; + | ^^^^^ not found in this scope +... +LL | no_curly__rhs_dollar__no_round!(a); + | ---------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 39 previous errors + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/macros/rfc-3086-metavar-expr/count-and-length-are-distinct.rs b/tests/ui/macros/rfc-3086-metavar-expr/count-and-length-are-distinct.rs deleted file mode 100644 index 8ca453273cd..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/count-and-length-are-distinct.rs +++ /dev/null @@ -1,283 +0,0 @@ -//@ run-pass - -#![feature(macro_metavar_expr)] - -fn main() { - macro_rules! one_nested_count_and_len { - ( $( [ $( $l:literal ),* ] ),* ) => { - [ - // outermost repetition - $( - // innermost repetition - $( - ${ignore($l)} ${index()}, ${len()}, - )* - ${count($l)}, ${index()}, ${len()}, - )* - ${count($l)}, - ] - }; - } - assert_eq!( - one_nested_count_and_len!(["foo"], ["bar", "baz"]), - [ - // # ["foo"] - - // ## innermost repetition (first iteration) - // - // `index` is 0 because this is the first innermost iteration. - // `len` is 1 because there is only one innermost repetition, "foo". - 0, 1, - // ## outermost repetition (first iteration) - // - // `count` is 1 because of "foo", i,e, `$l` has only one repetition, - // `index` is 0 because this is the first outermost iteration. - // `len` is 2 because there are 2 outermost repetitions, ["foo"] and ["bar", "baz"] - 1, 0, 2, - // # ["bar", "baz"] - - // ## innermost repetition (first iteration) - // - // `index` is 0 because this is the first innermost iteration - // `len` is 2 because there are repetitions, "bar" and "baz" - 0, 2, - // ## innermost repetition (second iteration) - // - // `index` is 1 because this is the second innermost iteration - // `len` is 2 because there are repetitions, "bar" and "baz" - 1, 2, - // ## outermost repetition (second iteration) - // - // `count` is 2 because of "bar" and "baz", i,e, `$l` has two repetitions, - // `index` is 1 because this is the second outermost iteration - // `len` is 2 because there are 2 outermost repetitions, ["foo"] and ["bar", "baz"] - 2, 1, 2, - // # last count - - // Because there are a total of 3 repetitions of `$l`, "foo", "bar" and "baz" - 3, - ] - ); - - // Based on the above explanation, the following macros should be straightforward - - // Grouped from the outermost to the innermost - macro_rules! three_nested_count { - ( $( { $( [ $( ( $( $i:ident )* ) )* ] )* } )* ) => { - &[ - $( $( $( - &[ - ${ignore($i)} ${count($i, 0)}, - ][..], - )* )* )* - - $( $( - &[ - ${ignore($i)} ${count($i, 0)}, - ${ignore($i)} ${count($i, 1)}, - ][..], - )* )* - - $( - &[ - ${ignore($i)} ${count($i, 0)}, - ${ignore($i)} ${count($i, 1)}, - ${ignore($i)} ${count($i, 2)}, - ][..], - )* - - &[ - ${count($i, 0)}, - ${count($i, 1)}, - ${count($i, 2)}, - ${count($i, 3)}, - ][..] - ][..] - } - } - assert_eq!( - three_nested_count!( - { - [ (a b c) (d e f) ] - [ (g h) (i j k l m) ] - [ (n) ] - } - { - [ (o) (p q) (r s) ] - [ (t u v w x y z) ] - } - ), - &[ - // a b c - &[3][..], - // d e f - &[3][..], - // g h - &[2][..], - // i j k l m - &[5][..], - // n - &[1][..], - // o - &[1][..], - // p q - &[2][..], - // r s - &[2][..], - // t u v w x y z - &[7][..], - // (a b c) (d e f) - &[6, 2][..], - // (g h) (i j k l m) - &[7, 2][..], - // (n) - &[1, 1][..], - // (o) (p q) (r s) - &[5, 3][..], - // (t u v w x y z) - &[7, 1][..], - // [ (a b c) (d e f) ] - // [ (g h) (i j k l m) ] - // [ (n) ] - &[14, 5, 3][..], - // [ (o) (p q) (r s) ] - // [ (t u v w x y z) ] - &[12, 4, 2][..], - // { - // [ (a b c) (d e f) ] - // [ (g h) (i j k l m) ] - // [ (n) ] - // } - // { - // [ (o) (p q) (r s) ] - // [ (t u v w x y z) ] - // } - &[26, 9, 5, 2][..] - ][..] - ); - - // Grouped from the outermost to the innermost - macro_rules! three_nested_len { - ( $( { $( [ $( ( $( $i:ident )* ) )* ] )* } )* ) => { - &[ - $( $( $( $( - &[ - ${ignore($i)} ${len(3)}, - ${ignore($i)} ${len(2)}, - ${ignore($i)} ${len(1)}, - ${ignore($i)} ${len(0)}, - ][..], - )* )* )* )* - - $( $( $( - &[ - ${ignore($i)} ${len(2)}, - ${ignore($i)} ${len(1)}, - ${ignore($i)} ${len(0)}, - ][..], - )* )* )* - - $( $( - &[ - ${ignore($i)} ${len(1)}, - ${ignore($i)} ${len(0)}, - ][..], - )* )* - - $( - &[ - ${ignore($i)} ${len(0)}, - ][..], - )* - ][..] - } - } - assert_eq!( - three_nested_len!( - { - [ (a b c) (d e f) ] - [ (g h) (i j k l m) ] - [ (n) ] - } - { - [ (o) (p q) (r s) ] - [ (t u v w x y z) ] - } - ), - &[ - // a b c - &[2, 3, 2, 3][..], - &[2, 3, 2, 3][..], - &[2, 3, 2, 3][..], - // d e f - &[2, 3, 2, 3][..], - &[2, 3, 2, 3][..], - &[2, 3, 2, 3][..], - // g h - &[2, 3, 2, 2][..], - &[2, 3, 2, 2][..], - // i j k l m - &[2, 3, 2, 5][..], - &[2, 3, 2, 5][..], - &[2, 3, 2, 5][..], - &[2, 3, 2, 5][..], - &[2, 3, 2, 5][..], - // n - &[2, 3, 1, 1][..], - // o - &[2, 2, 3, 1][..], - // p q - &[2, 2, 3, 2][..], - &[2, 2, 3, 2][..], - // r s - &[2, 2, 3, 2][..], - &[2, 2, 3, 2][..], - // t u v w x y z - &[2, 2, 1, 7][..], - &[2, 2, 1, 7][..], - &[2, 2, 1, 7][..], - &[2, 2, 1, 7][..], - &[2, 2, 1, 7][..], - &[2, 2, 1, 7][..], - &[2, 2, 1, 7][..], - // (a b c) (d e f) - &[2, 3, 2][..], - &[2, 3, 2][..], - // (g h) (i j k l m) - &[2, 3, 2][..], - &[2, 3, 2][..], - // (n) - &[2, 3, 1][..], - // (o) (p q) (r s) - &[2, 2, 3][..], - &[2, 2, 3][..], - &[2, 2, 3][..], - // (t u v w x y z) - &[2, 2, 1][..], - // [ (a b c) (d e f) ] - // [ (g h) (i j k l m) ] - // [ (n) ] - &[2, 3][..], - &[2, 3][..], - &[2, 3,][..], - // [ (o) (p q) (r s) ] - // [ (t u v w x y z) ] - &[2, 2][..], - &[2, 2][..], - // { - // [ (a b c) (d e f) ] - // [ (g h) (i j k l m) ] - // [ (n) ] - // } - // { - // [ (o) (p q) (r s) ] - // [ (t u v w x y z) ] - // } - &[2][..], - &[2][..] - ][..] - ); - - // It is possible to say, to some degree, that count is an "amalgamation" of len (see - // each len line result and compare them with the count results) -} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/dollar-dollar-has-correct-behavior.rs b/tests/ui/macros/rfc-3086-metavar-expr/dollar-dollar-has-correct-behavior.rs deleted file mode 100644 index 9b8e3216a68..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/dollar-dollar-has-correct-behavior.rs +++ /dev/null @@ -1,28 +0,0 @@ -//@ run-pass - -#![feature(macro_metavar_expr)] - -macro_rules! nested { - ( $a:ident ) => { - macro_rules! $a { - ( $$( $b:ident ),* ) => { - $$( - macro_rules! $b { - ( $$$$( $c:ident ),* ) => { - $$$$( - fn $c() -> &'static str { stringify!($c) } - ),* - }; - } - )* - }; - } - }; -} - -fn main() { - nested!(a); - a!(b); - b!(c); - assert_eq!(c(), "c"); -} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs b/tests/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs deleted file mode 100644 index 51445221c57..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs +++ /dev/null @@ -1,147 +0,0 @@ -//@ run-pass - -#![feature(macro_metavar_expr)] - -/// Count the number of idents in a macro repetition. -macro_rules! count_idents { - ( $( $i:ident ),* ) => { - ${count($i)} - }; -} - -/// Count the number of idents in a 2-dimensional macro repetition. -macro_rules! count_idents_2 { - ( $( [ $( $i:ident ),* ] ),* ) => { - ${count($i)} - }; -} - -/// Mostly counts the number of OUTER-MOST repetitions -macro_rules! count_depth_limits { - ( $( { $( [ $( $outer:ident : ( $( $inner:ident )* ) )* ] )* } )* ) => { - ( - ( - ${count($inner)}, - ${count($inner, 0)}, - ${count($inner, 1)}, - ${count($inner, 2)}, - ${count($inner, 3)}, - ), - ( - ${count($outer)}, - ${count($outer, 0)}, - ${count($outer, 1)}, - ${count($outer, 2)}, - ), - ) - }; -} - -/// Produce (index, len) pairs for literals in a macro repetition. -/// The literal is not included in the output, so this macro uses the -/// `ignore` meta-variable expression to create a non-expanding -/// repetition binding. -macro_rules! enumerate_literals { - ( $( ($l:stmt) ),* ) => { - [$( ${ignore($l)} (${index()}, ${len()}) ),*] - }; -} - -/// Produce index and len tuples for literals in a 2-dimensional -/// macro repetition. -macro_rules! enumerate_literals_2 { - ( $( [ $( ($l:literal) ),* ] ),* ) => { - [ - $( - $( - ( - ${index(1)}, - ${len(1)}, - ${index(0)}, - ${len(0)}, - $l - ), - )* - )* - ] - }; -} - -/// Generate macros that count idents and then add a constant number -/// to the count. -/// -/// This macro uses dollar escaping to make it unambiguous as to which -/// macro the repetition belongs to. -macro_rules! make_count_adders { - ( $( $i:ident, $b:literal );* ) => { - $( - macro_rules! $i { - ( $$( $$j:ident ),* ) => { - $b + $${count($j)} - }; - } - )* - }; -} - -make_count_adders! { plus_one, 1; plus_five, 5 } - -/// Generate a macro that allows selection of a particular literal -/// from a sequence of inputs by their identifier. -/// -/// This macro uses dollar escaping to make it unambiguous as to which -/// macro the repetition belongs to, and to allow expansion of an -/// identifier the name of which is not known in the definition -/// of `make_picker`. -macro_rules! make_picker { - ( $m:ident => $( $i:ident ),* ; $p:ident ) => { - macro_rules! $m { - ( $( $$ $i:literal ),* ) => { - $$ $p - }; - } - }; -} - -make_picker!(first => a, b; a); - -make_picker!(second => a, b; b); - -fn main() { - assert_eq!(count_idents!(a, b, c), 3); - assert_eq!(count_idents_2!([a, b, c], [d, e], [f]), 6); - assert_eq!( - count_depth_limits! { - { - [ A: (a b c) D: (d e f) ] - [ G: (g h) I: (i j k l m) ] - [ N: (n) ] - } - { - [ O: (o) P: (p q) R: (r s) ] - [ T: (t u v w x y z) ] - } - }, - ((26, 26, 9, 5, 2), (9, 9, 5, 2)) - ); - assert_eq!(enumerate_literals![("foo"), ("bar")], [(0, 2), (1, 2)]); - assert_eq!( - enumerate_literals_2![ - [("foo"), ("bar"), ("baz")], - [("qux"), ("quux"), ("quuz"), ("xyzzy")] - ], - [ - (0, 2, 0, 3, "foo"), - (0, 2, 1, 3, "bar"), - (0, 2, 2, 3, "baz"), - (1, 2, 0, 4, "qux"), - (1, 2, 1, 4, "quux"), - (1, 2, 2, 4, "quuz"), - (1, 2, 3, 4, "xyzzy"), - ] - ); - assert_eq!(plus_one!(a, b, c), 4); - assert_eq!(plus_five!(a, b), 7); - assert_eq!(first!(1, 2), 1); - assert_eq!(second!(1, 2), 2); -} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.rs b/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.rs deleted file mode 100644 index 3000bfed6a8..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(macro_metavar_expr)] - -macro_rules! foo { - ( $( $($t:ident),* );* ) => { ${count($t,)} } - //~^ ERROR `count` followed by a comma must have an associated - //~| ERROR expected expression, found `$` -} - -fn test() { - foo!(a, a; b, b); -} - -fn main() { -} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.stderr b/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.stderr deleted file mode 100644 index fd53c1686cf..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/issue-111904.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: `count` followed by a comma must have an associated index indicating its depth - --> $DIR/issue-111904.rs:4:37 - | -LL | ( $( $($t:ident),* );* ) => { ${count($t,)} } - | ^^^^^ - -error: expected expression, found `$` - --> $DIR/issue-111904.rs:4:35 - | -LL | ( $( $($t:ident),* );* ) => { ${count($t,)} } - | ^ expected expression -... -LL | foo!(a, a; b, b); - | ---------------- in this macro invocation - | - = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - diff --git a/tests/ui/macros/rfc-3086-metavar-expr/macro-expansion.rs b/tests/ui/macros/rfc-3086-metavar-expr/macro-expansion.rs deleted file mode 100644 index 1d34275874b..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/macro-expansion.rs +++ /dev/null @@ -1,102 +0,0 @@ -//@ run-pass - -#![feature(macro_metavar_expr)] - -#[derive(Debug)] -struct Example<'a> { - _indexes: &'a [(u32, u32)], - _counts: &'a [u32], - _nested: Vec>, -} - -macro_rules! example { - ( $( [ $( ( $( $x:ident )* ) )* ] )* ) => { - Example { - _indexes: &[], - _counts: &[${count($x, 0)}, ${count($x, 1)}, ${count($x, 2)}], - _nested: vec![ - $( - Example { - _indexes: &[(${index()}, ${len()})], - _counts: &[${count($x, 0)}, ${count($x, 1)}], - _nested: vec![ - $( - Example { - _indexes: &[(${index(1)}, ${len(1)}), (${index()}, ${len()})], - _counts: &[${count($x)}], - _nested: vec![ - $( - Example { - _indexes: &[ - (${index(2)}, ${len(2)}), - (${index(1)}, ${len(1)}), - (${index()}, ${len()}) - ], - _counts: &[], - _nested: vec![], - ${ignore($x)} - } - ),* - ] - } - ),* - ] - } - ),* - ] - } - }; -} - -static EXPECTED: &str = concat!( - "Example { _indexes: [], _counts: [13, 4, 2], _nested: [", - concat!( - "Example { _indexes: [(0, 2)], _counts: [10, 3], _nested: [", - concat!( - "Example { _indexes: [(0, 2), (0, 3)], _counts: [4], _nested: [", - concat!( - "Example { _indexes: [(0, 2), (0, 3), (0, 4)], _counts: [], _nested: [] }, ", - "Example { _indexes: [(0, 2), (0, 3), (1, 4)], _counts: [], _nested: [] }, ", - "Example { _indexes: [(0, 2), (0, 3), (2, 4)], _counts: [], _nested: [] }, ", - "Example { _indexes: [(0, 2), (0, 3), (3, 4)], _counts: [], _nested: [] }", - ), - "] }, ", - "Example { _indexes: [(0, 2), (1, 3)], _counts: [4], _nested: [", - concat!( - "Example { _indexes: [(0, 2), (1, 3), (0, 4)], _counts: [], _nested: [] }, ", - "Example { _indexes: [(0, 2), (1, 3), (1, 4)], _counts: [], _nested: [] }, ", - "Example { _indexes: [(0, 2), (1, 3), (2, 4)], _counts: [], _nested: [] }, ", - "Example { _indexes: [(0, 2), (1, 3), (3, 4)], _counts: [], _nested: [] }", - ), - "] }, ", - "Example { _indexes: [(0, 2), (2, 3)], _counts: [2], _nested: [", - concat!( - "Example { _indexes: [(0, 2), (2, 3), (0, 2)], _counts: [], _nested: [] }, ", - "Example { _indexes: [(0, 2), (2, 3), (1, 2)], _counts: [], _nested: [] }", - ), - "] }", - ), - "] }, ", - "Example { _indexes: [(1, 2)], _counts: [3, 1], _nested: [", - concat!( - "Example { _indexes: [(1, 2), (0, 1)], _counts: [3], _nested: [", - concat!( - "Example { _indexes: [(1, 2), (0, 1), (0, 3)], _counts: [], _nested: [] }, ", - "Example { _indexes: [(1, 2), (0, 1), (1, 3)], _counts: [], _nested: [] }, ", - "Example { _indexes: [(1, 2), (0, 1), (2, 3)], _counts: [], _nested: [] }", - ), - "] }", - ), - "] }", - ), - "] }", -); - -fn main() { - let e = example! { - [ ( A B C D ) ( E F G H ) ( I J ) ] - [ ( K L M ) ] - }; - let debug = format!("{:?}", e); - assert_eq!(debug, EXPECTED); -} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.rs b/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.rs deleted file mode 100644 index 0caa3ea89e4..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![feature(macro_metavar_expr)] - -macro_rules! a { - ( $( { $( [ $( ( $( $foo:ident )* ) )* ] )* } )* ) => { - ( - ${count($foo, 0)}, - ${count($foo, 10)}, - //~^ ERROR depth parameter of meta-variable expression `count` must be less than 4 - ) - }; -} - -macro_rules! b { - ( $( { $( [ $( $foo:ident )* ] )* } )* ) => { - ( - $( $( $( - ${ignore($foo)} - ${index(0)}, - ${index(10)}, - //~^ ERROR depth parameter of meta-variable expression `index` must be less than 3 - )* )* )* - ) - }; -} - -macro_rules! c { - ( $( { $( $foo:ident )* } )* ) => { - ( - $( $( - ${ignore($foo)} - ${len(0)} - ${len(10)} - //~^ ERROR depth parameter of meta-variable expression `len` must be less than 2 - )* )* - ) - }; -} - -fn main() { - a!( { [ (a) ] [ (b c) ] } ); - b!( { [ a b ] } ); - c!({ a }); -} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.stderr b/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.stderr deleted file mode 100644 index 0b441cad083..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: depth parameter of meta-variable expression `count` must be less than 4 - --> $DIR/out-of-bounds-arguments.rs:7:14 - | -LL | ${count($foo, 10)}, - | ^^^^^^^^^^^^^^^^^ - -error: depth parameter of meta-variable expression `index` must be less than 3 - --> $DIR/out-of-bounds-arguments.rs:19:18 - | -LL | ${index(10)}, - | ^^^^^^^^^^^ - -error: depth parameter of meta-variable expression `len` must be less than 2 - --> $DIR/out-of-bounds-arguments.rs:32:18 - | -LL | ${len(10)} - | ^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/macros/rfc-3086-metavar-expr/required-feature.rs b/tests/ui/macros/rfc-3086-metavar-expr/required-feature.rs deleted file mode 100644 index 77c165e3855..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/required-feature.rs +++ /dev/null @@ -1,43 +0,0 @@ -macro_rules! count { - ( $( $e:stmt ),* ) => { - ${ count($e) } - //~^ ERROR meta-variable expressions are unstable - }; -} - -macro_rules! dollar_dollar { - () => { - macro_rules! bar { - ( $$( $$any:tt )* ) => { $$( $$any )* }; - //~^ ERROR meta-variable expressions are unstable - //~| ERROR meta-variable expressions are unstable - //~| ERROR meta-variable expressions are unstable - //~| ERROR meta-variable expressions are unstable - } - }; -} - -macro_rules! index { - ( $( $e:stmt ),* ) => { - $( ${ignore($e)} ${index()} )* - //~^ ERROR meta-variable expressions are unstable - //~| ERROR meta-variable expressions are unstable - }; -} - -macro_rules! ignore { - ( $( $i:stmt ),* ) => {{ - 0 $( + 1 ${ignore($i)} )* - //~^ ERROR meta-variable expressions are unstable - }}; -} - -macro_rules! len { - ( $( $e:stmt ),* ) => { - $( ${ignore($e)} ${len()} )* - //~^ ERROR meta-variable expressions are unstable - //~| ERROR meta-variable expressions are unstable - }; -} - -fn main() {} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/required-feature.stderr b/tests/ui/macros/rfc-3086-metavar-expr/required-feature.stderr deleted file mode 100644 index f28f822a058..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/required-feature.stderr +++ /dev/null @@ -1,103 +0,0 @@ -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:3:10 - | -LL | ${ count($e) } - | ^^^^^^^^^^^^^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:11:16 - | -LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; - | ^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:11:20 - | -LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; - | ^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:11:39 - | -LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; - | ^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:11:43 - | -LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; - | ^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:22:13 - | -LL | $( ${ignore($e)} ${index()} )* - | ^^^^^^^^^^^^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:22:27 - | -LL | $( ${ignore($e)} ${index()} )* - | ^^^^^^^^^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:30:19 - | -LL | 0 $( + 1 ${ignore($i)} )* - | ^^^^^^^^^^^^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:37:13 - | -LL | $( ${ignore($e)} ${len()} )* - | ^^^^^^^^^^^^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:37:27 - | -LL | $( ${ignore($e)} ${len()} )* - | ^^^^^^^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 10 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs b/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs deleted file mode 100644 index 78cede92526..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs +++ /dev/null @@ -1,164 +0,0 @@ -#![feature(macro_metavar_expr)] - -// `curly` = Right hand side curly brackets -// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function" -// `round` = Left hand side round brackets - -macro_rules! curly__no_rhs_dollar__round { - ( $( $i:ident ),* ) => { ${ count($i) } }; -} - -macro_rules! curly__no_rhs_dollar__no_round { - ( $i:ident ) => { ${ count($i) } }; - //~^ ERROR `count` can not be placed inside the innermost repetition -} - -macro_rules! curly__rhs_dollar__no_round { - ( $i:ident ) => { ${ count($i) } }; - //~^ ERROR `count` can not be placed inside the innermost repetition -} - -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__no_rhs_dollar__round { - ( $( $i:ident ),* ) => { count(i) }; - //~^ ERROR cannot find function `count` in this scope - //~| ERROR cannot find value `i` in this scope -} - -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__no_rhs_dollar__no_round { - ( $i:ident ) => { count(i) }; - //~^ ERROR cannot find function `count` in this scope - //~| ERROR cannot find value `i` in this scope -} - -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__rhs_dollar__round { - ( $( $i:ident ),* ) => { count($i) }; - //~^ ERROR variable `i` is still repeating at this depth -} - -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__rhs_dollar__no_round { - ( $i:ident ) => { count($i) }; - //~^ ERROR cannot find function `count` in this scope -} - -// Other scenarios - -macro_rules! dollar_dollar_in_the_lhs { - ( $$ $a:ident ) => { - //~^ ERROR unexpected token: $ - }; -} - -macro_rules! extra_garbage_after_metavar { - ( $( $i:ident ),* ) => { - ${count() a b c} - //~^ ERROR unexpected token: a - //~| ERROR expected expression, found `$` - ${count($i a b c)} - //~^ ERROR unexpected token: a - ${count($i, 1 a b c)} - //~^ ERROR unexpected token: a - ${count($i) a b c} - //~^ ERROR unexpected token: a - - ${ignore($i) a b c} - //~^ ERROR unexpected token: a - ${ignore($i a b c)} - //~^ ERROR unexpected token: a - - ${index() a b c} - //~^ ERROR unexpected token: a - ${index(1 a b c)} - //~^ ERROR unexpected token: a - - ${index() a b c} - //~^ ERROR unexpected token: a - ${index(1 a b c)} - //~^ ERROR unexpected token: a - }; -} - -const IDX: usize = 1; -macro_rules! metavar_depth_is_not_literal { - ( $( $i:ident ),* ) => { ${ index(IDX) } }; - //~^ ERROR meta-variable expression depth must be a literal - //~| ERROR expected expression, found `$` -} - -macro_rules! metavar_in_the_lhs { - ( ${ len() } ) => { - //~^ ERROR unexpected token: { - //~| ERROR expected one of: `*`, `+`, or `?` - }; -} - -macro_rules! metavar_token_without_ident { - ( $( $i:ident ),* ) => { ${ ignore() } }; - //~^ ERROR meta-variable expressions must be referenced using a dollar sign - //~| ERROR expected expression -} - -macro_rules! metavar_with_literal_suffix { - ( $( $i:ident ),* ) => { ${ index(1u32) } }; - //~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions - //~| ERROR expected expression, found `$` -} - -macro_rules! metavar_without_parens { - ( $( $i:ident ),* ) => { ${ count{i} } }; - //~^ ERROR meta-variable expression parameter must be wrapped in parentheses - //~| ERROR expected expression, found `$` -} - -#[rustfmt::skip] -macro_rules! open_brackets_without_tokens { - ( $( $i:ident ),* ) => { ${ {} } }; - //~^ ERROR expected expression, found `$` - //~| ERROR expected identifier -} - -macro_rules! unknown_count_ident { - ( $( $i:ident )* ) => { - ${count(foo)} - //~^ ERROR meta-variable expressions must be referenced using a dollar sign - //~| ERROR expected expression - }; -} - -macro_rules! unknown_ignore_ident { - ( $( $i:ident )* ) => { - ${ignore(bar)} - //~^ ERROR meta-variable expressions must be referenced using a dollar sign - //~| ERROR expected expression - }; -} - -macro_rules! unknown_metavar { - ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; - //~^ ERROR unrecognized meta-variable expression - //~| ERROR expected expression -} - -fn main() { - curly__no_rhs_dollar__round!(a, b, c); - curly__no_rhs_dollar__no_round!(a); - curly__rhs_dollar__no_round!(a); - no_curly__no_rhs_dollar__round!(a, b, c); - no_curly__no_rhs_dollar__no_round!(a); - no_curly__rhs_dollar__round!(a, b, c); - no_curly__rhs_dollar__no_round!(a); - //~^ ERROR cannot find value `a` in this scope - - extra_garbage_after_metavar!(a); - metavar_depth_is_not_literal!(a); - metavar_token_without_ident!(a); - metavar_with_literal_suffix!(a); - metavar_without_parens!(a); - open_brackets_without_tokens!(a); - unknown_count_ident!(a); - unknown_ignore_ident!(a); - unknown_metavar!(a); -} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr b/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr deleted file mode 100644 index d9646760cea..00000000000 --- a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr +++ /dev/null @@ -1,382 +0,0 @@ -error: unexpected token: $ - --> $DIR/syntax-errors.rs:50:8 - | -LL | ( $$ $a:ident ) => { - | ^ - -note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions - --> $DIR/syntax-errors.rs:50:8 - | -LL | ( $$ $a:ident ) => { - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:57:19 - | -LL | ${count() a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:57:19 - | -LL | ${count() a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:60:20 - | -LL | ${count($i a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:60:20 - | -LL | ${count($i a b c)} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:62:23 - | -LL | ${count($i, 1 a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:62:23 - | -LL | ${count($i, 1 a b c)} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:64:21 - | -LL | ${count($i) a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:64:21 - | -LL | ${count($i) a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:67:22 - | -LL | ${ignore($i) a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:67:22 - | -LL | ${ignore($i) a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:69:21 - | -LL | ${ignore($i a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:69:21 - | -LL | ${ignore($i a b c)} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:72:19 - | -LL | ${index() a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:72:19 - | -LL | ${index() a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:74:19 - | -LL | ${index(1 a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:74:19 - | -LL | ${index(1 a b c)} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:77:19 - | -LL | ${index() a b c} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:77:19 - | -LL | ${index() a b c} - | ^ - -error: unexpected token: a - --> $DIR/syntax-errors.rs:79:19 - | -LL | ${index(1 a b c)} - | ^ - | -note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:79:19 - | -LL | ${index(1 a b c)} - | ^ - -error: meta-variable expression depth must be a literal - --> $DIR/syntax-errors.rs:86:33 - | -LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; - | ^^^^^ - -error: unexpected token: { - --> $DIR/syntax-errors.rs:92:8 - | -LL | ( ${ len() } ) => { - | ^^^^^^^^^ - -note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions - --> $DIR/syntax-errors.rs:92:8 - | -LL | ( ${ len() } ) => { - | ^^^^^^^^^ - -error: expected one of: `*`, `+`, or `?` - --> $DIR/syntax-errors.rs:92:8 - | -LL | ( ${ len() } ) => { - | ^^^^^^^^^ - -error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:99:33 - | -LL | ( $( $i:ident ),* ) => { ${ ignore() } }; - | ^^^^^^ - -error: only unsuffixes integer literals are supported in meta-variable expressions - --> $DIR/syntax-errors.rs:105:33 - | -LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; - | ^^^^^ - -error: meta-variable expression parameter must be wrapped in parentheses - --> $DIR/syntax-errors.rs:111:33 - | -LL | ( $( $i:ident ),* ) => { ${ count{i} } }; - | ^^^^^ - -error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:125:11 - | -LL | ${count(foo)} - | ^^^^^ - -error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:133:11 - | -LL | ${ignore(bar)} - | ^^^^^^ - -error: unrecognized meta-variable expression - --> $DIR/syntax-errors.rs:140:33 - | -LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; - | ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and len - -error: expected identifier or string literal - --> $DIR/syntax-errors.rs:118:33 - | -LL | ( $( $i:ident ),* ) => { ${ {} } }; - | ^^ - -error: `count` can not be placed inside the innermost repetition - --> $DIR/syntax-errors.rs:12:24 - | -LL | ( $i:ident ) => { ${ count($i) } }; - | ^^^^^^^^^^^^^ - -error: `count` can not be placed inside the innermost repetition - --> $DIR/syntax-errors.rs:17:24 - | -LL | ( $i:ident ) => { ${ count($i) } }; - | ^^^^^^^^^^^^^ - -error: variable `i` is still repeating at this depth - --> $DIR/syntax-errors.rs:37:36 - | -LL | ( $( $i:ident ),* ) => { count($i) }; - | ^^ - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:57:9 - | -LL | ${count() a b c} - | ^ expected expression -... -LL | extra_garbage_after_metavar!(a); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `extra_garbage_after_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:86:30 - | -LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; - | ^ expected expression -... -LL | metavar_depth_is_not_literal!(a); - | -------------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_depth_is_not_literal` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:99:30 - | -LL | ( $( $i:ident ),* ) => { ${ ignore() } }; - | ^ expected expression -... -LL | metavar_token_without_ident!(a); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_token_without_ident` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:105:30 - | -LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; - | ^ expected expression -... -LL | metavar_with_literal_suffix!(a); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_with_literal_suffix` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:111:30 - | -LL | ( $( $i:ident ),* ) => { ${ count{i} } }; - | ^ expected expression -... -LL | metavar_without_parens!(a); - | -------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_without_parens` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:118:30 - | -LL | ( $( $i:ident ),* ) => { ${ {} } }; - | ^ expected expression -... -LL | open_brackets_without_tokens!(a); - | -------------------------------- in this macro invocation - | - = note: this error originates in the macro `open_brackets_without_tokens` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:125:9 - | -LL | ${count(foo)} - | ^ expected expression -... -LL | unknown_count_ident!(a); - | ----------------------- in this macro invocation - | - = note: this error originates in the macro `unknown_count_ident` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:133:9 - | -LL | ${ignore(bar)} - | ^ expected expression -... -LL | unknown_ignore_ident!(a); - | ------------------------ in this macro invocation - | - = note: this error originates in the macro `unknown_ignore_ident` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:140:30 - | -LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; - | ^ expected expression -... -LL | unknown_metavar!(a); - | ------------------- in this macro invocation - | - = note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find value `i` in this scope - --> $DIR/syntax-errors.rs:23:36 - | -LL | ( $( $i:ident ),* ) => { count(i) }; - | ^ not found in this scope -... -LL | no_curly__no_rhs_dollar__round!(a, b, c); - | ---------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find value `i` in this scope - --> $DIR/syntax-errors.rs:30:29 - | -LL | ( $i:ident ) => { count(i) }; - | ^ not found in this scope -... -LL | no_curly__no_rhs_dollar__no_round!(a); - | ------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find value `a` in this scope - --> $DIR/syntax-errors.rs:152:37 - | -LL | ( $i:ident ) => { count($i) }; - | -- due to this macro variable -... -LL | no_curly__rhs_dollar__no_round!(a); - | ^ not found in this scope - -error[E0425]: cannot find function `count` in this scope - --> $DIR/syntax-errors.rs:23:30 - | -LL | ( $( $i:ident ),* ) => { count(i) }; - | ^^^^^ not found in this scope -... -LL | no_curly__no_rhs_dollar__round!(a, b, c); - | ---------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find function `count` in this scope - --> $DIR/syntax-errors.rs:30:23 - | -LL | ( $i:ident ) => { count(i) }; - | ^^^^^ not found in this scope -... -LL | no_curly__no_rhs_dollar__no_round!(a); - | ------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find function `count` in this scope - --> $DIR/syntax-errors.rs:43:23 - | -LL | ( $i:ident ) => { count($i) }; - | ^^^^^ not found in this scope -... -LL | no_curly__rhs_dollar__no_round!(a); - | ---------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 39 previous errors - -For more information about this error, try `rustc --explain E0425`. -- cgit 1.4.1-3-g733a5 From c702055df88e6782c12c323de5c12cfadf1576ce Mon Sep 17 00:00:00 2001 From: Eeshvar Das Date: Sun, 29 Jun 2025 01:15:23 -0700 Subject: Update the-doc-attribute.md (#1) --- src/doc/rustdoc/src/write-documentation/the-doc-attribute.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustdoc/src/write-documentation/the-doc-attribute.md b/src/doc/rustdoc/src/write-documentation/the-doc-attribute.md index 65e6b417427..4d7f1a4aafc 100644 --- a/src/doc/rustdoc/src/write-documentation/the-doc-attribute.md +++ b/src/doc/rustdoc/src/write-documentation/the-doc-attribute.md @@ -62,7 +62,7 @@ This form of the `doc` attribute lets you control the favicon of your docs. This will put `` into your docs, where the string for the attribute goes into the `{}`. -If you don't use this attribute, there will be no favicon. +If you don't use this attribute, a default favicon will be used. ### `html_logo_url` -- cgit 1.4.1-3-g733a5 From bcf51051ed5ee27e5ae0f68de4d8899639355288 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Sat, 28 Jun 2025 21:31:28 +0200 Subject: inherit `#[align]` from trait method prototypes --- compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 31 +++++++--- compiler/rustc_middle/src/query/erase.rs | 1 + compiler/rustc_middle/src/query/mod.rs | 5 ++ tests/codegen/align-fn.rs | 82 ++++++++++++++++++++----- 4 files changed, 93 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index acdda32d58a..47c1e9085e3 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use rustc_abi::ExternAbi; +use rustc_abi::{Align, ExternAbi}; use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode}; use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr}; use rustc_attr_data_structures::{ @@ -402,6 +402,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { codegen_fn_attrs.alignment = Ord::max(codegen_fn_attrs.alignment, tcx.sess.opts.unstable_opts.min_function_alignment); + // On trait methods, inherit the `#[align]` of the trait's method prototype. + codegen_fn_attrs.alignment = Ord::max(codegen_fn_attrs.alignment, tcx.inherited_align(did)); + let inline_span; (codegen_fn_attrs.inline, inline_span) = if let Some((inline_attr, span)) = find_attr!(attrs, AttributeKind::Inline(i, span) => (*i, *span)) @@ -556,17 +559,26 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { codegen_fn_attrs } +/// If the provided DefId is a method in a trait impl, return the DefId of the method prototype. +fn opt_trait_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option { + let impl_item = tcx.opt_associated_item(def_id)?; + match impl_item.container { + ty::AssocItemContainer::Impl => impl_item.trait_item_def_id, + _ => None, + } +} + /// Checks if the provided DefId is a method in a trait impl for a trait which has track_caller /// applied to the method prototype. fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool { - if let Some(impl_item) = tcx.opt_associated_item(def_id) - && let ty::AssocItemContainer::Impl = impl_item.container - && let Some(trait_item) = impl_item.trait_item_def_id - { - return tcx.codegen_fn_attrs(trait_item).flags.intersects(CodegenFnAttrFlags::TRACK_CALLER); - } + let Some(trait_item) = opt_trait_item(tcx, def_id) else { return false }; + tcx.codegen_fn_attrs(trait_item).flags.intersects(CodegenFnAttrFlags::TRACK_CALLER) +} - false +/// If the provided DefId is a method in a trait impl, return the value of the `#[align]` +/// attribute on the method prototype (if any). +fn inherited_align<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option { + tcx.codegen_fn_attrs(opt_trait_item(tcx, def_id)?).alignment } fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &hir::Attribute) -> Option { @@ -734,5 +746,6 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { codegen_fn_attrs, should_inherit_track_caller, ..*providers }; + *providers = + Providers { codegen_fn_attrs, should_inherit_track_caller, inherited_align, ..*providers }; } diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 26a31cb055e..f138c5ca039 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -266,6 +266,7 @@ trivial! { Option, Option, Option, + Option, Result<(), rustc_errors::ErrorGuaranteed>, Result<(), rustc_middle::traits::query::NoSolution>, Result, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index ddedea32112..a57475f4fa8 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -67,6 +67,7 @@ use std::mem; use std::path::PathBuf; use std::sync::Arc; +use rustc_abi::Align; use rustc_arena::TypedArena; use rustc_ast::expand::StrippedCfgItem; use rustc_ast::expand::allocator::AllocatorKind; @@ -1481,6 +1482,10 @@ rustc_queries! { desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) } } + query inherited_align(def_id: DefId) -> Option { + desc { |tcx| "computing inherited_align of `{}`", tcx.def_path_str(def_id) } + } + query lookup_deprecation_entry(def_id: DefId) -> Option { desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) } cache_on_disk_if { def_id.is_local() } diff --git a/tests/codegen/align-fn.rs b/tests/codegen/align-fn.rs index 267da060240..90073ff3081 100644 --- a/tests/codegen/align-fn.rs +++ b/tests/codegen/align-fn.rs @@ -1,10 +1,10 @@ -//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 +//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 -Clink-dead-code #![crate_type = "lib"] #![feature(fn_align)] // CHECK: align 16 -#[no_mangle] +#[unsafe(no_mangle)] #[align(16)] pub fn fn_align() {} @@ -12,12 +12,12 @@ pub struct A; impl A { // CHECK: align 16 - #[no_mangle] + #[unsafe(no_mangle)] #[align(16)] pub fn method_align(self) {} // CHECK: align 16 - #[no_mangle] + #[unsafe(no_mangle)] #[align(16)] pub fn associated_fn() {} } @@ -25,46 +25,94 @@ impl A { trait T: Sized { fn trait_fn() {} - // CHECK: align 32 - #[align(32)] fn trait_method(self) {} + + #[align(8)] + fn trait_method_inherit_low(self); + + #[align(32)] + fn trait_method_inherit_high(self); + + #[align(32)] + fn trait_method_inherit_default(self) {} + + #[align(4)] + #[align(128)] + #[align(8)] + fn inherit_highest(self) {} } impl T for A { - // CHECK: align 16 - #[no_mangle] + // CHECK-LABEL: trait_fn + // CHECK-SAME: align 16 + #[unsafe(no_mangle)] #[align(16)] fn trait_fn() {} - // CHECK: align 16 - #[no_mangle] + // CHECK-LABEL: trait_method + // CHECK-SAME: align 16 + #[unsafe(no_mangle)] #[align(16)] fn trait_method(self) {} -} -impl T for () {} + // The prototype's align is ignored because the align here is higher. + // CHECK-LABEL: trait_method_inherit_low + // CHECK-SAME: align 16 + #[unsafe(no_mangle)] + #[align(16)] + fn trait_method_inherit_low(self) {} + + // The prototype's align is used because it is higher. + // CHECK-LABEL: trait_method_inherit_high + // CHECK-SAME: align 32 + #[unsafe(no_mangle)] + #[align(16)] + fn trait_method_inherit_high(self) {} + + // The prototype's align inherited. + // CHECK-LABEL: trait_method_inherit_default + // CHECK-SAME: align 32 + #[unsafe(no_mangle)] + fn trait_method_inherit_default(self) {} + + // The prototype's highest align inherited. + // CHECK-LABEL: inherit_highest + // CHECK-SAME: align 128 + #[unsafe(no_mangle)] + #[align(32)] + #[align(64)] + fn inherit_highest(self) {} +} -pub fn foo() { - ().trait_method(); +trait HasDefaultImpl: Sized { + // CHECK-LABEL: inherit_from_default_method + // CHECK-LABEL: inherit_from_default_method + // CHECK-SAME: align 32 + #[align(32)] + fn inherit_from_default_method(self) {} } +pub struct InstantiateDefaultMethods; + +impl HasDefaultImpl for InstantiateDefaultMethods {} + // CHECK-LABEL: align_specified_twice_1 // CHECK-SAME: align 64 -#[no_mangle] +#[unsafe(no_mangle)] #[align(32)] #[align(64)] pub fn align_specified_twice_1() {} // CHECK-LABEL: align_specified_twice_2 // CHECK-SAME: align 128 -#[no_mangle] +#[unsafe(no_mangle)] #[align(128)] #[align(32)] pub fn align_specified_twice_2() {} // CHECK-LABEL: align_specified_twice_3 // CHECK-SAME: align 256 -#[no_mangle] +#[unsafe(no_mangle)] #[align(32)] #[align(256)] pub fn align_specified_twice_3() {} -- cgit 1.4.1-3-g733a5 From 4fd37c719824a49c639803c6d4be4ca401a43abd Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 27 Jun 2025 20:24:01 -0500 Subject: Disable f16 on Aarch64 without neon for llvm < 20.1.1 This check was added unconditionally in c51b229140 ("Disable f16 on Aarch64 without `neon`") and reverted in 4a8d35709e ("Revert "Disable `f16` on Aarch64 without `neon`"") since it did not fail in Rust's build. However, it is still possible to hit this crash if using LLVM 19 built with assertions, so disable the type conditionally based on version here. Note that for these builds, a similar patch is needed in the build script for `compiler-builtins` since it does not yet use `cfg(target_has_reliable_f16)` (hopefully to be resolved in the near future). Report: https://www.github.com/rust-lang/rust/pull/139276#issuecomment-3014781652 Original LLVM issue: https://www.github.com/llvm/llvm-project/issues/129394 --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 6fd07d562af..0fb987bdf82 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -370,10 +370,18 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { let target_env = sess.target.options.env.as_ref(); let target_abi = sess.target.options.abi.as_ref(); let target_pointer_width = sess.target.pointer_width; + let version = get_version(); cfg.has_reliable_f16 = match (target_arch, target_os) { // Selection failure ("s390x", _) => false, + // LLVM crash without neon (now fixed) + ("aarch64", _) + if !cfg.target_features.iter().any(|f| f.as_str() == "neon") + && version < (20, 1, 1) => + { + false + } // Unsupported ("arm64ec", _) => false, // MinGW ABI bugs -- cgit 1.4.1-3-g733a5 From 76df2656dfdb385830e83b14abf908544177be22 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 30 Jun 2025 15:11:34 +0200 Subject: Replace `ItemCtxt::report_placeholder_type_error` `match` with a call to `TyCtxt::def_descr` --- compiler/rustc_hir_analysis/src/collect.rs | 12 +--------- .../invalid_infered_static_and_const.stderr | 4 ++-- tests/ui/closures/missing-body.rs | 7 ++++++ tests/ui/closures/missing-body.stderr | 19 +++++++++++++++ .../did_you_mean/bad-assoc-ty.edition2015.stderr | 2 +- .../did_you_mean/bad-assoc-ty.edition2021.stderr | 2 +- tests/ui/did_you_mean/bad-assoc-ty.rs | 2 +- .../replace-impl-infer-ty-from-trait.rs | 2 +- .../replace-impl-infer-ty-from-trait.stderr | 2 +- tests/ui/fn/error-recovery-mismatch.stderr | 2 +- tests/ui/self/self-infer.rs | 4 ++-- tests/ui/self/self-infer.stderr | 4 ++-- tests/ui/suggestions/bad-infer-in-trait-impl.rs | 2 +- .../ui/suggestions/bad-infer-in-trait-impl.stderr | 2 +- .../ice-119717-constant-lifetime.stderr | 2 +- ...od-argument-mismatch-variance-ice-119867.stderr | 2 +- tests/ui/typeck/issue-74086.rs | 2 +- tests/ui/typeck/issue-74086.stderr | 2 +- tests/ui/typeck/issue-75889.stderr | 4 ++-- tests/ui/typeck/issue-81885.rs | 4 ++-- tests/ui/typeck/issue-81885.stderr | 4 ++-- ...issue-83621-placeholder-static-in-extern.stderr | 2 +- tests/ui/typeck/issue-88643.rs | 6 ++--- tests/ui/typeck/issue-88643.stderr | 6 ++--- tests/ui/typeck/typeck_type_placeholder_item.rs | 28 +++++++++++----------- .../ui/typeck/typeck_type_placeholder_item.stderr | 28 +++++++++++----------- .../ui/typeck/typeck_type_placeholder_item_help.rs | 2 +- .../typeck_type_placeholder_item_help.stderr | 2 +- 28 files changed, 88 insertions(+), 72 deletions(-) create mode 100644 tests/ui/closures/missing-body.rs create mode 100644 tests/ui/closures/missing-body.stderr diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index d7568554669..3ee39fb71b2 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -277,17 +277,7 @@ impl<'tcx> ItemCtxt<'tcx> { } _ => self.item_def_id, }; - // FIXME: just invoke `tcx.def_descr` instead of going through the HIR - // Can also remove most `descr` methods then. - let kind = match self.tcx.hir_node_by_def_id(kind_id) { - Node::Item(it) => it.kind.descr(), - Node::ImplItem(it) => it.kind.descr(), - Node::TraitItem(it) => it.kind.descr(), - Node::ForeignItem(it) => it.kind.descr(), - Node::OpaqueTy(_) => "opaque type", - Node::Synthetic => self.tcx.def_descr(kind_id.into()), - node => todo!("{node:#?}"), - }; + let kind = self.tcx.def_descr(kind_id.into()); let mut diag = placeholder_type_error_diag( self, generics, diff --git a/tests/rustdoc-ui/invalid_infered_static_and_const.stderr b/tests/rustdoc-ui/invalid_infered_static_and_const.stderr index 401020224d6..3e116826c49 100644 --- a/tests/rustdoc-ui/invalid_infered_static_and_const.stderr +++ b/tests/rustdoc-ui/invalid_infered_static_and_const.stderr @@ -1,10 +1,10 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/invalid_infered_static_and_const.rs:1:24 | LL | const FOO: dyn Fn() -> _ = ""; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/invalid_infered_static_and_const.rs:2:25 | LL | static BOO: dyn Fn() -> _ = ""; diff --git a/tests/ui/closures/missing-body.rs b/tests/ui/closures/missing-body.rs new file mode 100644 index 00000000000..461c2be3ccd --- /dev/null +++ b/tests/ui/closures/missing-body.rs @@ -0,0 +1,7 @@ +// Checks that the compiler complains about the missing closure body and does not +// crash. +// This is a regression test for . + +fn main() { |b: [str; _]| {}; } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for closures +//~| ERROR the size for values of type `str` cannot be known at compilation time diff --git a/tests/ui/closures/missing-body.stderr b/tests/ui/closures/missing-body.stderr new file mode 100644 index 00000000000..33580fc2fbd --- /dev/null +++ b/tests/ui/closures/missing-body.stderr @@ -0,0 +1,19 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for closures + --> $DIR/missing-body.rs:5:23 + | +LL | fn main() { |b: [str; _]| {}; } + | ^ not allowed in type signatures + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/missing-body.rs:5:17 + | +LL | fn main() { |b: [str; _]| {}; } + | ^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: slice and array elements must have `Sized` type + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0121, E0277. +For more information about an error, try `rustc --explain E0121`. diff --git a/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr index fe1ce5ad18b..ed6e5c3e0c0 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr @@ -302,7 +302,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | trait P where F: Fn() -> _ { | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/bad-assoc-ty.rs:88:38 | LL | fn foo(_: F) where F: Fn() -> _ {} diff --git a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr index 2cf7a150aa2..2ee8ab2760a 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr @@ -284,7 +284,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | trait P where F: Fn() -> _ { | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/bad-assoc-ty.rs:88:38 | LL | fn foo(_: F) where F: Fn() -> _ {} diff --git a/tests/ui/did_you_mean/bad-assoc-ty.rs b/tests/ui/did_you_mean/bad-assoc-ty.rs index 9abda4fd962..39f0a84855a 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.rs +++ b/tests/ui/did_you_mean/bad-assoc-ty.rs @@ -86,7 +86,7 @@ trait P where F: Fn() -> _ { trait Q { fn foo(_: F) where F: Fn() -> _ {} - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions } fn main() {} diff --git a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.rs b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.rs index 1217a96112d..9ebc565b8fd 100644 --- a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.rs +++ b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.rs @@ -7,7 +7,7 @@ trait Foo: Sized { impl Foo for () { fn bar(i: _, t: _, s: _) -> _ { - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions //~| ERROR type annotations needed (1, 2) } diff --git a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr index 6c24a5899ea..3c11ad0cf29 100644 --- a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr +++ b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/replace-impl-infer-ty-from-trait.rs:9:15 | LL | fn bar(i: _, t: _, s: _) -> _ { diff --git a/tests/ui/fn/error-recovery-mismatch.stderr b/tests/ui/fn/error-recovery-mismatch.stderr index c046302cb91..10dab3052be 100644 --- a/tests/ui/fn/error-recovery-mismatch.stderr +++ b/tests/ui/fn/error-recovery-mismatch.stderr @@ -29,7 +29,7 @@ LL | fn fold(&self, _: T, &self._) {} = note: for more information, see issue #41686 = note: `#[warn(anonymous_parameters)]` on by default -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/error-recovery-mismatch.rs:11:35 | LL | fn fold(&self, _: T, &self._) {} diff --git a/tests/ui/self/self-infer.rs b/tests/ui/self/self-infer.rs index 9839b8880e9..d6f6d8bfa06 100644 --- a/tests/ui/self/self-infer.rs +++ b/tests/ui/self/self-infer.rs @@ -1,8 +1,8 @@ struct S; impl S { - fn f(self: _) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for functions - fn g(self: &_) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for functions + fn f(self: _) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for methods + fn g(self: &_) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for methods } fn main() {} diff --git a/tests/ui/self/self-infer.stderr b/tests/ui/self/self-infer.stderr index f9db559390f..13d803d9559 100644 --- a/tests/ui/self/self-infer.stderr +++ b/tests/ui/self/self-infer.stderr @@ -1,10 +1,10 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/self-infer.rs:4:16 | LL | fn f(self: _) {} | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/self-infer.rs:5:17 | LL | fn g(self: &_) {} diff --git a/tests/ui/suggestions/bad-infer-in-trait-impl.rs b/tests/ui/suggestions/bad-infer-in-trait-impl.rs index f38b168037b..db6fc9319e1 100644 --- a/tests/ui/suggestions/bad-infer-in-trait-impl.rs +++ b/tests/ui/suggestions/bad-infer-in-trait-impl.rs @@ -4,7 +4,7 @@ trait Foo { impl Foo for () { fn bar(s: _) {} - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions //~| ERROR has 1 parameter but the declaration in trait `Foo::bar` has 0 } diff --git a/tests/ui/suggestions/bad-infer-in-trait-impl.stderr b/tests/ui/suggestions/bad-infer-in-trait-impl.stderr index 8b7d67ac041..5aa46545943 100644 --- a/tests/ui/suggestions/bad-infer-in-trait-impl.stderr +++ b/tests/ui/suggestions/bad-infer-in-trait-impl.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/bad-infer-in-trait-impl.rs:6:15 | LL | fn bar(s: _) {} diff --git a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr index c6e0c699520..a165ef12060 100644 --- a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr +++ b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr @@ -16,7 +16,7 @@ LL | impl const FromResidual for T { = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/ice-119717-constant-lifetime.rs:9:31 | LL | fn from_residual(t: T) -> _ { diff --git a/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr b/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr index d535c39639f..6472ac7363b 100644 --- a/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr +++ b/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/method-argument-mismatch-variance-ice-119867.rs:8:23 | LL | fn deserialize(s: _) {} diff --git a/tests/ui/typeck/issue-74086.rs b/tests/ui/typeck/issue-74086.rs index 1993cc7db35..c00ba81f551 100644 --- a/tests/ui/typeck/issue-74086.rs +++ b/tests/ui/typeck/issue-74086.rs @@ -1,4 +1,4 @@ fn main() { static BUG: fn(_) -> u8 = |_| 8; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static items + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for statics } diff --git a/tests/ui/typeck/issue-74086.stderr b/tests/ui/typeck/issue-74086.stderr index 25f454ac0c3..02c48201918 100644 --- a/tests/ui/typeck/issue-74086.stderr +++ b/tests/ui/typeck/issue-74086.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-74086.rs:2:20 | LL | static BUG: fn(_) -> u8 = |_| 8; diff --git a/tests/ui/typeck/issue-75889.stderr b/tests/ui/typeck/issue-75889.stderr index 1438f481ec7..c76f7c60b2e 100644 --- a/tests/ui/typeck/issue-75889.stderr +++ b/tests/ui/typeck/issue-75889.stderr @@ -1,10 +1,10 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/issue-75889.rs:3:24 | LL | const FOO: dyn Fn() -> _ = ""; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-75889.rs:4:25 | LL | static BOO: dyn Fn() -> _ = ""; diff --git a/tests/ui/typeck/issue-81885.rs b/tests/ui/typeck/issue-81885.rs index d73c77b8f3a..d675231d898 100644 --- a/tests/ui/typeck/issue-81885.rs +++ b/tests/ui/typeck/issue-81885.rs @@ -1,7 +1,7 @@ const TEST4: fn() -> _ = 42; -//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants fn main() { const TEST5: fn() -> _ = 42; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants } diff --git a/tests/ui/typeck/issue-81885.stderr b/tests/ui/typeck/issue-81885.stderr index 25a6bb632ef..414fe548883 100644 --- a/tests/ui/typeck/issue-81885.stderr +++ b/tests/ui/typeck/issue-81885.stderr @@ -1,10 +1,10 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/issue-81885.rs:1:22 | LL | const TEST4: fn() -> _ = 42; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/issue-81885.rs:5:26 | LL | const TEST5: fn() -> _ = 42; diff --git a/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr b/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr index a4cb53025e3..c4a5c0dea6e 100644 --- a/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr +++ b/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr @@ -1,4 +1,4 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-83621-placeholder-static-in-extern.rs:4:15 | LL | static x: _; diff --git a/tests/ui/typeck/issue-88643.rs b/tests/ui/typeck/issue-88643.rs index 4435cba0207..e562f3e55ac 100644 --- a/tests/ui/typeck/issue-88643.rs +++ b/tests/ui/typeck/issue-88643.rs @@ -8,12 +8,12 @@ use std::collections::HashMap; pub trait T {} static CALLBACKS: HashMap<*const dyn T, dyn FnMut(&mut _) + 'static> = HashMap::new(); -//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121] +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for statics [E0121] static CALLBACKS2: Vec = Vec::new(); -//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121] +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for statics [E0121] static CALLBACKS3: Option = None; -//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121] +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for statics [E0121] fn main() {} diff --git a/tests/ui/typeck/issue-88643.stderr b/tests/ui/typeck/issue-88643.stderr index d5d596b6f42..ad11c3ea8e0 100644 --- a/tests/ui/typeck/issue-88643.stderr +++ b/tests/ui/typeck/issue-88643.stderr @@ -1,16 +1,16 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-88643.rs:10:56 | LL | static CALLBACKS: HashMap<*const dyn T, dyn FnMut(&mut _) + 'static> = HashMap::new(); | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-88643.rs:13:33 | LL | static CALLBACKS2: Vec = Vec::new(); | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics --> $DIR/issue-88643.rs:16:36 | LL | static CALLBACKS3: Option = None; diff --git a/tests/ui/typeck/typeck_type_placeholder_item.rs b/tests/ui/typeck/typeck_type_placeholder_item.rs index dc790361919..48547c019d6 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item.rs @@ -41,7 +41,7 @@ impl Test9 { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types fn test10(&self, _x : _) { } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods } fn test11(x: &usize) -> &_ { @@ -56,10 +56,10 @@ unsafe fn test12(x: *const usize) -> *const *const _ { impl Clone for Test9 { fn clone(&self) -> _ { Test9 } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods fn clone_from(&mut self, other: _) { *self = Test9; } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods } struct Test10 { @@ -108,15 +108,15 @@ pub fn main() { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types fn fn_test10(&self, _x : _) { } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods } impl Clone for FnTest9 { fn clone(&self) -> _ { FnTest9 } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods fn clone_from(&mut self, other: _) { *self = FnTest9; } - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods } struct FnTest10 { @@ -140,19 +140,19 @@ pub fn main() { trait T { fn method_test1(&self, x: _); - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods fn method_test2(&self, x: _) -> _; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions - //~| ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods + //~| ERROR the placeholder `_` is not allowed within types on item signatures for methods fn method_test3(&self) -> _; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods fn assoc_fn_test1(x: _); - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions fn assoc_fn_test2(x: _) -> _; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions - //~| ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions + //~| ERROR the placeholder `_` is not allowed within types on item signatures for associated functions fn assoc_fn_test3() -> _; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions } struct BadStruct<_>(_); diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index 53476f6c807..87750ee6dc1 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -203,7 +203,7 @@ LL | unsafe fn test12(x: *const usize) -> *const *const _ { | | not allowed in type signatures | help: replace with the correct return type: `*const *const usize` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:58:24 | LL | fn clone(&self) -> _ { Test9 } @@ -215,7 +215,7 @@ LL - fn clone(&self) -> _ { Test9 } LL + fn clone(&self) -> Test9 { Test9 } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:61:37 | LL | fn clone_from(&mut self, other: _) { *self = Test9; } @@ -332,7 +332,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | fn fn_test8(_f: fn() -> _) { } | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:115:28 | LL | fn clone(&self) -> _ { FnTest9 } @@ -344,7 +344,7 @@ LL - fn clone(&self) -> _ { FnTest9 } LL + fn clone(&self) -> FnTest9 { FnTest9 } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:118:41 | LL | fn clone_from(&mut self, other: _) { *self = FnTest9; } @@ -389,49 +389,49 @@ LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } | | not allowed in type signatures | help: replace with the correct return type: `(i32, i32)` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:142:31 | LL | fn method_test1(&self, x: _); | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:144:31 | LL | fn method_test2(&self, x: _) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:144:37 | LL | fn method_test2(&self, x: _) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:147:31 | LL | fn method_test3(&self) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/typeck_type_placeholder_item.rs:149:26 | LL | fn assoc_fn_test1(x: _); | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/typeck_type_placeholder_item.rs:151:26 | LL | fn assoc_fn_test2(x: _) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/typeck_type_placeholder_item.rs:151:32 | LL | fn assoc_fn_test2(x: _) -> _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions --> $DIR/typeck_type_placeholder_item.rs:154:28 | LL | fn assoc_fn_test3() -> _; @@ -575,7 +575,7 @@ LL | fn test9(&self) -> _ { () } | not allowed in type signatures | help: replace with the correct return type: `()` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:43:27 | LL | fn test10(&self, _x : _) { } @@ -590,7 +590,7 @@ LL | fn fn_test9(&self) -> _ { () } | not allowed in type signatures | help: replace with the correct return type: `()` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:110:34 | LL | fn fn_test10(&self, _x : _) { } diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.rs b/tests/ui/typeck/typeck_type_placeholder_item_help.rs index ab433aaaf16..758b94f9854 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item_help.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.rs @@ -11,7 +11,7 @@ const TEST3: _ = Some(42); //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants const TEST4: fn() -> _ = 42; -//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants trait Test5 { const TEST5: _ = 42; diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr index 5066e2eaa52..2fce00e7a8e 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr @@ -31,7 +31,7 @@ LL - const TEST3: _ = Some(42); LL + const TEST3: Option = Some(42); | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/typeck_type_placeholder_item_help.rs:13:22 | LL | const TEST4: fn() -> _ = 42; -- cgit 1.4.1-3-g733a5 From 74fda50f3b8b9cd3ad05c5f2f5c8cef8a14aad88 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 30 Jun 2025 15:11:55 +0200 Subject: Remove unused `descr` methods --- compiler/rustc_hir/src/hir.rs | 28 ---------------------- .../replace-impl-infer-ty-from-trait.fixed | 2 +- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 75dff588669..88e0ee1cc0b 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3141,15 +3141,6 @@ pub enum TraitItemKind<'hir> { /// type. Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>), } -impl TraitItemKind<'_> { - pub fn descr(&self) -> &'static str { - match self { - TraitItemKind::Const(..) => "associated constant", - TraitItemKind::Fn(..) => "function", - TraitItemKind::Type(..) => "associated type", - } - } -} // The bodies for items are stored "out of line", in a separate // hashmap in the `Crate`. Here we just record the hir-id of the item @@ -3211,15 +3202,6 @@ pub enum ImplItemKind<'hir> { /// An associated type. Type(&'hir Ty<'hir>), } -impl ImplItemKind<'_> { - pub fn descr(&self) -> &'static str { - match self { - ImplItemKind::Const(..) => "associated constant", - ImplItemKind::Fn(..) => "function", - ImplItemKind::Type(..) => "associated type", - } - } -} /// A constraint on an associated item. /// @@ -4545,16 +4527,6 @@ pub enum ForeignItemKind<'hir> { Type, } -impl ForeignItemKind<'_> { - pub fn descr(&self) -> &'static str { - match self { - ForeignItemKind::Fn(..) => "function", - ForeignItemKind::Static(..) => "static variable", - ForeignItemKind::Type => "type", - } - } -} - /// A variable captured by a closure. #[derive(Debug, Copy, Clone, HashStable_Generic)] pub struct Upvar { diff --git a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.fixed b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.fixed index db18cf2ad96..0096d3eaea4 100644 --- a/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.fixed +++ b/tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.fixed @@ -7,7 +7,7 @@ trait Foo: Sized { impl Foo for () { fn bar(i: i32, t: usize, s: &()) -> (usize, i32) { - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions //~| ERROR type annotations needed (1, 2) } -- cgit 1.4.1-3-g733a5 From 876835de11c3405f5de83a6b14755583bb3ff185 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 23 Jun 2025 00:14:23 -0500 Subject: mbe: Split metavariable usage tests off from syntax tests `syntax-errors` currently contains both syntax error tests (which don't need expansion) and tests for incorrect instantiations of the `count` metavariable expression (which do need expansion). Split the expansion-dependent tests to a separate file and remove unneeded invocations from `syntax-errors`, to ensure we are catching these before expansion. --- .../metavar-expressions/concat-syntax-errors.rs | 168 ----------- .../concat-syntax-errors.stderr | 284 ------------------- .../metavar-expressions/concat-usage-errors.rs | 168 +++++++++++ .../metavar-expressions/concat-usage-errors.stderr | 284 +++++++++++++++++++ .../ui/macros/metavar-expressions/syntax-errors.rs | 125 ++------- .../metavar-expressions/syntax-errors.stderr | 310 +++++---------------- .../ui/macros/metavar-expressions/usage-errors.rs | 55 ++++ .../macros/metavar-expressions/usage-errors.stderr | 71 +++++ 8 files changed, 670 insertions(+), 795 deletions(-) delete mode 100644 tests/ui/macros/metavar-expressions/concat-syntax-errors.rs delete mode 100644 tests/ui/macros/metavar-expressions/concat-syntax-errors.stderr create mode 100644 tests/ui/macros/metavar-expressions/concat-usage-errors.rs create mode 100644 tests/ui/macros/metavar-expressions/concat-usage-errors.stderr create mode 100644 tests/ui/macros/metavar-expressions/usage-errors.rs create mode 100644 tests/ui/macros/metavar-expressions/usage-errors.stderr diff --git a/tests/ui/macros/metavar-expressions/concat-syntax-errors.rs b/tests/ui/macros/metavar-expressions/concat-syntax-errors.rs deleted file mode 100644 index 7673bd3200f..00000000000 --- a/tests/ui/macros/metavar-expressions/concat-syntax-errors.rs +++ /dev/null @@ -1,168 +0,0 @@ -#![feature(macro_metavar_expr_concat)] - -macro_rules! wrong_concat_declarations { - ($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($ident, 'b')}: () = (); - //~^ ERROR expected identifier or string literal - let ${concat($ident, 1)}: () = (); - //~^ 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() { - wrong_concat_declarations!(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'); -} diff --git a/tests/ui/macros/metavar-expressions/concat-syntax-errors.stderr b/tests/ui/macros/metavar-expressions/concat-syntax-errors.stderr deleted file mode 100644 index 3297de80186..00000000000 --- a/tests/ui/macros/metavar-expressions/concat-syntax-errors.stderr +++ /dev/null @@ -1,284 +0,0 @@ -error: expected identifier or string literal - --> $DIR/concat-syntax-errors.rs:5:10 - | -LL | ${concat()} - | ^^^^^^^^^^ - -error: `concat` must have at least two elements - --> $DIR/concat-syntax-errors.rs:8:11 - | -LL | ${concat(aaaa)} - | ^^^^^^ - -error: expected identifier or string literal - --> $DIR/concat-syntax-errors.rs:11:10 - | -LL | ${concat(aaaa,)} - | ^^^^^^^^^^^^^^^ - -error: expected comma - --> $DIR/concat-syntax-errors.rs:16:10 - | -LL | ${concat(aaaa aaaa)} - | ^^^^^^^^^^^^^^^^^^^ - -error: `concat` must have at least two elements - --> $DIR/concat-syntax-errors.rs:19:11 - | -LL | ${concat($ex)} - | ^^^^^^ - -error: expected comma - --> $DIR/concat-syntax-errors.rs:25:10 - | -LL | ${concat($ex, aaaa 123)} - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: expected identifier or string literal - --> $DIR/concat-syntax-errors.rs:28:10 - | -LL | ${concat($ex, aaaa,)} - | ^^^^^^^^^^^^^^^^^^^^ - -error: expected identifier or string literal - --> $DIR/concat-syntax-errors.rs:88:26 - | -LL | let ${concat(_a, 'b')}: () = (); - | ^^^ - -error: expected identifier or string literal - --> $DIR/concat-syntax-errors.rs:91:26 - | -LL | let ${concat(_a, 1)}: () = (); - | ^ - -error: expected identifier or string literal - --> $DIR/concat-syntax-errors.rs:94:30 - | -LL | let ${concat($ident, 'b')}: () = (); - | ^^^ - -error: expected identifier or string literal - --> $DIR/concat-syntax-errors.rs:96:30 - | -LL | let ${concat($ident, 1)}: () = (); - | ^ - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-syntax-errors.rs:22:19 - | -LL | ${concat($ex, aaaa)} - | ^^ - | - = note: currently only string literals are supported - -error: variable `foo` is not recognized in meta-variable expression - --> $DIR/concat-syntax-errors.rs:35:30 - | -LL | const ${concat(FOO, $foo)}: i32 = 2; - | ^^^ - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:42:14 - | -LL | let ${concat("1", $ident)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^ -... -LL | starting_number!(_abc); - | ---------------------- in this macro invocation - | - = note: this error originates in the macro `starting_number` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:55:14 - | -LL | let ${concat("\u{00BD}", $ident)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | starting_invalid_unicode!(_abc); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `starting_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:74:14 - | -LL | let ${concat($ident, "\u{00BD}")}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | ending_invalid_unicode!(_abc); - | ----------------------------- in this macro invocation - | - = note: this error originates in the macro `ending_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected pattern, found `$` - --> $DIR/concat-syntax-errors.rs:88:13 - | -LL | let ${concat(_a, 'b')}: () = (); - | ^ expected pattern -... -LL | unsupported_literals!(_abc); - | --------------------------- in this macro invocation - | - = note: this error originates in the macro `unsupported_literals` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:81:14 - | -LL | let ${concat("", "")}: () = (); - | ^^^^^^^^^^^^^^^^ -... -LL | empty!(); - | -------- in this macro invocation - | - = note: this error originates in the macro `empty` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("\u{00BD}"); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("\x41"); - | --------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("🤷"); - | ------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("d[-_-]b"); - | ------------------------------ in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("-1"); - | ------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("1.0"); - | -------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-syntax-errors.rs:103:16 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | bad_literal_string!("'1'"); - | -------------------------- in this macro invocation - | - = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-syntax-errors.rs:116:31 - | -LL | const ${concat(_foo, $literal)}: () = (); - | ^^^^^^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-syntax-errors.rs:127:31 - | -LL | const ${concat(_foo, $tt)}: () = (); - | ^^ - | - = note: currently only string literals are supported - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-syntax-errors.rs:127:31 - | -LL | const ${concat(_foo, $tt)}: () = (); - | ^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-syntax-errors.rs:127:31 - | -LL | const ${concat(_foo, $tt)}: () = (); - | ^^ - | - = note: currently only string literals are supported - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 33 previous errors - 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..f86a2328da2 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-usage-errors.rs @@ -0,0 +1,168 @@ +#![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($ident, 'b')}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat($ident, 1)}: () = (); + //~^ 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'); +} diff --git a/tests/ui/macros/metavar-expressions/concat-usage-errors.stderr b/tests/ui/macros/metavar-expressions/concat-usage-errors.stderr new file mode 100644 index 00000000000..629843ecbda --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-usage-errors.stderr @@ -0,0 +1,284 @@ +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:5:10 + | +LL | ${concat()} + | ^^^^^^^^^^ + +error: `concat` must have at least two elements + --> $DIR/concat-usage-errors.rs:8:11 + | +LL | ${concat(aaaa)} + | ^^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:11:10 + | +LL | ${concat(aaaa,)} + | ^^^^^^^^^^^^^^^ + +error: expected comma + --> $DIR/concat-usage-errors.rs:16:10 + | +LL | ${concat(aaaa aaaa)} + | ^^^^^^^^^^^^^^^^^^^ + +error: `concat` must have at least two elements + --> $DIR/concat-usage-errors.rs:19:11 + | +LL | ${concat($ex)} + | ^^^^^^ + +error: expected comma + --> $DIR/concat-usage-errors.rs:25:10 + | +LL | ${concat($ex, aaaa 123)} + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:28:10 + | +LL | ${concat($ex, aaaa,)} + | ^^^^^^^^^^^^^^^^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:88:26 + | +LL | let ${concat(_a, 'b')}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:91:26 + | +LL | let ${concat(_a, 1)}: () = (); + | ^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:94:30 + | +LL | let ${concat($ident, 'b')}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:96:30 + | +LL | let ${concat($ident, 1)}: () = (); + | ^ + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-usage-errors.rs:22:19 + | +LL | ${concat($ex, aaaa)} + | ^^ + | + = note: currently only string literals are supported + +error: variable `foo` is not recognized in meta-variable expression + --> $DIR/concat-usage-errors.rs:35:30 + | +LL | const ${concat(FOO, $foo)}: i32 = 2; + | ^^^ + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:42:14 + | +LL | let ${concat("1", $ident)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^ +... +LL | starting_number!(_abc); + | ---------------------- in this macro invocation + | + = note: this error originates in the macro `starting_number` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:55:14 + | +LL | let ${concat("\u{00BD}", $ident)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | starting_invalid_unicode!(_abc); + | ------------------------------- in this macro invocation + | + = note: this error originates in the macro `starting_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:74:14 + | +LL | let ${concat($ident, "\u{00BD}")}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | ending_invalid_unicode!(_abc); + | ----------------------------- in this macro invocation + | + = note: this error originates in the macro `ending_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected pattern, found `$` + --> $DIR/concat-usage-errors.rs:88:13 + | +LL | let ${concat(_a, 'b')}: () = (); + | ^ expected pattern +... +LL | unsupported_literals!(_abc); + | --------------------------- in this macro invocation + | + = note: this error originates in the macro `unsupported_literals` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:81:14 + | +LL | let ${concat("", "")}: () = (); + | ^^^^^^^^^^^^^^^^ +... +LL | empty!(); + | -------- in this macro invocation + | + = note: this error originates in the macro `empty` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("\u{00BD}"); + | ------------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("\x41"); + | --------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("🤷"); + | ------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("d[-_-]b"); + | ------------------------------ in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("-1"); + | ------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("1.0"); + | -------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-usage-errors.rs:103:16 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | bad_literal_string!("'1'"); + | -------------------------- in this macro invocation + | + = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-usage-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-usage-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-usage-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-usage-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-usage-errors.rs:116:31 + | +LL | const ${concat(_foo, $literal)}: () = (); + | ^^^^^^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-usage-errors.rs:127:31 + | +LL | const ${concat(_foo, $tt)}: () = (); + | ^^ + | + = note: currently only string literals are supported + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-usage-errors.rs:127:31 + | +LL | const ${concat(_foo, $tt)}: () = (); + | ^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` + --> $DIR/concat-usage-errors.rs:127:31 + | +LL | const ${concat(_foo, $tt)}: () = (); + | ^^ + | + = note: currently only string literals are supported + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 33 previous errors + diff --git a/tests/ui/macros/metavar-expressions/syntax-errors.rs b/tests/ui/macros/metavar-expressions/syntax-errors.rs index 78cede92526..8735da352d8 100644 --- a/tests/ui/macros/metavar-expressions/syntax-errors.rs +++ b/tests/ui/macros/metavar-expressions/syntax-errors.rs @@ -1,62 +1,48 @@ -#![feature(macro_metavar_expr)] - -// `curly` = Right hand side curly brackets -// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function" -// `round` = Left hand side round brackets - -macro_rules! curly__no_rhs_dollar__round { - ( $( $i:ident ),* ) => { ${ count($i) } }; -} +// General syntax errors that apply to all matavariable expressions +// +// We don't invoke the macros here to ensure code gets rejected at the definition rather than +// only when expanded. -macro_rules! curly__no_rhs_dollar__no_round { - ( $i:ident ) => { ${ count($i) } }; - //~^ ERROR `count` can not be placed inside the innermost repetition -} +#![feature(macro_metavar_expr)] -macro_rules! curly__rhs_dollar__no_round { - ( $i:ident ) => { ${ count($i) } }; - //~^ ERROR `count` can not be placed inside the innermost repetition +macro_rules! dollar_dollar_in_the_lhs { + ( $$ $a:ident ) => { + //~^ ERROR unexpected token: $ + }; } -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__no_rhs_dollar__round { - ( $( $i:ident ),* ) => { count(i) }; - //~^ ERROR cannot find function `count` in this scope - //~| ERROR cannot find value `i` in this scope +macro_rules! metavar_in_the_lhs { + ( ${ len() } ) => { + //~^ ERROR unexpected token: { + //~| ERROR expected one of: `*`, `+`, or `?` + }; } -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__no_rhs_dollar__no_round { - ( $i:ident ) => { count(i) }; - //~^ ERROR cannot find function `count` in this scope - //~| ERROR cannot find value `i` in this scope +macro_rules! metavar_token_without_ident { + ( $( $i:ident ),* ) => { ${ ignore() } }; + //~^ ERROR meta-variable expressions must be referenced using a dollar sign } -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__rhs_dollar__round { - ( $( $i:ident ),* ) => { count($i) }; - //~^ ERROR variable `i` is still repeating at this depth +macro_rules! metavar_with_literal_suffix { + ( $( $i:ident ),* ) => { ${ index(1u32) } }; + //~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions } -#[rustfmt::skip] // autoformatters can break a few of the error traces -macro_rules! no_curly__rhs_dollar__no_round { - ( $i:ident ) => { count($i) }; - //~^ ERROR cannot find function `count` in this scope +macro_rules! metavar_without_parens { + ( $( $i:ident ),* ) => { ${ count{i} } }; + //~^ ERROR meta-variable expression parameter must be wrapped in parentheses } -// Other scenarios - -macro_rules! dollar_dollar_in_the_lhs { - ( $$ $a:ident ) => { - //~^ ERROR unexpected token: $ - }; +#[rustfmt::skip] +macro_rules! open_brackets_without_tokens { + ( $( $i:ident ),* ) => { ${ {} } }; + //~^ ERROR expected identifier } macro_rules! extra_garbage_after_metavar { ( $( $i:ident ),* ) => { ${count() a b c} //~^ ERROR unexpected token: a - //~| ERROR expected expression, found `$` ${count($i a b c)} //~^ ERROR unexpected token: a ${count($i, 1 a b c)} @@ -85,46 +71,12 @@ const IDX: usize = 1; macro_rules! metavar_depth_is_not_literal { ( $( $i:ident ),* ) => { ${ index(IDX) } }; //~^ ERROR meta-variable expression depth must be a literal - //~| ERROR expected expression, found `$` -} - -macro_rules! metavar_in_the_lhs { - ( ${ len() } ) => { - //~^ ERROR unexpected token: { - //~| ERROR expected one of: `*`, `+`, or `?` - }; -} - -macro_rules! metavar_token_without_ident { - ( $( $i:ident ),* ) => { ${ ignore() } }; - //~^ ERROR meta-variable expressions must be referenced using a dollar sign - //~| ERROR expected expression -} - -macro_rules! metavar_with_literal_suffix { - ( $( $i:ident ),* ) => { ${ index(1u32) } }; - //~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions - //~| ERROR expected expression, found `$` -} - -macro_rules! metavar_without_parens { - ( $( $i:ident ),* ) => { ${ count{i} } }; - //~^ ERROR meta-variable expression parameter must be wrapped in parentheses - //~| ERROR expected expression, found `$` -} - -#[rustfmt::skip] -macro_rules! open_brackets_without_tokens { - ( $( $i:ident ),* ) => { ${ {} } }; - //~^ ERROR expected expression, found `$` - //~| ERROR expected identifier } macro_rules! unknown_count_ident { ( $( $i:ident )* ) => { ${count(foo)} //~^ ERROR meta-variable expressions must be referenced using a dollar sign - //~| ERROR expected expression }; } @@ -132,33 +84,12 @@ macro_rules! unknown_ignore_ident { ( $( $i:ident )* ) => { ${ignore(bar)} //~^ ERROR meta-variable expressions must be referenced using a dollar sign - //~| ERROR expected expression }; } macro_rules! unknown_metavar { ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; //~^ ERROR unrecognized meta-variable expression - //~| ERROR expected expression } -fn main() { - curly__no_rhs_dollar__round!(a, b, c); - curly__no_rhs_dollar__no_round!(a); - curly__rhs_dollar__no_round!(a); - no_curly__no_rhs_dollar__round!(a, b, c); - no_curly__no_rhs_dollar__no_round!(a); - no_curly__rhs_dollar__round!(a, b, c); - no_curly__rhs_dollar__no_round!(a); - //~^ ERROR cannot find value `a` in this scope - - extra_garbage_after_metavar!(a); - metavar_depth_is_not_literal!(a); - metavar_token_without_ident!(a); - metavar_with_literal_suffix!(a); - metavar_without_parens!(a); - open_brackets_without_tokens!(a); - unknown_count_ident!(a); - unknown_ignore_ident!(a); - unknown_metavar!(a); -} +fn main() {} diff --git a/tests/ui/macros/metavar-expressions/syntax-errors.stderr b/tests/ui/macros/metavar-expressions/syntax-errors.stderr index d9646760cea..291e27924c8 100644 --- a/tests/ui/macros/metavar-expressions/syntax-errors.stderr +++ b/tests/ui/macros/metavar-expressions/syntax-errors.stderr @@ -1,382 +1,200 @@ error: unexpected token: $ - --> $DIR/syntax-errors.rs:50:8 + --> $DIR/syntax-errors.rs:9:8 | LL | ( $$ $a:ident ) => { | ^ note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions - --> $DIR/syntax-errors.rs:50:8 + --> $DIR/syntax-errors.rs:9:8 | LL | ( $$ $a:ident ) => { | ^ +error: unexpected token: { + --> $DIR/syntax-errors.rs:15:8 + | +LL | ( ${ len() } ) => { + | ^^^^^^^^^ + +note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions + --> $DIR/syntax-errors.rs:15:8 + | +LL | ( ${ len() } ) => { + | ^^^^^^^^^ + +error: expected one of: `*`, `+`, or `?` + --> $DIR/syntax-errors.rs:15:8 + | +LL | ( ${ len() } ) => { + | ^^^^^^^^^ + +error: meta-variables within meta-variable expressions must be referenced using a dollar sign + --> $DIR/syntax-errors.rs:22:33 + | +LL | ( $( $i:ident ),* ) => { ${ ignore() } }; + | ^^^^^^ + +error: only unsuffixes integer literals are supported in meta-variable expressions + --> $DIR/syntax-errors.rs:27:33 + | +LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; + | ^^^^^ + +error: meta-variable expression parameter must be wrapped in parentheses + --> $DIR/syntax-errors.rs:32:33 + | +LL | ( $( $i:ident ),* ) => { ${ count{i} } }; + | ^^^^^ + error: unexpected token: a - --> $DIR/syntax-errors.rs:57:19 + --> $DIR/syntax-errors.rs:44:19 | LL | ${count() a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:57:19 + --> $DIR/syntax-errors.rs:44:19 | LL | ${count() a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:60:20 + --> $DIR/syntax-errors.rs:46:20 | LL | ${count($i a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:60:20 + --> $DIR/syntax-errors.rs:46:20 | LL | ${count($i a b c)} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:62:23 + --> $DIR/syntax-errors.rs:48:23 | LL | ${count($i, 1 a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:62:23 + --> $DIR/syntax-errors.rs:48:23 | LL | ${count($i, 1 a b c)} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:64:21 + --> $DIR/syntax-errors.rs:50:21 | LL | ${count($i) a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:64:21 + --> $DIR/syntax-errors.rs:50:21 | LL | ${count($i) a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:67:22 + --> $DIR/syntax-errors.rs:53:22 | LL | ${ignore($i) a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:67:22 + --> $DIR/syntax-errors.rs:53:22 | LL | ${ignore($i) a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:69:21 + --> $DIR/syntax-errors.rs:55:21 | LL | ${ignore($i a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:69:21 + --> $DIR/syntax-errors.rs:55:21 | LL | ${ignore($i a b c)} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:72:19 + --> $DIR/syntax-errors.rs:58:19 | LL | ${index() a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:72:19 + --> $DIR/syntax-errors.rs:58:19 | LL | ${index() a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:74:19 + --> $DIR/syntax-errors.rs:60:19 | LL | ${index(1 a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:74:19 + --> $DIR/syntax-errors.rs:60:19 | LL | ${index(1 a b c)} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:77:19 + --> $DIR/syntax-errors.rs:63:19 | LL | ${index() a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:77:19 + --> $DIR/syntax-errors.rs:63:19 | LL | ${index() a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:79:19 + --> $DIR/syntax-errors.rs:65:19 | LL | ${index(1 a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:79:19 + --> $DIR/syntax-errors.rs:65:19 | LL | ${index(1 a b c)} | ^ error: meta-variable expression depth must be a literal - --> $DIR/syntax-errors.rs:86:33 + --> $DIR/syntax-errors.rs:72:33 | LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; | ^^^^^ -error: unexpected token: { - --> $DIR/syntax-errors.rs:92:8 - | -LL | ( ${ len() } ) => { - | ^^^^^^^^^ - -note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions - --> $DIR/syntax-errors.rs:92:8 - | -LL | ( ${ len() } ) => { - | ^^^^^^^^^ - -error: expected one of: `*`, `+`, or `?` - --> $DIR/syntax-errors.rs:92:8 - | -LL | ( ${ len() } ) => { - | ^^^^^^^^^ - -error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:99:33 - | -LL | ( $( $i:ident ),* ) => { ${ ignore() } }; - | ^^^^^^ - -error: only unsuffixes integer literals are supported in meta-variable expressions - --> $DIR/syntax-errors.rs:105:33 - | -LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; - | ^^^^^ - -error: meta-variable expression parameter must be wrapped in parentheses - --> $DIR/syntax-errors.rs:111:33 - | -LL | ( $( $i:ident ),* ) => { ${ count{i} } }; - | ^^^^^ - error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:125:11 + --> $DIR/syntax-errors.rs:78:11 | LL | ${count(foo)} | ^^^^^ error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:133:11 + --> $DIR/syntax-errors.rs:85:11 | LL | ${ignore(bar)} | ^^^^^^ error: unrecognized meta-variable expression - --> $DIR/syntax-errors.rs:140:33 + --> $DIR/syntax-errors.rs:91:33 | LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; | ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and len error: expected identifier or string literal - --> $DIR/syntax-errors.rs:118:33 + --> $DIR/syntax-errors.rs:38:33 | LL | ( $( $i:ident ),* ) => { ${ {} } }; | ^^ -error: `count` can not be placed inside the innermost repetition - --> $DIR/syntax-errors.rs:12:24 - | -LL | ( $i:ident ) => { ${ count($i) } }; - | ^^^^^^^^^^^^^ - -error: `count` can not be placed inside the innermost repetition - --> $DIR/syntax-errors.rs:17:24 - | -LL | ( $i:ident ) => { ${ count($i) } }; - | ^^^^^^^^^^^^^ - -error: variable `i` is still repeating at this depth - --> $DIR/syntax-errors.rs:37:36 - | -LL | ( $( $i:ident ),* ) => { count($i) }; - | ^^ - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:57:9 - | -LL | ${count() a b c} - | ^ expected expression -... -LL | extra_garbage_after_metavar!(a); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `extra_garbage_after_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:86:30 - | -LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; - | ^ expected expression -... -LL | metavar_depth_is_not_literal!(a); - | -------------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_depth_is_not_literal` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:99:30 - | -LL | ( $( $i:ident ),* ) => { ${ ignore() } }; - | ^ expected expression -... -LL | metavar_token_without_ident!(a); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_token_without_ident` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:105:30 - | -LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; - | ^ expected expression -... -LL | metavar_with_literal_suffix!(a); - | ------------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_with_literal_suffix` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:111:30 - | -LL | ( $( $i:ident ),* ) => { ${ count{i} } }; - | ^ expected expression -... -LL | metavar_without_parens!(a); - | -------------------------- in this macro invocation - | - = note: this error originates in the macro `metavar_without_parens` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:118:30 - | -LL | ( $( $i:ident ),* ) => { ${ {} } }; - | ^ expected expression -... -LL | open_brackets_without_tokens!(a); - | -------------------------------- in this macro invocation - | - = note: this error originates in the macro `open_brackets_without_tokens` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:125:9 - | -LL | ${count(foo)} - | ^ expected expression -... -LL | unknown_count_ident!(a); - | ----------------------- in this macro invocation - | - = note: this error originates in the macro `unknown_count_ident` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:133:9 - | -LL | ${ignore(bar)} - | ^ expected expression -... -LL | unknown_ignore_ident!(a); - | ------------------------ in this macro invocation - | - = note: this error originates in the macro `unknown_ignore_ident` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected expression, found `$` - --> $DIR/syntax-errors.rs:140:30 - | -LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; - | ^ expected expression -... -LL | unknown_metavar!(a); - | ------------------- in this macro invocation - | - = note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find value `i` in this scope - --> $DIR/syntax-errors.rs:23:36 - | -LL | ( $( $i:ident ),* ) => { count(i) }; - | ^ not found in this scope -... -LL | no_curly__no_rhs_dollar__round!(a, b, c); - | ---------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find value `i` in this scope - --> $DIR/syntax-errors.rs:30:29 - | -LL | ( $i:ident ) => { count(i) }; - | ^ not found in this scope -... -LL | no_curly__no_rhs_dollar__no_round!(a); - | ------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find value `a` in this scope - --> $DIR/syntax-errors.rs:152:37 - | -LL | ( $i:ident ) => { count($i) }; - | -- due to this macro variable -... -LL | no_curly__rhs_dollar__no_round!(a); - | ^ not found in this scope - -error[E0425]: cannot find function `count` in this scope - --> $DIR/syntax-errors.rs:23:30 - | -LL | ( $( $i:ident ),* ) => { count(i) }; - | ^^^^^ not found in this scope -... -LL | no_curly__no_rhs_dollar__round!(a, b, c); - | ---------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find function `count` in this scope - --> $DIR/syntax-errors.rs:30:23 - | -LL | ( $i:ident ) => { count(i) }; - | ^^^^^ not found in this scope -... -LL | no_curly__no_rhs_dollar__no_round!(a); - | ------------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0425]: cannot find function `count` in this scope - --> $DIR/syntax-errors.rs:43:23 - | -LL | ( $i:ident ) => { count($i) }; - | ^^^^^ not found in this scope -... -LL | no_curly__rhs_dollar__no_round!(a); - | ---------------------------------- in this macro invocation - | - = note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 39 previous errors +error: aborting due to 21 previous errors -For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/macros/metavar-expressions/usage-errors.rs b/tests/ui/macros/metavar-expressions/usage-errors.rs new file mode 100644 index 00000000000..feff02e2ce4 --- /dev/null +++ b/tests/ui/macros/metavar-expressions/usage-errors.rs @@ -0,0 +1,55 @@ +// Errors for the `count` and `length` metavariable expressions + +#![feature(macro_metavar_expr)] + +// `curly` = Right hand side curly brackets +// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function" +// `round` = Left hand side round brackets + +macro_rules! curly__no_rhs_dollar__round { + ( $( $i:ident ),* ) => { ${ count($i) } }; +} +const _: u32 = curly__no_rhs_dollar__round!(a, b, c); + +macro_rules! curly__no_rhs_dollar__no_round { + ( $i:ident ) => { ${ count($i) } }; + //~^ ERROR `count` can not be placed inside the innermost repetition +} +curly__no_rhs_dollar__no_round!(a); + +macro_rules! curly__rhs_dollar__no_round { + ( $i:ident ) => { ${ count($i) } }; + //~^ ERROR `count` can not be placed inside the innermost repetition +} +curly__rhs_dollar__no_round !(a); + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__no_rhs_dollar__round { + ( $( $i:ident ),* ) => { count(i) }; + //~^ ERROR missing `fn` or `struct` for function or struct definition +} +no_curly__no_rhs_dollar__round !(a, b, c); + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__no_rhs_dollar__no_round { + ( $i:ident ) => { count(i) }; + //~^ ERROR missing `fn` or `struct` for function or struct definition +} +no_curly__no_rhs_dollar__no_round !(a); + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__rhs_dollar__round { + ( $( $i:ident ),* ) => { count($i) }; + //~^ ERROR variable `i` is still repeating at this depth +} +no_curly__rhs_dollar__round! (a); + +#[rustfmt::skip] // autoformatters can break a few of the error traces +macro_rules! no_curly__rhs_dollar__no_round { + ( $i:ident ) => { count($i) }; + //~^ ERROR cannot find function `count` in this scope +} +const _: u32 = no_curly__rhs_dollar__no_round! (a); +//~^ ERROR cannot find value `a` in this scope + +fn main() {} diff --git a/tests/ui/macros/metavar-expressions/usage-errors.stderr b/tests/ui/macros/metavar-expressions/usage-errors.stderr new file mode 100644 index 00000000000..f66f522e23b --- /dev/null +++ b/tests/ui/macros/metavar-expressions/usage-errors.stderr @@ -0,0 +1,71 @@ +error: `count` can not be placed inside the innermost repetition + --> $DIR/usage-errors.rs:15:24 + | +LL | ( $i:ident ) => { ${ count($i) } }; + | ^^^^^^^^^^^^^ + +error: `count` can not be placed inside the innermost repetition + --> $DIR/usage-errors.rs:21:24 + | +LL | ( $i:ident ) => { ${ count($i) } }; + | ^^^^^^^^^^^^^ + +error: missing `fn` or `struct` for function or struct definition + --> $DIR/usage-errors.rs:28:30 + | +LL | ( $( $i:ident ),* ) => { count(i) }; + | ^^^^^ +... +LL | no_curly__no_rhs_dollar__round !(a, b, c); + | ----------------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) +help: if you meant to call a macro, try + | +LL | ( $( $i:ident ),* ) => { count!(i) }; + | + + +error: missing `fn` or `struct` for function or struct definition + --> $DIR/usage-errors.rs:35:23 + | +LL | ( $i:ident ) => { count(i) }; + | ^^^^^ +... +LL | no_curly__no_rhs_dollar__no_round !(a); + | -------------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) +help: if you meant to call a macro, try + | +LL | ( $i:ident ) => { count!(i) }; + | + + +error: variable `i` is still repeating at this depth + --> $DIR/usage-errors.rs:42:36 + | +LL | ( $( $i:ident ),* ) => { count($i) }; + | ^^ + +error[E0425]: cannot find value `a` in this scope + --> $DIR/usage-errors.rs:52:49 + | +LL | ( $i:ident ) => { count($i) }; + | -- due to this macro variable +... +LL | const _: u32 = no_curly__rhs_dollar__no_round! (a); + | ^ not found in this scope + +error[E0425]: cannot find function `count` in this scope + --> $DIR/usage-errors.rs:49:23 + | +LL | ( $i:ident ) => { count($i) }; + | ^^^^^ not found in this scope +... +LL | const _: u32 = no_curly__rhs_dollar__no_round! (a); + | ----------------------------------- in this macro invocation + | + = note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0425`. -- cgit 1.4.1-3-g733a5 From b3d74da9b8edb47b9b785afb7ac9f1a9a1841835 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 23 Jun 2025 00:42:06 -0500 Subject: mbe: Extend metavariable expression tests Add tests showing the current state to make it more clear when output gets updated later in refactoring. --- .../metavar-expressions/concat-trace-errors.rs | 33 ++++++ .../metavar-expressions/concat-trace-errors.stderr | 24 ++++ .../metavar-expressions/concat-usage-errors.rs | 22 ++++ .../metavar-expressions/concat-usage-errors.stderr | 128 +++++++++++++++------ .../ui/macros/metavar-expressions/syntax-errors.rs | 26 ++++- .../metavar-expressions/syntax-errors.stderr | 76 +++++++----- 6 files changed, 247 insertions(+), 62 deletions(-) create mode 100644 tests/ui/macros/metavar-expressions/concat-trace-errors.rs create mode 100644 tests/ui/macros/metavar-expressions/concat-trace-errors.stderr diff --git a/tests/ui/macros/metavar-expressions/concat-trace-errors.rs b/tests/ui/macros/metavar-expressions/concat-trace-errors.rs new file mode 100644 index 00000000000..45407f5e86d --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-trace-errors.rs @@ -0,0 +1,33 @@ +// Our diagnostics should be able to point to a specific input that caused an invalid +// identifier. + +#![feature(macro_metavar_expr_concat)] + +// See what we can do without expanding anything +macro_rules! pre_expansion { + ($a:ident) => { + ${concat("hi", " bye ")}; + ${concat("hi", "-", "bye")}; + ${concat($a, "-")}; + } +} + +macro_rules! post_expansion { + ($a:literal) => { + const _: () = ${concat("hi", $a, "bye")}; + //~^ ERROR is not generating a valid identifier + } +} + +post_expansion!("!"); + +macro_rules! post_expansion_many { + ($a:ident, $b:ident, $c:ident, $d:literal, $e:ident) => { + const _: () = ${concat($a, $b, $c, $d, $e)}; + //~^ ERROR is not generating a valid identifier + } +} + +post_expansion_many!(a, b, c, ".d", e); + +fn main() {} diff --git a/tests/ui/macros/metavar-expressions/concat-trace-errors.stderr b/tests/ui/macros/metavar-expressions/concat-trace-errors.stderr new file mode 100644 index 00000000000..dac8b58a15c --- /dev/null +++ b/tests/ui/macros/metavar-expressions/concat-trace-errors.stderr @@ -0,0 +1,24 @@ +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-trace-errors.rs:17:24 + | +LL | const _: () = ${concat("hi", $a, "bye")}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | post_expansion!("!"); + | -------------------- in this macro invocation + | + = note: this error originates in the macro `post_expansion` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/concat-trace-errors.rs:26:24 + | +LL | const _: () = ${concat($a, $b, $c, $d, $e)}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | post_expansion_many!(a, b, c, ".d", e); + | -------------------------------------- in this macro invocation + | + = note: this error originates in the macro `post_expansion_many` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + diff --git a/tests/ui/macros/metavar-expressions/concat-usage-errors.rs b/tests/ui/macros/metavar-expressions/concat-usage-errors.rs index f86a2328da2..7d8756de9e2 100644 --- a/tests/ui/macros/metavar-expressions/concat-usage-errors.rs +++ b/tests/ui/macros/metavar-expressions/concat-usage-errors.rs @@ -1,3 +1,5 @@ +//@ edition: 2021 + #![feature(macro_metavar_expr_concat)] macro_rules! syntax_errors { @@ -90,11 +92,31 @@ macro_rules! unsupported_literals { //~| 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 }}; } diff --git a/tests/ui/macros/metavar-expressions/concat-usage-errors.stderr b/tests/ui/macros/metavar-expressions/concat-usage-errors.stderr index 629843ecbda..8be3e792ec3 100644 --- a/tests/ui/macros/metavar-expressions/concat-usage-errors.stderr +++ b/tests/ui/macros/metavar-expressions/concat-usage-errors.stderr @@ -1,71 +1,131 @@ error: expected identifier or string literal - --> $DIR/concat-usage-errors.rs:5:10 + --> $DIR/concat-usage-errors.rs:7:10 | LL | ${concat()} | ^^^^^^^^^^ error: `concat` must have at least two elements - --> $DIR/concat-usage-errors.rs:8:11 + --> $DIR/concat-usage-errors.rs:10:11 | LL | ${concat(aaaa)} | ^^^^^^ error: expected identifier or string literal - --> $DIR/concat-usage-errors.rs:11:10 + --> $DIR/concat-usage-errors.rs:13:10 | LL | ${concat(aaaa,)} | ^^^^^^^^^^^^^^^ error: expected comma - --> $DIR/concat-usage-errors.rs:16:10 + --> $DIR/concat-usage-errors.rs:18:10 | LL | ${concat(aaaa aaaa)} | ^^^^^^^^^^^^^^^^^^^ error: `concat` must have at least two elements - --> $DIR/concat-usage-errors.rs:19:11 + --> $DIR/concat-usage-errors.rs:21:11 | LL | ${concat($ex)} | ^^^^^^ error: expected comma - --> $DIR/concat-usage-errors.rs:25:10 + --> $DIR/concat-usage-errors.rs:27:10 | LL | ${concat($ex, aaaa 123)} | ^^^^^^^^^^^^^^^^^^^^^^^ error: expected identifier or string literal - --> $DIR/concat-usage-errors.rs:28:10 + --> $DIR/concat-usage-errors.rs:30:10 | LL | ${concat($ex, aaaa,)} | ^^^^^^^^^^^^^^^^^^^^ error: expected identifier or string literal - --> $DIR/concat-usage-errors.rs:88:26 + --> $DIR/concat-usage-errors.rs:90:26 | LL | let ${concat(_a, 'b')}: () = (); | ^^^ error: expected identifier or string literal - --> $DIR/concat-usage-errors.rs:91:26 + --> $DIR/concat-usage-errors.rs:93:26 | LL | let ${concat(_a, 1)}: () = (); | ^ error: expected identifier or string literal - --> $DIR/concat-usage-errors.rs:94:30 + --> $DIR/concat-usage-errors.rs:95:26 + | +LL | let ${concat(_a, 1.5)}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:97:26 + | +LL | let ${concat(_a, c"hi")}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:99:26 + | +LL | let ${concat(_a, b"hi")}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:101:26 + | +LL | let ${concat(_a, b'b')}: () = (); + | ^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:103:26 + | +LL | let ${concat(_a, b'b')}: () = (); + | ^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:106:30 | LL | let ${concat($ident, 'b')}: () = (); | ^^^ error: expected identifier or string literal - --> $DIR/concat-usage-errors.rs:96:30 + --> $DIR/concat-usage-errors.rs:108:30 | LL | let ${concat($ident, 1)}: () = (); | ^ +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:110:30 + | +LL | let ${concat($ident, 1.5)}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:112:30 + | +LL | let ${concat($ident, c"hi")}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:114:30 + | +LL | let ${concat($ident, b"hi")}: () = (); + | ^^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:116:30 + | +LL | let ${concat($ident, b'b')}: () = (); + | ^^^^ + +error: expected identifier or string literal + --> $DIR/concat-usage-errors.rs:118:30 + | +LL | let ${concat($ident, b'b')}: () = (); + | ^^^^ + error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-usage-errors.rs:22:19 + --> $DIR/concat-usage-errors.rs:24:19 | LL | ${concat($ex, aaaa)} | ^^ @@ -73,13 +133,13 @@ LL | ${concat($ex, aaaa)} = note: currently only string literals are supported error: variable `foo` is not recognized in meta-variable expression - --> $DIR/concat-usage-errors.rs:35:30 + --> $DIR/concat-usage-errors.rs:37:30 | LL | const ${concat(FOO, $foo)}: i32 = 2; | ^^^ error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:42:14 + --> $DIR/concat-usage-errors.rs:44:14 | LL | let ${concat("1", $ident)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^ @@ -90,7 +150,7 @@ LL | starting_number!(_abc); = note: this error originates in the macro `starting_number` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:55:14 + --> $DIR/concat-usage-errors.rs:57:14 | LL | let ${concat("\u{00BD}", $ident)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -101,7 +161,7 @@ LL | starting_invalid_unicode!(_abc); = note: this error originates in the macro `starting_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:74:14 + --> $DIR/concat-usage-errors.rs:76:14 | LL | let ${concat($ident, "\u{00BD}")}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +172,7 @@ LL | ending_invalid_unicode!(_abc); = note: this error originates in the macro `ending_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) error: expected pattern, found `$` - --> $DIR/concat-usage-errors.rs:88:13 + --> $DIR/concat-usage-errors.rs:90:13 | LL | let ${concat(_a, 'b')}: () = (); | ^ expected pattern @@ -123,7 +183,7 @@ LL | unsupported_literals!(_abc); = note: this error originates in the macro `unsupported_literals` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:81:14 + --> $DIR/concat-usage-errors.rs:83:14 | LL | let ${concat("", "")}: () = (); | ^^^^^^^^^^^^^^^^ @@ -134,7 +194,7 @@ LL | empty!(); = note: this error originates in the macro `empty` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +205,7 @@ LL | bad_literal_string!("\u{00BD}"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,7 +216,7 @@ LL | bad_literal_string!("\x41"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -167,7 +227,7 @@ LL | bad_literal_string!("🤷"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -178,7 +238,7 @@ LL | bad_literal_string!("d[-_-]b"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +249,7 @@ LL | bad_literal_string!("-1"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -200,7 +260,7 @@ LL | bad_literal_string!("1.0"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: `${concat(..)}` is not generating a valid identifier - --> $DIR/concat-usage-errors.rs:103:16 + --> $DIR/concat-usage-errors.rs:125:16 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -211,7 +271,7 @@ LL | bad_literal_string!("'1'"); = note: this error originates in the macro `bad_literal_string` (in Nightly builds, run with -Z macro-backtrace for more info) error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-usage-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -219,7 +279,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: currently only string literals are supported error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-usage-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -228,7 +288,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-usage-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -237,7 +297,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-usage-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -246,7 +306,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-usage-errors.rs:116:31 + --> $DIR/concat-usage-errors.rs:138:31 | LL | const ${concat(_foo, $literal)}: () = (); | ^^^^^^^ @@ -255,7 +315,7 @@ LL | const ${concat(_foo, $literal)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-usage-errors.rs:127:31 + --> $DIR/concat-usage-errors.rs:149:31 | LL | const ${concat(_foo, $tt)}: () = (); | ^^ @@ -263,7 +323,7 @@ LL | const ${concat(_foo, $tt)}: () = (); = note: currently only string literals are supported error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-usage-errors.rs:127:31 + --> $DIR/concat-usage-errors.rs:149:31 | LL | const ${concat(_foo, $tt)}: () = (); | ^^ @@ -272,7 +332,7 @@ LL | const ${concat(_foo, $tt)}: () = (); = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt` - --> $DIR/concat-usage-errors.rs:127:31 + --> $DIR/concat-usage-errors.rs:149:31 | LL | const ${concat(_foo, $tt)}: () = (); | ^^ @@ -280,5 +340,5 @@ LL | const ${concat(_foo, $tt)}: () = (); = note: currently only string literals are supported = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 33 previous errors +error: aborting due to 43 previous errors diff --git a/tests/ui/macros/metavar-expressions/syntax-errors.rs b/tests/ui/macros/metavar-expressions/syntax-errors.rs index 8735da352d8..8fc76a74baa 100644 --- a/tests/ui/macros/metavar-expressions/syntax-errors.rs +++ b/tests/ui/macros/metavar-expressions/syntax-errors.rs @@ -28,13 +28,35 @@ macro_rules! metavar_with_literal_suffix { //~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions } -macro_rules! metavar_without_parens { +macro_rules! mve_without_parens { + ( $( $i:ident ),* ) => { ${ count } }; + //~^ ERROR meta-variable expression parameter must be wrapped in parentheses +} + +#[rustfmt::skip] +macro_rules! empty_expression { + () => { ${} }; + //~^ ERROR expected identifier or string literal +} + +#[rustfmt::skip] +macro_rules! open_brackets_with_lit { + () => { ${ "hi" } }; + //~^ ERROR expected identifier + } + +macro_rules! mve_wrong_delim { ( $( $i:ident ),* ) => { ${ count{i} } }; //~^ ERROR meta-variable expression parameter must be wrapped in parentheses } +macro_rules! invalid_metavar { + () => { ${ignore($123)} } + //~^ ERROR expected identifier, found `123` +} + #[rustfmt::skip] -macro_rules! open_brackets_without_tokens { +macro_rules! open_brackets_with_group { ( $( $i:ident ),* ) => { ${ {} } }; //~^ ERROR expected identifier } diff --git a/tests/ui/macros/metavar-expressions/syntax-errors.stderr b/tests/ui/macros/metavar-expressions/syntax-errors.stderr index 291e27924c8..20d2358facc 100644 --- a/tests/ui/macros/metavar-expressions/syntax-errors.stderr +++ b/tests/ui/macros/metavar-expressions/syntax-errors.stderr @@ -43,158 +43,182 @@ LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; error: meta-variable expression parameter must be wrapped in parentheses --> $DIR/syntax-errors.rs:32:33 | +LL | ( $( $i:ident ),* ) => { ${ count } }; + | ^^^^^ + +error: meta-variable expression parameter must be wrapped in parentheses + --> $DIR/syntax-errors.rs:49:33 + | LL | ( $( $i:ident ),* ) => { ${ count{i} } }; | ^^^^^ +error: expected identifier, found `123` + --> $DIR/syntax-errors.rs:54:23 + | +LL | () => { ${ignore($123)} } + | ^^^ help: try removing `123` + error: unexpected token: a - --> $DIR/syntax-errors.rs:44:19 + --> $DIR/syntax-errors.rs:66:19 | LL | ${count() a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:44:19 + --> $DIR/syntax-errors.rs:66:19 | LL | ${count() a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:46:20 + --> $DIR/syntax-errors.rs:68:20 | LL | ${count($i a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:46:20 + --> $DIR/syntax-errors.rs:68:20 | LL | ${count($i a b c)} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:48:23 + --> $DIR/syntax-errors.rs:70:23 | LL | ${count($i, 1 a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:48:23 + --> $DIR/syntax-errors.rs:70:23 | LL | ${count($i, 1 a b c)} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:50:21 + --> $DIR/syntax-errors.rs:72:21 | LL | ${count($i) a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:50:21 + --> $DIR/syntax-errors.rs:72:21 | LL | ${count($i) a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:53:22 + --> $DIR/syntax-errors.rs:75:22 | LL | ${ignore($i) a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:53:22 + --> $DIR/syntax-errors.rs:75:22 | LL | ${ignore($i) a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:55:21 + --> $DIR/syntax-errors.rs:77:21 | LL | ${ignore($i a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:55:21 + --> $DIR/syntax-errors.rs:77:21 | LL | ${ignore($i a b c)} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:58:19 + --> $DIR/syntax-errors.rs:80:19 | LL | ${index() a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:58:19 + --> $DIR/syntax-errors.rs:80:19 | LL | ${index() a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:60:19 + --> $DIR/syntax-errors.rs:82:19 | LL | ${index(1 a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:60:19 + --> $DIR/syntax-errors.rs:82:19 | LL | ${index(1 a b c)} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:63:19 + --> $DIR/syntax-errors.rs:85:19 | LL | ${index() a b c} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:63:19 + --> $DIR/syntax-errors.rs:85:19 | LL | ${index() a b c} | ^ error: unexpected token: a - --> $DIR/syntax-errors.rs:65:19 + --> $DIR/syntax-errors.rs:87:19 | LL | ${index(1 a b c)} | ^ | note: meta-variable expression must not have trailing tokens - --> $DIR/syntax-errors.rs:65:19 + --> $DIR/syntax-errors.rs:87:19 | LL | ${index(1 a b c)} | ^ error: meta-variable expression depth must be a literal - --> $DIR/syntax-errors.rs:72:33 + --> $DIR/syntax-errors.rs:94:33 | LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; | ^^^^^ error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:78:11 + --> $DIR/syntax-errors.rs:100:11 | LL | ${count(foo)} | ^^^^^ error: meta-variables within meta-variable expressions must be referenced using a dollar sign - --> $DIR/syntax-errors.rs:85:11 + --> $DIR/syntax-errors.rs:107:11 | LL | ${ignore(bar)} | ^^^^^^ error: unrecognized meta-variable expression - --> $DIR/syntax-errors.rs:91:33 + --> $DIR/syntax-errors.rs:113:33 | LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; | ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and len error: expected identifier or string literal - --> $DIR/syntax-errors.rs:38:33 + --> $DIR/syntax-errors.rs:38:14 + | +LL | () => { ${} }; + | ^^ + +error: expected identifier, found `"hi"` + --> $DIR/syntax-errors.rs:44:17 + | +LL | () => { ${ "hi" } }; + | ^^^^ help: try removing `"hi"` + +error: expected identifier or string literal + --> $DIR/syntax-errors.rs:60:33 | LL | ( $( $i:ident ),* ) => { ${ {} } }; | ^^ -error: aborting due to 21 previous errors +error: aborting due to 25 previous errors -- cgit 1.4.1-3-g733a5 From 128945fdbf737cba3eaa33ae8663c6dd3f45e363 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 21 Jun 2025 03:46:54 -0400 Subject: mbe: Shorten `MetaVarExpr` -> `Mve` in structural diagnostics More diagnostic structs related to metavariable expressions will be introduced. Introduce the abbreviation "mve" which is reasonably unambiguous (`rg Mve` and `rg '(\b|_|-)mve(\b|_|-)'` return no results outside of a Thumb target feature) and use it for these diagnostic types. A new module is also created. --- compiler/rustc_expand/messages.ftl | 6 +++--- compiler/rustc_expand/src/errors.rs | 21 +++++++++++++-------- compiler/rustc_expand/src/mbe/transcribe.rs | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_expand/messages.ftl b/compiler/rustc_expand/messages.ftl index 8b7c47dad99..85ded855e6c 100644 --- a/compiler/rustc_expand/messages.ftl +++ b/compiler/rustc_expand/messages.ftl @@ -109,9 +109,6 @@ expand_malformed_feature_attribute = expand_meta_var_dif_seq_matchers = {$msg} -expand_meta_var_expr_unrecognized_var = - variable `{$key}` is not recognized in meta-variable expression - expand_missing_fragment_specifier = missing fragment specifier .note = fragment specifiers must be provided .suggestion_add_fragspec = try adding a specifier here @@ -136,6 +133,9 @@ expand_module_multiple_candidates = expand_must_repeat_once = this must repeat at least once +expand_mve_unrecognized_var = + variable `{$key}` is not recognized in meta-variable expression + expand_non_inline_modules_in_proc_macro_input_are_unstable = non-inline modules in proc macro input are unstable diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index 714ba3bf0f4..0d77916d4cf 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -27,14 +27,6 @@ pub(crate) struct CountRepetitionMisplaced { pub span: Span, } -#[derive(Diagnostic)] -#[diag(expand_meta_var_expr_unrecognized_var)] -pub(crate) struct MetaVarExprUnrecognizedVar { - #[primary_span] - pub span: Span, - pub key: MacroRulesNormalizedIdent, -} - #[derive(Diagnostic)] #[diag(expand_var_still_repeating)] pub(crate) struct VarStillRepeating { @@ -500,3 +492,16 @@ pub(crate) struct ProcMacroBackCompat { pub crate_name: String, pub fixed_version: String, } + +pub(crate) use metavar_exprs::*; +mod metavar_exprs { + use super::*; + + #[derive(Diagnostic)] + #[diag(expand_mve_unrecognized_var)] + pub(crate) struct MveUnrecognizedVar { + #[primary_span] + pub span: Span, + pub key: MacroRulesNormalizedIdent, + } +} diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 0520be5fbae..1781a0c0771 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -17,7 +17,7 @@ use rustc_span::{ use smallvec::{SmallVec, smallvec}; use crate::errors::{ - CountRepetitionMisplaced, MetaVarExprUnrecognizedVar, MetaVarsDifSeqMatchers, MustRepeatOnce, + CountRepetitionMisplaced, MetaVarsDifSeqMatchers, MustRepeatOnce, MveUnrecognizedVar, NoSyntaxVarsExprRepeat, VarStillRepeating, }; use crate::mbe::macro_parser::NamedMatch; @@ -879,7 +879,7 @@ where { let span = ident.span; let key = MacroRulesNormalizedIdent::new(ident); - interp.get(&key).ok_or_else(|| dcx.create_err(MetaVarExprUnrecognizedVar { span, key })) + interp.get(&key).ok_or_else(|| dcx.create_err(MveUnrecognizedVar { span, key })) } /// Used by meta-variable expressions when an user input is out of the actual declared bounds. For -- cgit 1.4.1-3-g733a5 From 3d9e5104610dfef38f6772b097baa8fa2d6a60c1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 20 Jun 2025 17:08:38 -0400 Subject: mbe: Factor `concat` metavariable handling out Move the `concat` implementation to a separate function so it is easier to work on. Other metavariable expressions are already split this way. This is a non-functional change. --- compiler/rustc_expand/src/mbe/metavar_expr.rs | 85 ++++++++++++++------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/metavar_expr.rs b/compiler/rustc_expand/src/mbe/metavar_expr.rs index 1ccb070f83a..396d65b6f9d 100644 --- a/compiler/rustc_expand/src/mbe/metavar_expr.rs +++ b/compiler/rustc_expand/src/mbe/metavar_expr.rs @@ -47,46 +47,7 @@ impl MetaVarExpr { check_trailing_token(&mut iter, psess)?; let mut iter = args.iter(); let rslt = match ident.as_str() { - "concat" => { - let mut result = Vec::new(); - loop { - let is_var = try_eat_dollar(&mut iter); - let token = parse_token(&mut iter, psess, outer_span)?; - let element = if is_var { - MetaVarExprConcatElem::Var(parse_ident_from_token(psess, token)?) - } else if let TokenKind::Literal(Lit { - kind: token::LitKind::Str, - symbol, - suffix: None, - }) = token.kind - { - MetaVarExprConcatElem::Literal(symbol) - } else { - match parse_ident_from_token(psess, token) { - Err(err) => { - err.cancel(); - return Err(psess - .dcx() - .struct_span_err(token.span, UNSUPPORTED_CONCAT_ELEM_ERR)); - } - Ok(elem) => MetaVarExprConcatElem::Ident(elem), - } - }; - result.push(element); - if iter.peek().is_none() { - break; - } - if !try_eat_comma(&mut iter) { - return Err(psess.dcx().struct_span_err(outer_span, "expected comma")); - } - } - if result.len() < 2 { - return Err(psess - .dcx() - .struct_span_err(ident.span, "`concat` must have at least two elements")); - } - MetaVarExpr::Concat(result.into()) - } + "concat" => parse_concat(&mut iter, psess, outer_span, ident.span)?, "count" => parse_count(&mut iter, psess, ident.span)?, "ignore" => { eat_dollar(&mut iter, psess, ident.span)?; @@ -156,6 +117,50 @@ fn check_trailing_token<'psess>( } } +/// Parse a meta-variable `concat` expression: `concat($metavar, ident, ...)`. +fn parse_concat<'psess>( + iter: &mut TokenStreamIter<'_>, + psess: &'psess ParseSess, + outer_span: Span, + expr_ident_span: Span, +) -> PResult<'psess, MetaVarExpr> { + let mut result = Vec::new(); + loop { + let is_var = try_eat_dollar(iter); + let token = parse_token(iter, psess, outer_span)?; + let element = if is_var { + MetaVarExprConcatElem::Var(parse_ident_from_token(psess, token)?) + } else if let TokenKind::Literal(Lit { kind: token::LitKind::Str, symbol, suffix: None }) = + token.kind + { + MetaVarExprConcatElem::Literal(symbol) + } else { + match parse_ident_from_token(psess, token) { + Err(err) => { + err.cancel(); + return Err(psess + .dcx() + .struct_span_err(token.span, UNSUPPORTED_CONCAT_ELEM_ERR)); + } + Ok(elem) => MetaVarExprConcatElem::Ident(elem), + } + }; + result.push(element); + if iter.peek().is_none() { + break; + } + if !try_eat_comma(iter) { + return Err(psess.dcx().struct_span_err(outer_span, "expected comma")); + } + } + if result.len() < 2 { + return Err(psess + .dcx() + .struct_span_err(expr_ident_span, "`concat` must have at least two elements")); + } + Ok(MetaVarExpr::Concat(result.into())) +} + /// Parse a meta-variable `count` expression: `count(ident[, depth])` fn parse_count<'psess>( iter: &mut TokenStreamIter<'_>, -- cgit 1.4.1-3-g733a5 From a1a066999b9fbfc10e93931d9a552bf87dc32e4d Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 20 Jun 2025 17:10:57 -0400 Subject: mbe: Move `MetaVarExprConcatElem` closer to where it is used Move this structure directly above the `parse_` functions that return it to keep top-down flow. This is a non-functional change. --- compiler/rustc_expand/src/mbe/metavar_expr.rs | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/metavar_expr.rs b/compiler/rustc_expand/src/mbe/metavar_expr.rs index 396d65b6f9d..ffd3548019a 100644 --- a/compiler/rustc_expand/src/mbe/metavar_expr.rs +++ b/compiler/rustc_expand/src/mbe/metavar_expr.rs @@ -87,20 +87,6 @@ impl MetaVarExpr { } } -/// Indicates what is placed in a `concat` parameter. For example, literals -/// (`${concat("foo", "bar")}`) or adhoc identifiers (`${concat(foo, bar)}`). -#[derive(Debug, Decodable, Encodable, PartialEq)] -pub(crate) enum MetaVarExprConcatElem { - /// Identifier WITHOUT a preceding dollar sign, which means that this identifier should be - /// interpreted as a literal. - Ident(Ident), - /// For example, a number or a string. - Literal(Symbol), - /// Identifier WITH a preceding dollar sign, which means that this identifier should be - /// expanded and interpreted as a variable. - Var(Ident), -} - // Checks if there are any remaining tokens. For example, `${ignore(ident ... a b c ...)}` fn check_trailing_token<'psess>( iter: &mut TokenStreamIter<'_>, @@ -117,6 +103,20 @@ fn check_trailing_token<'psess>( } } +/// Indicates what is placed in a `concat` parameter. For example, literals +/// (`${concat("foo", "bar")}`) or adhoc identifiers (`${concat(foo, bar)}`). +#[derive(Debug, Decodable, Encodable, PartialEq)] +pub(crate) enum MetaVarExprConcatElem { + /// Identifier WITHOUT a preceding dollar sign, which means that this identifier should be + /// interpreted as a literal. + Ident(Ident), + /// For example, a number or a string. + Literal(Symbol), + /// Identifier WITH a preceding dollar sign, which means that this identifier should be + /// expanded and interpreted as a variable. + Var(Ident), +} + /// Parse a meta-variable `concat` expression: `concat($metavar, ident, ...)`. fn parse_concat<'psess>( iter: &mut TokenStreamIter<'_>, -- cgit 1.4.1-3-g733a5 From 18a621abe4d8e1cb32cd2b3f04a26c483816e985 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 30 Jun 2025 15:45:08 -0500 Subject: Upgrade dependencies in run-make-support The main purpose of this is to upgrade `object` and `gimli`, which will allow us to drop outdated versions once backtrace also updates. The only semver breakage in `object`'s is in `elf::R_RISCV_GNU_*` and `pe::IMAGE_WEAK_EXTERN_*` constants, as well as Mach-O dyld, which don't appear to be used here. `gimli` is similar, there is only minor breakage related to dyld. These version upgrades were also done in the library. `bstr`, `similar`, and `regex` are also upgraded to the latest minor version here to match what the lockfile already uses. The `regex` comment about `memchr` version hasn't been relevant to this lockfile since e95d15a11519 ("Pin memchr to 2.5.0 in the library rather than rustc_ast") and is no longer relevant in the library lockfile either. Object Changelog: https://github.com/gimli-rs/object/blob/master/CHANGELOG.md#0370 Gimli changelog: https://github.com/gimli-rs/gimli/blob/master/CHANGELOG.md#0320 --- Cargo.lock | 44 ++++++++++++++++++++++++++++------- src/tools/run-make-support/Cargo.toml | 10 ++++---- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 110d17142bb..da3eb92ece8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ - "gimli", + "gimli 0.31.1", ] [[package]] @@ -1483,6 +1483,17 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "gimli" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93563d740bc9ef04104f9ed6f86f1e3275c2cdafb95664e26584b9ca807a8ffe" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + [[package]] name = "glob" version = "0.3.2" @@ -2568,7 +2579,7 @@ dependencies = [ "hashbrown", "indexmap", "memchr", - "ruzstd", + "ruzstd 0.7.3", ] [[package]] @@ -2578,9 +2589,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03fd943161069e1768b4b3d050890ba48730e590f57e56d4aa04e7e090e61b4a" dependencies = [ "crc32fast", + "flate2", "hashbrown", "indexmap", "memchr", + "ruzstd 0.8.1", "wasmparser 0.234.0", ] @@ -3194,9 +3207,9 @@ version = "0.2.0" dependencies = [ "bstr", "build_helper", - "gimli", + "gimli 0.32.0", "libc", - "object 0.36.7", + "object 0.37.1", "regex", "serde_json", "similar", @@ -3498,7 +3511,7 @@ name = "rustc_codegen_llvm" version = "0.0.0" dependencies = [ "bitflags", - "gimli", + "gimli 0.31.1", "itertools", "libc", "measureme", @@ -4473,7 +4486,7 @@ dependencies = [ "rustc_target", "rustc_trait_selection", "tracing", - "twox-hash", + "twox-hash 1.6.3", ] [[package]] @@ -4857,7 +4870,16 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fad02996bfc73da3e301efe90b1837be9ed8f4a462b6ed410aa35d00381de89f" dependencies = [ - "twox-hash", + "twox-hash 1.6.3", +] + +[[package]] +name = "ruzstd" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3640bec8aad418d7d03c72ea2de10d5c646a598f9883c7babc160d91e3c1b26c" +dependencies = [ + "twox-hash 2.1.1", ] [[package]] @@ -5338,7 +5360,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e9c1e705f82a260173f3eec93f2ff6d7807f23ad5a8cc2e7316a891733ea7a1" dependencies = [ - "gimli", + "gimli 0.31.1", "hashbrown", "object 0.36.7", "tracing", @@ -5580,6 +5602,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "twox-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b907da542cbced5261bd3256de1b3a1bf340a3d37f93425a07362a1d687de56" + [[package]] name = "type-map" version = "0.5.1" diff --git a/src/tools/run-make-support/Cargo.toml b/src/tools/run-make-support/Cargo.toml index 15ed03ad5c2..3226f467ba4 100644 --- a/src/tools/run-make-support/Cargo.toml +++ b/src/tools/run-make-support/Cargo.toml @@ -4,12 +4,12 @@ version = "0.2.0" edition = "2021" [dependencies] -bstr = "1.6.0" -object = "0.36.2" -similar = "2.5.0" +bstr = "1.12" +object = "0.37" +similar = "2.7" wasmparser = { version = "0.219", default-features = false, features = ["std"] } -regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace -gimli = "0.31.0" +regex = "1.11" +gimli = "0.32" build_helper = { path = "../../build_helper" } serde_json = "1.0" libc = "0.2" -- cgit 1.4.1-3-g733a5 From 4e83298ae845a15e2d2dbb800921cfe0b09d4765 Mon Sep 17 00:00:00 2001 From: Dan Johnson Date: Mon, 30 Jun 2025 14:58:47 -0700 Subject: linkify CodeSuggestion in doc comments --- compiler/rustc_errors/src/diagnostic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 8da7cdd9358..fe9797026de 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -1005,7 +1005,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// * may look like "to do xyz, use" or "to do xyz, use abc" /// * may contain a name of a function, variable, or type, but not whole expressions /// - /// See `CodeSuggestion` for more information. + /// See [`CodeSuggestion`] for more information. #[rustc_lint_diagnostics] pub fn span_suggestion( &mut self, @@ -1166,7 +1166,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// Prints out a message with a suggested edit of the code. If the suggestion is presented /// inline, it will only show the message and not the suggestion. /// - /// See `CodeSuggestion` for more information. + /// See [`CodeSuggestion`] for more information. #[rustc_lint_diagnostics] pub fn span_suggestion_short( &mut self, -- cgit 1.4.1-3-g733a5 From c8fac7779e75c16cfb49d7bb95809dbb6e19d5f7 Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Thu, 26 Jun 2025 18:21:47 -0600 Subject: fix: Emit suggestion filename if primary diagnostic span is dummy --- compiler/rustc_errors/src/emitter.rs | 4 +++- tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index e333de4b660..3f5872f34a6 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2078,7 +2078,9 @@ impl HumanEmitter { // file name, saving in verbosity, but if it *isn't* we do need it, otherwise we're // telling users to make a change but not clarifying *where*. let loc = sm.lookup_char_pos(parts[0].span.lo()); - if loc.file.name != sm.span_to_filename(span) && loc.file.name.is_real() { + if (span.is_dummy() || loc.file.name != sm.span_to_filename(span)) + && loc.file.name.is_real() + { // --> file.rs:line:col // | let arrow = self.file_start(); diff --git a/tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr b/tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr index a9b45a18af3..f53e9e3b478 100644 --- a/tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr +++ b/tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr @@ -2,6 +2,7 @@ error[E0259]: the name `std` is defined multiple times | = note: `std` must be defined only once in the type namespace of this module help: you can use `as` to change the binding name of the import + --> $DIR/resolve-conflict-extern-crate-vs-extern-crate.rs:1:17 | LL | extern crate std as other_std; | ++++++++++++ -- cgit 1.4.1-3-g733a5