From 209ea4726e23ff0e190562fdd29e09cf2bdd31e6 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 16 Jun 2026 14:06:52 +0000 Subject: [PATCH] fix(rustc_codegen_ssa): Use cg_operand for Freeze check * fix(rustc_codegen_ssa): Use cg_operand for Freeze check * chore: remove unnecessary comment * test: add test for ssa rval monomorphization issue * fix: move ssa-rval-monomorphization test * tweak comment Co-authored-by: Ralf Jung --- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 2 +- .../ssa-rval-monomorphization-issue-157922.rs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/ui/generics/ssa-rval-monomorphization-issue-157922.rs diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index d792e3d126f5d..deb8ca12b059d 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -43,7 +43,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // If this is storing a &Freeze reference with a retag, record that it's not // possible to perform writes through the stored pointer. let flags = if let ty::Ref(_, pointee_ty, Mutability::Not) = - operand.ty(self.mir, self.cx.tcx()).kind() + cg_operand.layout.ty.kind() && with_retag.yes() && pointee_ty.is_freeze(self.cx.tcx(), self.cx.typing_env()) { diff --git a/tests/ui/generics/ssa-rval-monomorphization-issue-157922.rs b/tests/ui/generics/ssa-rval-monomorphization-issue-157922.rs new file mode 100644 index 0000000000000..f7ebc58e5400a --- /dev/null +++ b/tests/ui/generics/ssa-rval-monomorphization-issue-157922.rs @@ -0,0 +1,25 @@ +//@ build-pass +// (codegen test) +// +// Ensure that the "freeze" check on stores works correctly in generic functions. +// Regression test for [#157922](https://github.com/rust-lang/rust/issues/157922). + +pub trait Field { + type Value; +} + +pub struct S; + +impl Field for S

{ + type Value = (); +} + +pub struct Foo(F::Value); + +fn f(a: &Foo>) { + let _f = if 1 > 0 { a } else { a }; +} + +pub fn main() { + f(&Foo::>(())); +}