Skip to content

Commit

Permalink
monomorphize opaque_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Sep 25, 2023
1 parent 96ab09d commit 5bf82ee
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl<'tcx> CPlace<'tcx> {
fx: &mut FunctionCx<'_, '_, 'tcx>,
ty: Ty<'tcx>,
) -> CPlace<'tcx> {
CPlace { inner: self.inner, layout: fx.layout_of(ty) }
CPlace { inner: self.inner, layout: fx.layout_of(fx.monomorphize(ty)) }
}

pub(crate) fn place_field(
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::ProjectionElem::Field(ref field, _) => {
cg_base.project_field(bx, field.index())
}
mir::ProjectionElem::OpaqueCast(ty) => cg_base.project_type(bx, ty),
mir::ProjectionElem::OpaqueCast(ty) => {
cg_base.project_type(bx, self.monomorphize(ty))
}
mir::ProjectionElem::Index(index) => {
let index = &mir::Operand::Copy(mir::Place::from(index));
let index = self.codegen_operand(bx, index);
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_const_eval/src/interpret/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ where
{
use rustc_middle::mir::ProjectionElem::*;
Ok(match proj_elem {
OpaqueCast(ty) => base.transmute(self.layout_of(ty)?, self)?,
OpaqueCast(ty) => base.transmute(
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(ty)?)?,
self,
)?,
Field(field, _) => self.project_field(base, field.index())?,
Downcast(_, variant) => self.project_downcast(base, variant)?,
Deref => self.deref_pointer(&base.to_op(self)?)?.into(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// compile-flags: --edition=2021
// check-pass
// build-pass
#![feature(type_alias_impl_trait)]

fn main() {
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/type-alias-impl-trait/opaque-cast-monormophize-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// build-pass

#![feature(type_alias_impl_trait)]
const fn foo<T: Copy>(x: T) {
type Opaque<T: Copy> = impl Copy;
let foo: Opaque<T> = (x, 2u32);
let (a, b): (T, u32) = foo;
}

fn main() {
const CONST: () = foo::<u32>(42u32);
CONST
}
13 changes: 13 additions & 0 deletions tests/ui/type-alias-impl-trait/opaque-cast-monormophize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// build-pass

#![feature(type_alias_impl_trait)]

fn foo<T: Copy>(x: T) {
type Opaque<T: Copy> = impl Copy;
let foo: &Opaque<T> = &(x, 2u32);
let (a, b): (T, u32) = *foo;
}

fn main() {
foo::<u32>(1);
}

0 comments on commit 5bf82ee

Please sign in to comment.