You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
c2rust produces invalid Rust code when translating compound literals involving pointers and expressions (e.g., condition--). The generated Rust code incorrectly declares a temporary variable as immutable (let) while attempting to create a mutable reference (&mut) to it, leading to a Rust compiler error.
The translated Rust code incorrectly declares a temporary variable (fresh0) as immutable and attempts to create a mutable reference to it, causing the following Rust compile-time error.
error[E0596]: cannot borrow `fresh0` as mutable, as it is not declared as mutable
--> src/runner.rs:7:46
|
7 | let mut single_value: *mut libc::c_int = &mut fresh0 as *mut libc::c_int;
| ^^^^^^^^^^^ cannot borrow as mutable
Observation
I think &(int){condition--} involves modifying condition, but the temporary value created by the compound literal (fresh0) does not need to be mutable, as it is never modified in the original C code. Instead, c2rust should declare fresh0 as immutable and adjust the pointer type accordingly to align with C semantics.
letmut condition: libc::c_int = 1as libc::c_int;let fresh0 = condition;// fresh0 is immutable
condition = condition - 1;// condition is decrementedlet single_value:*const libc::c_int = &fresh0;// Use a const pointer
The text was updated successfully, but these errors were encountered:
Description
c2rust
produces invalid Rust code when translating compound literals involving pointers and expressions (e.g.,condition--
). The generated Rust code incorrectly declares a temporary variable as immutable (let
) while attempting to create a mutable reference (&mut
) to it, leading to a Rust compiler error.Source C code
Expected Behavior
c2rust
should generate valid Rust code that handles the mutability requirements of the compound literal, resulting in successful compilation.Translated Rust code
Cargo build failure
The translated Rust code incorrectly declares a temporary variable
(fresh0)
as immutable and attempts to create a mutable reference to it, causing the following Rust compile-time error.Observation
I think
&(int){condition--}
involves modifyingcondition
, but the temporary value created by the compound literal (fresh0
) does not need to be mutable, as it is never modified in the original C code. Instead,c2rust
should declarefresh0
as immutable and adjust the pointer type accordingly to align with C semantics.The text was updated successfully, but these errors were encountered: