Skip to content

Commit 446a2bb

Browse files
committed
normalize opaque alias type
1 parent 4f75af9 commit 446a2bb

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
677677

678678
let kind = match parent_ty.ty.kind() {
679679
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
680-
self.tcx.type_of(def_id).instantiate(self.tcx, args).kind()
680+
let ty = self.tcx.type_of(def_id).instantiate(self.tcx, args);
681+
// If the type we get is opaque, we want to normalize it.
682+
if ty.is_impl_trait() {
683+
let inner_ty = self.tcx.expand_opaque_types(ty).kind();
684+
inner_ty
685+
} else {
686+
ty.kind()
687+
}
681688
}
682689
kind => kind,
683690
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// check-pass
2+
// compile-flags: -Z mir-opt-level=3
3+
#![feature(type_alias_impl_trait)]
4+
#![crate_type = "lib"]
5+
pub trait Tr {
6+
fn get(&self) -> u32;
7+
}
8+
9+
impl Tr for (u32,) {
10+
#[inline]
11+
fn get(&self) -> u32 { self.0 }
12+
}
13+
14+
pub fn tr1() -> impl Tr {
15+
(32,)
16+
}
17+
18+
pub fn tr2() -> impl Tr {
19+
struct Inner {
20+
x: X,
21+
}
22+
23+
type X = impl Tr;
24+
25+
impl Tr for Inner {
26+
fn get(&self) -> u32 {
27+
self.x.get()
28+
}
29+
}
30+
31+
Inner {
32+
x: tr1(),
33+
}
34+
}

0 commit comments

Comments
 (0)