Can't use `usize::unchecked_mul()` because "checked mul is not supported yet"
还没有人认领这个 Issue。
评估
调研方向
复现 shader 编译失败,然后从 core/src/num/mod.rs 开始,跟踪 usize::unchecked_mul 经过 assert_unsafe_precondition! 和 overflowing_mul 的调用路径。将该路径与 Layout::repeat 进行比较,并确定支持 checked multiplication 或禁用 unsafe preconditions 是否能解决报告的错误;当 reproducer 成功编译时即表示完成。
由索引模型根据 Issue 内容生成。
描述
I've stumbled upon this while trying to use core::alloc::Layout type in my shader code.
You see, Layout::repeat() function uses checked math to return an error, but in my case this should not be possible, so I've reimplemented it using usize::unchecked_mul().
I expected my code to compile, but got this compiler error instead:
error: checked mul is not supported yet
--> ***\.rustup\toolchains\nightly-2025-06-30-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\num\mod.rs:1224:5
|
1224 | / uint_impl! {
1225 | | Self = usize,
1226 | | ActualT = u32,
1227 | | SignedT = isize,
... |
1241 | | bound_condition = " on 32-bit targets",
1242 | | }
| |_____^
|
note: used from within `<usize>::overflowing_mul`
--> ***\.rustup\toolchains\nightly-2025-06-30-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\num\mod.rs:1224:5
|
1224 | / uint_impl! {
1225 | | Self = usize,
1226 | | ActualT = u32,
1227 | | SignedT = isize,
... |
1241 | | bound_condition = " on 32-bit targets",
1242 | | }
| |_____^
note: called by `<usize>::unchecked_mul::precondition_check`
--> ***\.rustup\toolchains\nightly-2025-06-30-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\num\mod.rs:1224:5
|
1224 | / uint_impl! {
1225 | | Self = usize,
1226 | | ActualT = u32,
1227 | | SignedT = isize,
... |
1241 | | bound_condition = " on 32-bit targets",
1242 | | }
| |_____^
note: called by `<usize>::unchecked_mul`
--> ***\.rustup\toolchains\nightly-2025-06-30-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\num\mod.rs:1224:5
|
1224 | / uint_impl! {
1225 | | Self = usize,
1226 | | ActualT = u32,
1227 | | SignedT = isize,
... |
1241 | | bound_condition = " on 32-bit targets",
1242 | | }
| |_____^
note:
I guess it tries to compile assert_unsafe_precondition! macro call which contains a call to usize::overflowing_mul() (which is used to do checked multiplication), and fails to do so.
I thought it should be compiled out because I'm compiling my shader in release mode (as by default) which suggests that debug_assertions are set to false (which should disable unsafe preconditions), but it seems this is not the case here.
I think it will be best to resolve such issue by implementing checked mul (as it is already implemented in Zig SPIR-V compiler, which I guess was the inspiration for rust-gpu's checked math functions)...
But if it is possible to disable unsafe preconditions completely, I can do just that.
- 主要语言
- Rust
- 星标
- 3.4k
- 派生
- 127
- 平均合并
- 1 小时 44 分钟
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Rust-GPU/rust-gpu 的其他 Issue
-
enhancement
难度 1/5 1 小时以内 新手友好度 68/100
-
Adhere to Rust floating-point semantics可能已有人在做 @Firestar99 于 18 天前认领。 未关闭enhancement
-
bug
难度 4/5 3-5 天 新手友好度 48/100
-
bug
难度 3/5 1-2 天 新手友好度 48/100
-
bug
难度 4/5 3-5 天 新手友好度 48/100
查看 Rust-GPU/rust-gpu 的全部 Issue
相似的 Issue
-
bug CLI exec tool-calls
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
-
maintainer-needed p2 triaged ui windows
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
ai_p2
难度 2/5 1-3 小时 新手友好度 76/100
ClickHouse/ClickHouse#123351 ·
维护者通常 1 天内回复
-
documentation
难度 1/5 1 小时以内 新手友好度 92/100
github/copilot-sdk#2804 · 1 条评论 ·
维护者通常 1 天内回复