Skip to content

reduce the amount of panics in {TokenStream, Literal}::from_str calls#147859

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
cyrgani:nonfatal-tokenstream-parse
Feb 22, 2026
Merged

reduce the amount of panics in {TokenStream, Literal}::from_str calls#147859
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
cyrgani:nonfatal-tokenstream-parse

Conversation

@cyrgani
Copy link
Copy Markdown
Contributor

@cyrgani cyrgani commented Oct 18, 2025

View all comments

Before this PR, calling TokenStream::from_str or Literal::from_str with an invalid argument would always cause a compile error, even if the TokenStream is not used afterwards at all.
This PR changes this so it returns a LexError instead in some cases.

This is very theoretically a breaking change, but the doc comment on the impl already says

/// NOTE: some errors may cause panics instead of returning `LexError`. We reserve the right to
/// change these errors into `LexError`s later.

Fixes some cases of #58736.

Loading
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. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic in proc_macro::TokenStream::from_str