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 /compiler/rustc_interface/src/passes.rs | |
| 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 'compiler/rustc_interface/src/passes.rs')
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index fb6897c7d89..057fbe2fc4e 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -208,6 +208,10 @@ fn configure_and_expand( // Expand macros now! let krate = sess.time("expand_crate", || ecx.monotonic_expander().expand_crate(krate)); + if ecx.nb_macro_errors > 0 { + sess.dcx().abort_if_errors(); + } + // The rest is error reporting and stats sess.psess.buffered_lints.with_lock(|buffered_lints: &mut Vec<BufferedEarlyLint>| { |
