Skip to content

Commit d018144

Browse files
Optimize subtyping and equation of GeneratorWitness
1 parent 43119d6 commit d018144

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

compiler/rustc_infer/src/infer/equate.rs

+18
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
110110
.obligations,
111111
);
112112
}
113+
(&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => {
114+
let a_types = infcx.tcx.anonymize_bound_vars(a_types);
115+
let b_types = infcx.tcx.anonymize_bound_vars(b_types);
116+
if a_types.bound_vars() == b_types.bound_vars() {
117+
let (a_types, b_types) = infcx.replace_bound_vars_with_placeholders(
118+
a_types.map_bound(|a_types| (a_types, b_types.skip_binder())),
119+
);
120+
for (a, b) in std::iter::zip(a_types, b_types) {
121+
self.relate(a, b)?;
122+
}
123+
} else {
124+
self.fields.infcx.super_combine_tys(
125+
self,
126+
infcx.tcx.mk_generator_witness(a_types),
127+
infcx.tcx.mk_generator_witness(b_types),
128+
)?;
129+
}
130+
}
113131

114132
_ => {
115133
self.fields.infcx.super_combine_tys(self, a, b)?;

compiler/rustc_infer/src/infer/sub.rs

+19
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
164164
);
165165
Ok(ga)
166166
}
167+
(&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => {
168+
let a_types = infcx.tcx.anonymize_bound_vars(a_types);
169+
let b_types = infcx.tcx.anonymize_bound_vars(b_types);
170+
if a_types.bound_vars() == b_types.bound_vars() {
171+
let (a_types, b_types) = infcx.replace_bound_vars_with_placeholders(
172+
a_types.map_bound(|a_types| (a_types, b_types.skip_binder())),
173+
);
174+
for (a, b) in std::iter::zip(a_types, b_types) {
175+
self.relate(a, b)?;
176+
}
177+
} else {
178+
self.fields.infcx.super_combine_tys(
179+
self,
180+
infcx.tcx.mk_generator_witness(a_types),
181+
infcx.tcx.mk_generator_witness(b_types),
182+
)?;
183+
}
184+
Ok(a)
185+
}
167186

168187
_ => {
169188
self.fields.infcx.super_combine_tys(self, a, b)?;

src/test/ui/higher-rank-trait-bounds/issue-95034.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
1-
// known-bug: #95034
2-
// failure-status: 101
1+
// check-pass
32
// compile-flags: --edition=2021 --crate-type=lib
4-
// rustc-env:RUST_BACKTRACE=0
5-
6-
// normalize-stderr-test "thread 'rustc' panicked.*" -> "thread 'rustc' panicked"
7-
// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> ""
8-
// normalize-stderr-test "\nerror: internal compiler error.*\n\n" -> ""
9-
// normalize-stderr-test "note:.*unexpectedly panicked.*\n\n" -> ""
10-
// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> ""
11-
// normalize-stderr-test "note: compiler flags.*\n\n" -> ""
12-
// normalize-stderr-test "note: rustc.*running on.*\n\n" -> ""
13-
// normalize-stderr-test "query stack during panic:\n" -> ""
14-
// normalize-stderr-test "we're just showing a limited slice of the query stack\n" -> ""
15-
// normalize-stderr-test "end of query stack\n" -> ""
16-
// normalize-stderr-test "#.*\n" -> ""
17-
18-
// This should not ICE.
19-
20-
// Refer to the issue for more minimized versions.
213

224
use std::{
235
future::Future,

src/test/ui/higher-rank-trait-bounds/issue-95034.stderr

-1
This file was deleted.

0 commit comments

Comments
 (0)