Skip to content

Commit 5bf82ee

Browse files
committed
monomorphize opaque_cast
1 parent 96ab09d commit 5bf82ee

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

compiler/rustc_codegen_cranelift/src/value_and_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<'tcx> CPlace<'tcx> {
679679
fx: &mut FunctionCx<'_, '_, 'tcx>,
680680
ty: Ty<'tcx>,
681681
) -> CPlace<'tcx> {
682-
CPlace { inner: self.inner, layout: fx.layout_of(ty) }
682+
CPlace { inner: self.inner, layout: fx.layout_of(fx.monomorphize(ty)) }
683683
}
684684

685685
pub(crate) fn place_field(

compiler/rustc_codegen_ssa/src/mir/place.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
463463
mir::ProjectionElem::Field(ref field, _) => {
464464
cg_base.project_field(bx, field.index())
465465
}
466-
mir::ProjectionElem::OpaqueCast(ty) => cg_base.project_type(bx, ty),
466+
mir::ProjectionElem::OpaqueCast(ty) => {
467+
cg_base.project_type(bx, self.monomorphize(ty))
468+
}
467469
mir::ProjectionElem::Index(index) => {
468470
let index = &mir::Operand::Copy(mir::Place::from(index));
469471
let index = self.codegen_operand(bx, index);

compiler/rustc_const_eval/src/interpret/projection.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,10 @@ where
316316
{
317317
use rustc_middle::mir::ProjectionElem::*;
318318
Ok(match proj_elem {
319-
OpaqueCast(ty) => base.transmute(self.layout_of(ty)?, self)?,
319+
OpaqueCast(ty) => base.transmute(
320+
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(ty)?)?,
321+
self,
322+
)?,
320323
Field(field, _) => self.project_field(base, field.index())?,
321324
Downcast(_, variant) => self.project_downcast(base, variant)?,
322325
Deref => self.deref_pointer(&base.to_op(self)?)?.into(),

tests/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile-flags: --edition=2021
2-
// check-pass
2+
// build-pass
33
#![feature(type_alias_impl_trait)]
44

55
fn main() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// build-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
const fn foo<T: Copy>(x: T) {
5+
type Opaque<T: Copy> = impl Copy;
6+
let foo: Opaque<T> = (x, 2u32);
7+
let (a, b): (T, u32) = foo;
8+
}
9+
10+
fn main() {
11+
const CONST: () = foo::<u32>(42u32);
12+
CONST
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// build-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
fn foo<T: Copy>(x: T) {
6+
type Opaque<T: Copy> = impl Copy;
7+
let foo: &Opaque<T> = &(x, 2u32);
8+
let (a, b): (T, u32) = *foo;
9+
}
10+
11+
fn main() {
12+
foo::<u32>(1);
13+
}

0 commit comments

Comments
 (0)