E0133
rust
type_error
ai_generated
true
error[E0133]: call to unsafe function is unsafe and requires unsafe block
ID: rust/e0133-unused-unsafe
90%Fix Rate
85%Confidence
1Evidence
2023-11-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.65.0 | active | — | — | — |
| 1.72.0 | active | — | — | — |
| 1.80.0 | active | — | — | — |
Root Cause
Calling a function marked as 'unsafe' without wrapping it in an 'unsafe {}' block.
generic中文
调用了标记为 'unsafe' 的函数,但没有将其包裹在 'unsafe {}' 块中。
Official Documentation
https://doc.rust-lang.org/stable/error_codes/E0133.htmlWorkarounds
-
95% success Wrap the unsafe call in an 'unsafe { ... }' block. Example: 'unsafe { std::ptr::read(ptr); }'
Wrap the unsafe call in an 'unsafe { ... }' block. Example: 'unsafe { std::ptr::read(ptr); }' -
85% success If the function has a safe wrapper, use that instead. E.g., use 'std::slice::from_raw_parts' via safe abstractions.
If the function has a safe wrapper, use that instead. E.g., use 'std::slice::from_raw_parts' via safe abstractions.
中文步骤
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.
Dead Ends
Common approaches that don't work:
-
70% fail
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% fail
Using '#[allow(unsafe_code)]' lint suppression — this only silences the warning, not the error, and doesn't make the code compile.