Skip to content

Commit

Permalink
normalize opaque alias type
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Oct 3, 2023
1 parent 4f75af9 commit 7d17d04
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {

let kind = match parent_ty.ty.kind() {
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
self.tcx.type_of(def_id).instantiate(self.tcx, args).kind()
let ty = self.tcx.type_of(def_id).instantiate(self.tcx, args);
// If the type we get is opaque, we want to normalize it.
if ty.is_impl_trait() {
let inner_ty = self.tcx.expand_opaque_types(ty).kind();
inner_ty
} else {
ty.kind()
}
}
kind => kind,
};
Expand Down
32 changes: 32 additions & 0 deletions tests/ui/type-alias-impl-trait/normalize-alias-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// check-pass
// compile-flags: -Z mir-opt-level=3
#![feature(type_alias_impl_trait)]
#![crate_type = "lib"]
pub trait Tr {
fn get(&self) -> u32;
}

impl Tr for (u32,) {
#[inline]
fn get(&self) -> u32 { self.0 }
}

pub fn tr1() -> impl Tr {
(32,)
}

pub fn tr2() -> impl Tr {
struct Inner {
x: X,
}
type X = impl Tr;
impl Tr for Inner {
fn get(&self) -> u32 {
self.x.get()
}
}

Inner {
x: tr1(),
}
}

0 comments on commit 7d17d04

Please sign in to comment.