diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-07-26 22:42:35 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-26 22:42:35 -0400 |
| commit | c92d61d1210fb8da853d21a02b28fd45651d999d (patch) | |
| tree | 203e31f8f19b0d2e367d553a48ccc2a28bc0305b /tests/ui/rfcs | |
| parent | 2c395c77597e81b0f2058410427dd03970b6d7f8 (diff) | |
| parent | 272513868f0dbc76fc3d0f10adda86a013d51b5e (diff) | |
| download | rust-c92d61d1210fb8da853d21a02b28fd45651d999d.tar.gz rust-c92d61d1210fb8da853d21a02b28fd45651d999d.zip | |
Rollup merge of #144409 - GuillaumeGomez:macro-expansion-early-abort, r=oli-obk
Stop compilation early if macro expansion failed Fixes rust-lang/rust#116180. So there isn't really a type that is central for macro expansion and some errors are actually emitted (because the resolution happens after the expansion I suppose) after the expansion pass (like "not found macro"). Sometimes, errors are only emitted on the second "try" (to improve error output). So I couldn't reach a similar solution than what was done in https://github.com/rust-lang/rust/pull/133937 and suggested by ````@estebank```` in https://github.com/rust-lang/rust/issues/116180#issuecomment-3109468922. But maybe I missed something? So in the end, I realized that there is method called every time (except one, described below) a macro error is actually emitted: `ExtCtxt::trace_macros_diag`. Considering I updated what it did, I renamed it into `macro_error_and_trace_macros_diag` to better reflect it. There is only one call of `trace_macros_diag` which isn't reporting an error but just used for `macro_trace` feature, so I kept it as is. r? ````@oli-obk````
Diffstat (limited to 'tests/ui/rfcs')
4 files changed, 32 insertions, 18 deletions
diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate-macro.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate-macro.rs new file mode 100644 index 00000000000..9d86ebc5331 --- /dev/null +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate-macro.rs @@ -0,0 +1,14 @@ +// gate-test-if_let_guard + +fn main() { + macro_rules! use_expr { + ($e:expr) => { + match () { + () if $e => {} + _ => {} + } + } + } + use_expr!(let 0 = 1); + //~^ ERROR no rules expected keyword `let` +} diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate-macro.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate-macro.stderr new file mode 100644 index 00000000000..411fde890a1 --- /dev/null +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate-macro.stderr @@ -0,0 +1,17 @@ +error: no rules expected keyword `let` + --> $DIR/feature-gate-macro.rs:12:15 + | +LL | macro_rules! use_expr { + | --------------------- when calling this macro +... +LL | use_expr!(let 0 = 1); + | ^^^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$e:expr` + --> $DIR/feature-gate-macro.rs:5:10 + | +LL | ($e:expr) => { + | ^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs index b1e305834cb..eb9e5dff37e 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs @@ -64,8 +64,6 @@ fn _macros() { //~^ ERROR `if let` guards are experimental _ => {} } - use_expr!(let 0 = 1); - //~^ ERROR no rules expected keyword `let` } fn main() {} diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr index 19d1f4b0a57..759f1478350 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr @@ -149,21 +149,6 @@ LL | use_expr!((let 0 = 1)); = note: only supported directly in conditions of `if` and `while` expressions = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: no rules expected keyword `let` - --> $DIR/feature-gate.rs:67:15 - | -LL | macro_rules! use_expr { - | --------------------- when calling this macro -... -LL | use_expr!(let 0 = 1); - | ^^^ no rules expected this token in macro call - | -note: while trying to match meta-variable `$e:expr` - --> $DIR/feature-gate.rs:48:10 - | -LL | ($e:expr) => { - | ^^^^^^^ - error[E0658]: `if let` guards are experimental --> $DIR/feature-gate.rs:7:12 | @@ -230,6 +215,6 @@ LL | () if let 0 = 1 => {} = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>` -error: aborting due to 20 previous errors +error: aborting due to 19 previous errors For more information about this error, try `rustc --explain E0658`. |
