Skip to content

Commit

Permalink
(c2rust-analyze) Remove the slice rule for safe transmutability, as…
Browse files Browse the repository at this point in the history
… it's only sound for non-empty slices, but we can't check that at compile-time.
  • Loading branch information
kkysen committed Jun 8, 2023
1 parent 60a4376 commit 9b43bd6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 3 additions & 2 deletions c2rust-analyze/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,11 @@ impl<'a, T: ?Sized> PhantomLifetime<'a> for T {}
/// * `A = B => A ~ B`
/// * `A ~ B => *A ~ *B`
/// * `uN ~ iN`, `iN ~ uN`, where `N` is an integer width
/// * `A ~ B => [A] ~ B`
/// * `A ~ B, N > 0 => [A; N] ~ B`, where `const N: usize`
///
/// Note: `A ~ B => [A] ~ B` is not a rule because it would be unsound for zero-length slices,
/// which we cannot check unlike for arrays, which we need for translated string literals.
///
/// Thus, [`true`] means it is definitely transmutable,
/// while [`false`] means it may not be transmutable.
pub fn is_transmutable_to<'tcx>(from: Ty<'tcx>, to: Ty<'tcx>) -> bool {
Expand Down Expand Up @@ -404,7 +406,6 @@ pub fn is_transmutable_to<'tcx>(from: Ty<'tcx>, to: Ty<'tcx>) -> bool {
!is_zero
}
}
ty::Slice(from) => is_transmutable_to(from, to),
_ => false,
};

Expand Down
4 changes: 0 additions & 4 deletions c2rust-analyze/tests/analyze/string_casts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ pub fn deep_cast_ptr_to_ptr(x: *const *const u8) {
x as *const *const i8;
}

pub fn cast_slice_ptr_to_ptr(s: *const [u8]) {
s as *const u8;
}

/// For the below disabled (`#[cfg(any())]`ed) tests, they currently crash in the rewriter
/// due to it not being able to handle implicitly inserted `&raw` MIR statements yet.
/// Thus, they also have `*_explicit` versions where
Expand Down

0 comments on commit 9b43bd6

Please sign in to comment.