Skip to content

fix: return an error early for unsupported string binary operations - #23368

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
edragain2nd:fix/early_return_binary_op_error
Sep 15, 2026
Merged

ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
edragain2nd:fix/early_return_binary_op_error

Conversation

@edragain2nd

@edragain2nd edragain2nd commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

fixes #23338

the reproduce code can actually reach the never!() macro in function eval_rvalue()

if *op != BinOp::Eq {
    never!("Only eq is builtin for `str`");
}

so evaluation continues and cause an out-of-bounds slice access

and the if statement means no only the shift operation(mentioned in the issue), any non-eq operation can cause the same panic. (like + in the test case)

I think the panic case is rare, so adding an early return would be valuable instead of modifying slice access which is used specifically for Eq operation.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2026

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet again MIR we should have rejected for errors in inference... But that what we got for now.

Thanks!

View changes since this review

@ChayimFriedman2
ChayimFriedman2 added this pull request to the merge queue Sep 15, 2026
Merged via the queue into rust-lang:master with commit e29c5c8 Sep 15, 2026
20 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: struct with shift

3 participants