Skip to content

Avoid parser panics bubbling out to proc macros - #158256

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Mark-Simulacrum:no-panic-pm-parsing
Jun 30, 2026
Merged

Avoid parser panics bubbling out to proc macros#158256
rust-bors[bot] merged 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

@rustbotrustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2026
@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 22, 2026
@Mark-SimulacrumMark-Simulacrum changed the title Avoid panics bubbling out to proc macrosAvoid parser panics bubbling out to proc macrosJun 22, 2026
Comment threadtests/ui/proc-macro/auxiliary/nonfatal-parsing-body.rs Outdated
Comment threadtests/ui/proc-macro/auxiliary/nonfatal-parsing-body.rs Outdated
@bjorn3

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-borsBot 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-borsrust-borsBot 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-borsBot 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)
This was referenced Jun 23, 2026
rust-borsBot 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)
@jhprattjhpratt mentioned this pull request Jun 24, 2026
rust-borsBot 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)
@jhprattjhpratt mentioned this pull request Jun 24, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 25, 2026
…g, r=bjorn3
Avoid parser panics bubbling out to proc macros
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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 25, 2026
…g, r=bjorn3
Avoid parser panics bubbling out to proc macros
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
@rust-borsrust-borsBot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 25, 2026
@rust-bors

This comment has been minimized.

@rust-borsrust-borsBot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 25, 2026
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.
@rustbot

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-borsrust-borsBot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 29, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
…g, r=bjorn3
Avoid parser panics bubbling out to proc macros
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
@jhprattjhpratt mentioned this pull request Jun 29, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
…g, r=bjorn3
Avoid parser panics bubbling out to proc macros
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
@jhprattjhpratt mentioned this pull request Jun 29, 2026
rust-borsBot pushed a commit that referenced this pull request Jun 29, 2026
Rollup of 6 pull requests
Successful merges:
- #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
- #158256 (Avoid parser panics bubbling out to proc macros)
- #158081 (trait-system: Recover deferred closure calls after errors)
- #158323 (rustc: improve diagnostics for file-open failures)
- #158327 (Move attribute and keyword docs from `std` to `core`)
- #158468 (Include default-stability info in rustdoc JSON.)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
…g, r=bjorn3
Avoid parser panics bubbling out to proc macros
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
@jhprattjhpratt mentioned this pull request Jun 29, 2026
rust-borsBot pushed a commit that referenced this pull request Jun 29, 2026
Rollup of 12 pull requests
Successful merges:
- #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
- #158169 (Fix debuginfo compression in bootstrap)
- #158256 (Avoid parser panics bubbling out to proc macros)
- #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
- #158417 (Avoid ICE when cfg_eval recovers no item from derive input)
- #158556 (delegation: store child segment flag in `PathSegment`)
- #158561 (Avoid building rustdoc for tests without doctests)
- #158562 (Improve tracing of steps in bootstrap)
- #157445 (Allow section override when using patchable-function-entries)
- #158081 (trait-system: Recover deferred closure calls after errors)
- #158327 (Move attribute and keyword docs from `std` to `core`)
- #158468 (Include default-stability info in rustdoc JSON.)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
…g, r=bjorn3
Avoid parser panics bubbling out to proc macros
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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
…g, r=bjorn3
Avoid parser panics bubbling out to proc macros
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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
…g, r=bjorn3
Avoid parser panics bubbling out to proc macros
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
rust-borsBot pushed a commit that referenced this pull request Jun 29, 2026
…uwer
Rollup of 16 pull requests
Successful merges:
- #155722 (Introduce aarch64-unknown-linux-pauthtest target)
- #156230 (tests: check wasm compiler_builtins object architecture)
- #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
- #158169 (Fix debuginfo compression in bootstrap)
- #158256 (Avoid parser panics bubbling out to proc macros)
- #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
- #158556 (delegation: store child segment flag in `PathSegment`)
- #158561 (Avoid building rustdoc for tests without doctests)
- #158562 (Improve tracing of steps in bootstrap)
- #157445 (Allow section override when using patchable-function-entries)
- #158081 (trait-system: Recover deferred closure calls after errors)
- #158327 (Move attribute and keyword docs from `std` to `core`)
- #158468 (Include default-stability info in rustdoc JSON.)
- #158564 (fix `-Z min-recursion-limit` unstable chapter name)
- #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
- #158582 (Comment on needed RAM in huge-stacks.rs)
rust-borsBot pushed a commit that referenced this pull request Jun 30, 2026
…uwer
Rollup of 16 pull requests
Successful merges:
- #155722 (Introduce aarch64-unknown-linux-pauthtest target)
- #156230 (tests: check wasm compiler_builtins object architecture)
- #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
- #158169 (Fix debuginfo compression in bootstrap)
- #158256 (Avoid parser panics bubbling out to proc macros)
- #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
- #158556 (delegation: store child segment flag in `PathSegment`)
- #158561 (Avoid building rustdoc for tests without doctests)
- #158562 (Improve tracing of steps in bootstrap)
- #157445 (Allow section override when using patchable-function-entries)
- #158081 (trait-system: Recover deferred closure calls after errors)
- #158327 (Move attribute and keyword docs from `std` to `core`)
- #158468 (Include default-stability info in rustdoc JSON.)
- #158564 (fix `-Z min-recursion-limit` unstable chapter name)
- #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
- #158582 (Comment on needed RAM in huge-stacks.rs)
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors try jobs=dist-x86_64-msvc

