Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
25 changes: 25 additions & 0 deletions tests/ui/generics/ssa-rval-monomorphization-issue-157922.rs
Comment thread
RalfJung marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -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<const P: u8>;

impl<const P: u8> Field for S<P> {
type Value = ();
}

pub struct Foo<F: Field>(F::Value);

fn f<const P: u8>(a: &Foo<S<P>>) {
let _f = if 1 > 0 { a } else { a };
}

pub fn main() {
f(&Foo::<S<7>>(()));
}
Loading