|
3 | 3 |
|
4 | 4 | use rustc_type_ir::fast_reject::DeepRejectCtxt;
|
5 | 5 | use rustc_type_ir::inherent::*;
|
6 |
| -use rustc_type_ir::{self as ty, Interner}; |
| 6 | +use rustc_type_ir::{self as ty, Interner, elaborate}; |
7 | 7 | use tracing::instrument;
|
8 | 8 |
|
9 | 9 | use super::assembly::Candidate;
|
|
70 | 70 | }
|
71 | 71 | }
|
72 | 72 |
|
| 73 | + /// Register additional assumptions for aliases corresponding to `~const` item bounds. |
| 74 | + /// |
| 75 | + /// Unlike item bounds, they are not simply implied by the well-formedness of the alias. |
| 76 | + /// Instead, they only hold if the const conditons on the alias also hold. This is why |
| 77 | + /// we also register the const conditions of the alias after matching the goal against |
| 78 | + /// the assumption. |
| 79 | + fn consider_additional_alias_assumptions( |
| 80 | + ecx: &mut EvalCtxt<'_, D>, |
| 81 | + goal: Goal<I, Self>, |
| 82 | + alias_ty: ty::AliasTy<I>, |
| 83 | + ) -> Vec<Candidate<I>> { |
| 84 | + let cx = ecx.cx(); |
| 85 | + let mut candidates = vec![]; |
| 86 | + |
| 87 | + // FIXME(effects): We elaborate here because the implied const bounds |
| 88 | + // aren't necessarily elaborated. We probably should prefix this query |
| 89 | + // with `explicit_`... |
| 90 | + for clause in elaborate::elaborate( |
| 91 | + cx, |
| 92 | + cx.implied_const_bounds(alias_ty.def_id) |
| 93 | + .iter_instantiated(cx, alias_ty.args) |
| 94 | + .map(|trait_ref| trait_ref.to_host_effect_clause(cx, goal.predicate.host)), |
| 95 | + ) { |
| 96 | + candidates.extend(Self::probe_and_match_goal_against_assumption( |
| 97 | + ecx, |
| 98 | + CandidateSource::AliasBound, |
| 99 | + goal, |
| 100 | + clause, |
| 101 | + |ecx| { |
| 102 | + // Const conditions must hold for the implied const bound to hold. |
| 103 | + ecx.add_goals( |
| 104 | + GoalSource::Misc, |
| 105 | + cx.const_conditions(alias_ty.def_id) |
| 106 | + .iter_instantiated(cx, alias_ty.args) |
| 107 | + .map(|trait_ref| { |
| 108 | + goal.with( |
| 109 | + cx, |
| 110 | + trait_ref.to_host_effect_clause(cx, goal.predicate.host), |
| 111 | + ) |
| 112 | + }), |
| 113 | + ); |
| 114 | + ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 115 | + }, |
| 116 | + )); |
| 117 | + } |
| 118 | + |
| 119 | + candidates |
| 120 | + } |
| 121 | + |
73 | 122 | fn consider_impl_candidate(
|
74 | 123 | ecx: &mut EvalCtxt<'_, D>,
|
75 | 124 | goal: Goal<I, Self>,
|
|
0 commit comments