E0133
rust
type_error
ai_generated
true
错误[E0133]: 调用不安全函数是不安全的,需要 unsafe 块
error[E0133]: call to unsafe function is unsafe and requires unsafe block
ID: rust/e0133-unused-unsafe
90%修复率
85%置信度
1证据数
2023-11-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.65.0 | active | — | — | — |
| 1.72.0 | active | — | — | — |
| 1.80.0 | active | — | — | — |
根因分析
调用了标记为 'unsafe' 的函数,但没有将其包裹在 'unsafe {}' 块中。
English
Calling a function marked as 'unsafe' without wrapping it in an 'unsafe {}' block.
官方文档
https://doc.rust-lang.org/stable/error_codes/E0133.html解决方案
-
Wrap the unsafe call in an 'unsafe { ... }' block. Example: 'unsafe { std::ptr::read(ptr); }' -
If the function has a safe wrapper, use that instead. E.g., use 'std::slice::from_raw_parts' via safe abstractions.
无效尝试
常见但无效的做法:
-
70% 失败
Adding 'unsafe' to the function signature instead of wrapping the call in a block — this changes the function's contract but doesn't fix the call site.
-
90% 失败
Using '#[allow(unsafe_code)]' lint suppression — this only silences the warning, not the error, and doesn't make the code compile.