Rollup merge of #154425 - ujjwalvishwakarma2006:migrate-transmute-tests, r=Kivooeo,Teapot4195

Migrate transmute tests

I have made the following changes in this PR:

- `tests/ui/issues/issue-23477.rs` ➝ `tests/ui/transmute/transmute-slice-to-dst.rs`
- `tests/ui/issues/issue-28625.{rs,stderr}` ➝ `tests/ui/transmute/transmute-associated-type-to-slice.{rs,stderr}`

The reason I changed the trait name from `trait Bar` to `trait MyTrait` and `type Bar` to `type MyType` is that the same name (i.e., `Bar`) for the trait and associated type was making it harder to follow the test. It was confusing for me, at least.

r? Kivooeo
This commit is contained in:
Jonathan Brouwer
2026-04-02 22:13:53 +02:00
committed by GitHub
4 changed files with 25 additions and 23 deletions
-22
View File
@@ -1,22 +0,0 @@
//@ normalize-stderr: "\d+ bits" -> "N bits"
trait Bar {
type Bar;
}
struct ArrayPeano<T: Bar> {
data: T::Bar,
}
fn foo<T>(a: &ArrayPeano<T>) -> &[T] where T: Bar {
unsafe { std::mem::transmute(a) } //~ ERROR cannot transmute between types of different sizes
}
impl Bar for () {
type Bar = ();
}
fn main() {
let x: ArrayPeano<()> = ArrayPeano { data: () };
foo(&x);
}
@@ -0,0 +1,23 @@
//! regression test for <https://github.com/rust-lang/rust/issues/28625>
//@ normalize-stderr: "\d+ bits" -> "N bits"
trait MyTrait {
type MyType;
}
struct ArrayPeano<T: MyTrait> {
data: T::MyType,
}
fn foo<T>(a: &ArrayPeano<T>) -> &[T] where T: MyTrait {
unsafe { std::mem::transmute(a) } //~ ERROR cannot transmute between types of different sizes
}
impl MyTrait for () {
type MyType = ();
}
fn main() {
let x: ArrayPeano<()> = ArrayPeano { data: () };
foo(&x);
}
@@ -1,5 +1,5 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/issue-28625.rs:12:14
--> $DIR/transmute-associated-type-to-slice.rs:13:14
|
LL | unsafe { std::mem::transmute(a) }
| ^^^^^^^^^^^^^^^^^^^
@@ -1,3 +1,4 @@
//! regression test for <https://github.com/rust-lang/rust/issues/23477>
//@ build-pass
//@ compile-flags: -g