Skip to content

Avoid parser panics bubbling out to proc macros#158256

Open
Mark-Simulacrum wants to merge 1 commit into
rust-lang:mainfrom
Mark-Simulacrum:no-panic-pm-parsing
Open

Avoid parser panics bubbling out to proc macros#158256
Mark-Simulacrum wants to merge 1 commit into
rust-lang:mainfrom
Mark-Simulacrum:no-panic-pm-parsing

Conversation

@Mark-Simulacrum

Copy link
Copy Markdown
Member

Currently, rustc can emit a FatalError diagnostic during parsing of literals and tokenstreams. These are handled under the hood as a panic, which means that proc-macro code needed to catch_unwind if it wanted to fallibly parse some code. These still emit diagnostics, so in practice this isn't a full fix, but it at least makes the interface on the macro side a bit more uniform. The long-term fix should be to get rid of those FatalErrors (and in general all diagnostics that actually get emitted out during parsing, not just returned), but this seems like a reasonable improvement in the meantime.

This is primarily motivated by wasm proc macros which can't use catch_unwind and so this lets the test's output be the same with and without them.

r? bjorn3

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 22, 2026
@Mark-Simulacrum Mark-Simulacrum changed the title Avoid panics bubbling out to proc macros Avoid parser panics bubbling out to proc macros Jun 22, 2026
Comment thread tests/ui/proc-macro/auxiliary/nonfatal-parsing-body.rs Outdated
Comment thread tests/ui/proc-macro/auxiliary/nonfatal-parsing-body.rs Outdated
Currently, rustc can emit a FatalError diagnostic during parsing of
literals and tokenstreams. These are handled under the hood as a panic,
which means that proc-macro code needed to catch_unwind if it wanted to
fallibly parse some code. These still emit diagnostics, so in practice
this isn't a full fix, but it at least makes the interface on the macro
side a bit more uniform.

This is primarily motivated by wasm proc macros which can't use
catch_unwind and so this lets the test's output be the same with and
without them.
@bjorn3

bjorn3 commented Jun 23, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ca1224d has been approved by bjorn3

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 23, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #158020 (Update mingw-w64 C toolchain)
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158257 ( fix escaping placeholder check in next solver normalization folder)
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)

Failed merges:

 - #158256 (Avoid parser panics bubbling out to proc macros)
rust-bors Bot pushed a commit that referenced this pull request Jun 23, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #158020 (Update mingw-w64 C toolchain)
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158257 ( fix escaping placeholder check in next solver normalization folder)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)

Failed merges:

 - #158256 (Avoid parser panics bubbling out to proc macros)
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 27 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158257 ( fix escaping placeholder check in next solver normalization folder)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)

Failed merges:

 - #158256 (Avoid parser panics bubbling out to proc macros)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants