From ca30c6715d65042990a97d9c8f89f96ae9dced9c Mon Sep 17 00:00:00 2001 From: lapla Date: Sun, 23 Nov 2025 07:50:58 +0900 Subject: [PATCH] transmutability: only short-circuit `is_transmutable` for non-region infers --- compiler/rustc_transmute/src/lib.rs | 6 +++++- .../ice-141400-transmutability-coherence.rs | 10 +++++++++ ...ce-141400-transmutability-coherence.stderr | 21 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/ui/transmutability/ice-141400-transmutability-coherence.rs create mode 100644 tests/ui/transmutability/ice-141400-transmutability-coherence.stderr diff --git a/compiler/rustc_transmute/src/lib.rs b/compiler/rustc_transmute/src/lib.rs index 36281ff16bceb..5c7a4e1e33105 100644 --- a/compiler/rustc_transmute/src/lib.rs +++ b/compiler/rustc_transmute/src/lib.rs @@ -89,7 +89,7 @@ pub enum Reason { #[cfg(feature = "rustc")] mod rustc { use rustc_hir::lang_items::LangItem; - use rustc_middle::ty::{Const, Region, Ty, TyCtxt}; + use rustc_middle::ty::{Const, Region, Ty, TyCtxt, TypeVisitableExt}; use super::*; @@ -116,6 +116,10 @@ mod rustc { types: Types<'tcx>, assume: crate::Assume, ) -> crate::Answer, Ty<'tcx>> { + if types.src.has_non_region_infer() || types.dst.has_non_region_infer() { + return Answer::No(Reason::TypeError); + } + crate::maybe_transmutable::MaybeTransmutableQuery::new( types.src, types.dst, assume, self.tcx, ) diff --git a/tests/ui/transmutability/ice-141400-transmutability-coherence.rs b/tests/ui/transmutability/ice-141400-transmutability-coherence.rs new file mode 100644 index 0000000000000..be3a9c0cb64c8 --- /dev/null +++ b/tests/ui/transmutability/ice-141400-transmutability-coherence.rs @@ -0,0 +1,10 @@ +#![feature(transmutability)] +trait OpaqueTrait {} + +impl> OpaqueTrait for T {} +//~^ ERROR: type provided when a constant was expected + +impl OpaqueTrait for &T where T: OpaqueTrait {} +//~^ ERROR: conflicting implementations of trait `OpaqueTrait` for type `&_` + +fn main() {} diff --git a/tests/ui/transmutability/ice-141400-transmutability-coherence.stderr b/tests/ui/transmutability/ice-141400-transmutability-coherence.stderr new file mode 100644 index 0000000000000..0c65957283950 --- /dev/null +++ b/tests/ui/transmutability/ice-141400-transmutability-coherence.stderr @@ -0,0 +1,21 @@ +error[E0747]: type provided when a constant was expected + --> $DIR/ice-141400-transmutability-coherence.rs:4:37 + | +LL | impl> OpaqueTrait for T {} + | ^^ + +error[E0119]: conflicting implementations of trait `OpaqueTrait` for type `&_` + --> $DIR/ice-141400-transmutability-coherence.rs:7:1 + | +LL | impl> OpaqueTrait for T {} + | ---------------------------------------------------------- first implementation here +... +LL | impl OpaqueTrait for &T where T: OpaqueTrait {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_` + | + = note: downstream crates may implement trait `std::mem::TransmuteFrom<(), std::mem::Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` for type `&_` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0119, E0747. +For more information about an error, try `rustc --explain E0119`.