From 8e7be34ed7fb755a74ecf3cccdbf8411a5005f65 Mon Sep 17 00:00:00 2001 From: johnproblems Date: Wed, 3 Jun 2026 03:50:38 -0400 Subject: [PATCH] Add a regression test for an unconstrained TransmuteFrom ICE An unconstrained `TransmuteFrom` obligation used to ICE with `layout_of: unexpected type` under the next-gen trait solver; it now reports `type annotations needed` (E0283). Add a regression test for that case, which the fix's own test suite did not cover. --- .../transmute-from-unconstrained.rs | 20 ++++++++++++++++ .../transmute-from-unconstrained.stderr | 23 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/ui/traits/next-solver/transmute-from-unconstrained.rs create mode 100644 tests/ui/traits/next-solver/transmute-from-unconstrained.stderr diff --git a/tests/ui/traits/next-solver/transmute-from-unconstrained.rs b/tests/ui/traits/next-solver/transmute-from-unconstrained.rs new file mode 100644 index 0000000000000..892b23d81d45b --- /dev/null +++ b/tests/ui/traits/next-solver/transmute-from-unconstrained.rs @@ -0,0 +1,20 @@ +//! Regression test for . +//! +//! Calling a function with an unconstrained `TransmuteFrom` obligation used to +//! trigger a `layout_of: unexpected type` ICE under the next-gen trait solver +//! instead of reporting that type annotations are needed. + +//@ compile-flags: -Znext-solver=globally + +#![feature(transmutability)] + +fn assert_transmutable() +where + (): std::mem::TransmuteFrom, +{ +} + +fn main() { + assert_transmutable() + //~^ ERROR type annotations needed +} diff --git a/tests/ui/traits/next-solver/transmute-from-unconstrained.stderr b/tests/ui/traits/next-solver/transmute-from-unconstrained.stderr new file mode 100644 index 0000000000000..a3a1cee105d59 --- /dev/null +++ b/tests/ui/traits/next-solver/transmute-from-unconstrained.stderr @@ -0,0 +1,23 @@ +error[E0283]: type annotations needed + --> $DIR/transmute-from-unconstrained.rs:18:5 + | +LL | assert_transmutable() + | ^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `assert_transmutable` + | + = note: cannot satisfy `(): TransmuteFrom<_, Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` +note: required by a bound in `assert_transmutable` + --> $DIR/transmute-from-unconstrained.rs:13:9 + | +LL | fn assert_transmutable() + | ------------------- required by a bound in this function +LL | where +LL | (): std::mem::TransmuteFrom, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_transmutable` +help: consider specifying a concrete type for the type parameter `T` + | +LL | assert_transmutable::() + | ++++++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`.