Skip to content

fix:Fix MIR const evaluator panic due to incompatible integer operands. - #23046

Open
YUZHEthefool wants to merge 1 commit into
rust-lang:masterfrom
YUZHEthefool:fix-22954-const-eval-integer-mismatch
Open

fix:Fix MIR const evaluator panic due to incompatible integer operands.#23046
YUZHEthefool wants to merge 1 commit into
rust-lang:masterfrom
YUZHEthefool:fix-22954-const-eval-integer-mismatch

Conversation

@YUZHEthefool

@YUZHEthefool YUZHEthefool commented Aug 5, 2026

Copy link
Copy Markdown

错误代码让常量求值器收到了两种不兼容的整数表示。原实现默认它们一定相同,因此直接 panic;现在会先检查,不兼容时返回普通错误,避免 rust-analyzer 崩溃。
<The error code caused the constant evaluator to receive two incompatible representations of integers. The original implementation defaults that they must be the same, so it panics directly.
So now it will be checked first and return a normal error if it is incompatible to avoid rust-analyzer crashing.>
Fixed #22954

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

Copy link
Copy Markdown
Contributor

This is not the way. MIR eval is not at fault here. MIR lowering should fail on that code, and in fact any code that has a type checking error, but that is not implemented currently and perhaps will not suffice.

@YUZHEthefool
YUZHEthefool force-pushed the fix-22954-const-eval-integer-mismatch branch from ee89d32 to 3e4816e Compare August 6, 2026 01:43
@YUZHEthefool

YUZHEthefool commented Aug 6, 2026

Copy link
Copy Markdown
Author

根据您的反馈,我发现MIR lowering已经能区分builtin运算和成功解析的overloaded运算但是当“两者都不是”时依然错误地继续生成 CheckedBinaryOp,导致非法的MIR传递。
在进行测试时我发现部分合法 overloaded 运算没有记录method_resolution,因此更好的方式是inference结果中实际存在HAS_ERROR类型,所以我在整个body进入MIR lowering前统一返回HasErrors。
同时我删除了仅用于我个人测试的regression_22954,完善了fn overloaded_binop()测试的内容.

<Based on your feedback, I found that MIR lowering can already distinguish between builtin operations and successfully resolved overloaded operations. However, when an operation is neither, it still incorrectly proceeds to generate a CheckedBinaryOp, resulting in invalid MIR being passed on.

During testing, I also found that some valid overloaded operations do not have a corresponding method_resolution entry. Therefore, a better approach is to check whether the inference result actually contains a HAS_ERROR type and return HasErrors uniformly before lowering the body to MIR.

I also removed regression_22954, which was only used for my personal testing, and expanded the fn overloaded_binop() test.>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: incompatible integer types adding enum and int

3 participants