|
1 | 1 | //! Helper routines for higher-ranked things. See the `doc` module at
|
2 | 2 | //! the end of the file for details.
|
3 | 3 |
|
4 |
| -use super::combine::CombineFields; |
5 | 4 | use crate::infer::CombinedSnapshot;
|
6 |
| -use crate::infer::{HigherRankedType, InferCtxt}; |
| 5 | +use crate::infer::InferCtxt; |
7 | 6 | use rustc_middle::ty::fold::FnMutDelegate;
|
8 |
| -use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation}; |
9 |
| -use rustc_middle::ty::{self, Binder, Ty, TyCtxt, TypeFoldable}; |
10 |
| - |
11 |
| -impl<'a, 'tcx> CombineFields<'a, 'tcx> { |
12 |
| - /// Checks whether `for<..> sub <: for<..> sup` holds. |
13 |
| - /// |
14 |
| - /// For this to hold, **all** instantiations of the super type |
15 |
| - /// have to be a super type of **at least one** instantiation of |
16 |
| - /// the subtype. |
17 |
| - /// |
18 |
| - /// This is implemented by first entering a new universe. |
19 |
| - /// We then replace all bound variables in `sup` with placeholders, |
20 |
| - /// and all bound variables in `sub` with inference vars. |
21 |
| - /// We can then just relate the two resulting types as normal. |
22 |
| - /// |
23 |
| - /// Note: this is a subtle algorithm. For a full explanation, please see |
24 |
| - /// the [rustc dev guide][rd] |
25 |
| - /// |
26 |
| - /// [rd]: https://rustc-dev-guide.rust-lang.org/borrow_check/region_inference/placeholders_and_universes.html |
27 |
| - #[instrument(skip(self), level = "debug")] |
28 |
| - pub fn higher_ranked_sub<T>( |
29 |
| - &mut self, |
30 |
| - sub: Binder<'tcx, T>, |
31 |
| - sup: Binder<'tcx, T>, |
32 |
| - sub_is_expected: bool, |
33 |
| - ) -> RelateResult<'tcx, ()> |
34 |
| - where |
35 |
| - T: Relate<'tcx>, |
36 |
| - { |
37 |
| - let span = self.trace.cause.span; |
38 |
| - // First, we instantiate each bound region in the supertype with a |
39 |
| - // fresh placeholder region. Note that this automatically creates |
40 |
| - // a new universe if needed. |
41 |
| - self.infcx.enter_forall(sup, |sup_prime| { |
42 |
| - // Next, we instantiate each bound region in the subtype |
43 |
| - // with a fresh region variable. These region variables -- |
44 |
| - // but no other preexisting region variables -- can name |
45 |
| - // the placeholders. |
46 |
| - let sub_prime = |
47 |
| - self.infcx.instantiate_binder_with_fresh_vars(span, HigherRankedType, sub); |
48 |
| - debug!("a_prime={:?}", sub_prime); |
49 |
| - debug!("b_prime={:?}", sup_prime); |
50 |
| - |
51 |
| - // Compare types now that bound regions have been replaced. |
52 |
| - // Reorder the inputs so that the expected is passed first. |
53 |
| - let result = if sub_is_expected { |
54 |
| - self.sub().relate(sub_prime, sup_prime) |
55 |
| - } else { |
56 |
| - self.sup().relate(sup_prime, sub_prime) |
57 |
| - }; |
58 |
| - |
59 |
| - if result.is_ok() { |
60 |
| - debug!("OK result={result:?}"); |
61 |
| - } |
62 |
| - // NOTE: returning the result here would be dangerous as it contains |
63 |
| - // placeholders which **must not** be named afterwards. |
64 |
| - result.map(|_| ()) |
65 |
| - }) |
66 |
| - } |
67 |
| -} |
| 7 | +use rustc_middle::ty::relate::RelateResult; |
| 8 | +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; |
68 | 9 |
|
69 | 10 | impl<'tcx> InferCtxt<'tcx> {
|
70 | 11 | /// Replaces all bound variables (lifetimes, types, and constants) bound by
|
|
0 commit comments