Skip to content

Commit 4cfaf9a

Browse files
committed
Normalize all projections in mir validation again
1 parent 1c5bfb1 commit 4cfaf9a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
169169
// Equal types, all is good.
170170
return true;
171171
}
172+
// Normalization reveals opaque types, but we may be validating MIR while computing
173+
// said opaque types, causing cycles.
174+
if (src, dest).has_opaque_types() {
175+
return true;
176+
}
172177
// Normalize projections and things like that.
173-
let param_env = self.param_env;
178+
let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
174179
let src = self.tcx.normalize_erasing_regions(param_env, src);
175180
let dest = self.tcx.normalize_erasing_regions(param_env, dest);
176181

src/test/ui/impl-trait/projection.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// build-pass
2+
// needs to be build-pass, because it is a regression test for a mir validation failure
3+
// that only happens during codegen.
4+
5+
struct D;
6+
7+
trait Tr {
8+
type It;
9+
fn foo(self) -> Option<Self::It>;
10+
}
11+
12+
impl<'a> Tr for &'a D {
13+
type It = ();
14+
fn foo(self) -> Option<()> { None }
15+
}
16+
17+
fn run<F>(f: F)
18+
where for<'a> &'a D: Tr,
19+
F: Fn(<&D as Tr>::It),
20+
{
21+
let d = &D;
22+
while let Some(i) = d.foo() {
23+
f(i);
24+
}
25+
}
26+
27+
fn main() {
28+
run(|_| {});
29+
}

0 commit comments

Comments
 (0)