25 lines
688 B
Plaintext
25 lines
688 B
Plaintext
![]() |
== Why is this an issue?
|
||
|
|
||
|
Using ``++core::intrinsics::transmute++`` in a way that is not valid on any architecture leads to undefined behavior. This can result in unpredictable program behavior or crashes.
|
||
|
|
||
|
=== Code examples
|
||
|
|
||
|
==== Noncompliant code example
|
||
|
|
||
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
||
|
----
|
||
|
let ptr: *const T = core::intrinsics::transmute('x'); // Noncompliant: Invalid transmute operation.
|
||
|
----
|
||
|
|
||
|
==== Compliant solution
|
||
|
|
||
|
[source,rust,diff-id=1,diff-type=compliant]
|
||
|
----
|
||
|
let value: T = 'x' as T; // Compliant: Use a safe conversion method.
|
||
|
----
|
||
|
|
||
|
== Resources
|
||
|
=== Documentation
|
||
|
|
||
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#wrong_transmute
|