Skip to content

Monomorphize OpaqueCast #116145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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_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);
}