Skip to content

Commit 6bddc75

Browse files
committed
normalize opaque alias type
1 parent e3c631b commit 6bddc75

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

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

688688
let kind = match parent_ty.ty.kind() {
689689
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
690-
self.tcx.type_of(def_id).instantiate(self.tcx, args).kind()
690+
let ty = self.tcx.type_of(def_id).instantiate(self.tcx, args);
691+
// If the type we get is opaque, we want to normalize it.
692+
if ty.is_impl_trait() {
693+
let inner_ty = self.tcx.expand_opaque_types(ty).kind();
694+
inner_ty
695+
} else {
696+
ty.kind()
697+
}
691698
}
692699
kind => kind,
693700
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
type X = impl Tr;
23+
impl Tr for Inner {
24+
fn get(&self) -> u32 {
25+
self.x.get()
26+
}
27+
}
28+
29+
Inner {
30+
x: tr1(),
31+
}
32+
}

0 commit comments

Comments
 (0)