Skip to content

Commit b61c6d3

Browse files
authored
Rollup merge of rust-lang#100121 - Nilstrieb:mir-validator-param-env, r=oli-obk
Try normalizing types without RevealAll in ParamEnv in MIR validation Before, the MIR validator used RevealAll in its ParamEnv for type checking. This could cause false negatives in some cases due to RevealAll ParamEnvs not always use all predicates as expected here. Since some MIR passes like inlining use RevealAll as well, keep using it in the MIR validator too, but when it fails usign RevealAll, also try the check without it, to stop false negatives. Fixes rust-lang#99866 cc ```@compiler-errors``` who nicely helped me on zulip
2 parents a230b73 + 96d4137 commit b61c6d3

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,23 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
181181
if (src, dest).has_opaque_types() {
182182
return true;
183183
}
184-
// Normalize projections and things like that.
185-
let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
186-
let src = self.tcx.normalize_erasing_regions(param_env, src);
187-
let dest = self.tcx.normalize_erasing_regions(param_env, dest);
188184

185+
// Normalize projections and things like that.
189186
// Type-changing assignments can happen when subtyping is used. While
190187
// all normal lifetimes are erased, higher-ranked types with their
191188
// late-bound lifetimes are still around and can lead to type
192189
// differences. So we compare ignoring lifetimes.
193-
equal_up_to_regions(self.tcx, param_env, src, dest)
190+
191+
// First, try with reveal_all. This might not work in some cases, as the predicates
192+
// can be cleared in reveal_all mode. We try the reveal first anyways as it is used
193+
// by some other passes like inlining as well.
194+
let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
195+
if equal_up_to_regions(self.tcx, param_env, src, dest) {
196+
return true;
197+
}
198+
199+
// If this fails, we can try it without the reveal.
200+
equal_up_to_regions(self.tcx, self.param_env, src, dest)
194201
}
195202
}
196203

src/test/ui/mir/issue-99866.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// check-pass
2+
pub trait Backend {
3+
type DescriptorSetLayout;
4+
}
5+
6+
pub struct Back;
7+
8+
impl Backend for Back {
9+
type DescriptorSetLayout = u32;
10+
}
11+
12+
pub struct HalSetLayouts {
13+
vertex_layout: <Back as Backend>::DescriptorSetLayout,
14+
}
15+
16+
impl HalSetLayouts {
17+
pub fn iter<DSL>(self) -> DSL
18+
where
19+
Back: Backend<DescriptorSetLayout = DSL>,
20+
{
21+
self.vertex_layout
22+
}
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)