@rust-bors

This comment has been minimized.

rust-borsBot pushed a commit that referenced this pull request Jun 30, 2026
Avoid parser panics bubbling out to proc macros
try-job: dist-x86_64-msvc
rust-borsBot pushed a commit that referenced this pull request Jun 30, 2026
…uwer
Rollup of 7 pull requests
Successful merges:
- #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
- #158256 (Avoid parser panics bubbling out to proc macros)
- #158561 (Avoid building rustdoc for tests without doctests)
- #158562 (Improve tracing of steps in bootstrap)
- #157445 (Allow section override when using patchable-function-entries)
- #158327 (Move attribute and keyword docs from `std` to `core`)
- #158591 (Fix spacing issue for unused parentheses lint)
rust-borsBot pushed a commit that referenced this pull request Jun 30, 2026
…uwer
Rollup of 7 pull requests
Successful merges:
- #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
- #158256 (Avoid parser panics bubbling out to proc macros)
- #158561 (Avoid building rustdoc for tests without doctests)
- #158562 (Improve tracing of steps in bootstrap)
- #157445 (Allow section override when using patchable-function-entries)
- #158327 (Move attribute and keyword docs from `std` to `core`)
- #158591 (Fix spacing issue for unused parentheses lint)
@rust-bors

rust-borsBot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: f1cacf9 (f1cacf993512b1e15709042333950d0a9108bc4a)
Base parent: 0966944 (096694416a41840709140eb0fd0ca193d1a3e6ba)

rust-borsBot pushed a commit that referenced this pull request Jun 30, 2026
…uwer
Rollup of 7 pull requests
Successful merges:
- #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
- #158256 (Avoid parser panics bubbling out to proc macros)
- #158561 (Avoid building rustdoc for tests without doctests)
- #158562 (Improve tracing of steps in bootstrap)
- #157445 (Allow section override when using patchable-function-entries)
- #158327 (Move attribute and keyword docs from `std` to `core`)
- #158591 (Fix spacing issue for unused parentheses lint)
rust-borsBot pushed a commit that referenced this pull request Jun 30, 2026
…uwer
Rollup of 7 pull requests
Successful merges:
- #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
- #158256 (Avoid parser panics bubbling out to proc macros)
- #158561 (Avoid building rustdoc for tests without doctests)
- #158562 (Improve tracing of steps in bootstrap)
- #157445 (Allow section override when using patchable-function-entries)
- #158327 (Move attribute and keyword docs from `std` to `core`)
- #158591 (Fix spacing issue for unused parentheses lint)
@rust-bors
rust-borsBot merged commit 3dc45e1 into rust-lang:mainJun 30, 2026
14 checks passed
@rustbotrustbot added this to the 1.98.0 milestone Jun 30, 2026
rust-timer added a commit that referenced this pull request Jun 30, 2026
Rollup merge of #158256 - Mark-Simulacrum:no-panic-pm-parsing, r=bjorn3
Avoid parser panics bubbling out to proc macros
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
bjorn3 pushed a commit to bjorn3/miri that referenced this pull request Jul 1, 2026
…uwer
Rollup of 7 pull requests
Successful merges:
- rust-lang/rust#158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
- rust-lang/rust#158256 (Avoid parser panics bubbling out to proc macros)
- rust-lang/rust#158561 (Avoid building rustdoc for tests without doctests)
- rust-lang/rust#158562 (Improve tracing of steps in bootstrap)
- rust-lang/rust#157445 (Allow section override when using patchable-function-entries)
- rust-lang/rust#158327 (Move attribute and keyword docs from `std` to `core`)
- rust-lang/rust#158591 (Fix spacing issue for unused parentheses lint)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

5 participants

@Mark-Simulacrum@bjorn3@rustbot@JonathanBrouwer@cyrgani