Skip to main content

rustc_next_trait_solver/canonical/
mod.rs

1//! Canonicalization is used to separate some goal from its context,
2//! throwing away unnecessary information in the process.
3//!
4//! This is necessary to cache goals containing inference variables
5//! and placeholders without restricting them to the current `InferCtxt`.
6//!
7//! Canonicalization is fairly involved, for more details see the relevant
8//! section of the [rustc-dev-guide][c].
9//!
10//! [c]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html
11
12use std::iter;
13
14use canonicalizer::Canonicalizer;
15use rustc_index::IndexVec;
16use rustc_type_ir::inherent::*;
17use rustc_type_ir::relate::{
18    self, Relate, RelateResult, TypeRelation, VarianceDiagInfo, relate_args_invariantly,
19};
20use rustc_type_ir::{
21    self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, Canonicalized, Const,
22    InferCtxtLike, Interner, Region, TypeFoldable, TypingMode, TypingModeEqWrapper,
23};
24use tracing::instrument;
25
26use crate::delegate::SolverDelegate;
27use crate::solve::{
28    CanonicalResponse, Certainty, ExternalConstraintsData, ExternalRegionConstraints, Goal,
29    IsIdentity, NestedNormalizationGoals, QueryInput, Response, VisibleForLeakCheck,
30    has_no_inference_or_external_constraints, inspect,
31};
32
33pub mod canonicalizer;
34
35trait ResponseT<I: Interner> {
36    fn var_values(&self) -> I::GenericArgs;
37}
38
39impl<I: Interner> ResponseT<I> for Response<I> {
40    fn var_values(&self) -> I::GenericArgs {
41        self.var_values
42    }
43}
44
45impl<I: Interner, T> ResponseT<I> for inspect::State<I, T> {
46    fn var_values(&self) -> I::GenericArgs {
47        self.var_values
48    }
49}
50
51/// Canonicalizes the goal remembering the original values
52/// for each bound variable.
53///
54/// This expects `goal` and `opaque_types` to be eager resolved.
55pub(super) fn canonicalize_goal<D, I>(
56    delegate: &D,
57    goal: Goal<I, I::Predicate>,
58    opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
59    typing_mode: TypingMode<I>,
60) -> (Vec<I::GenericArg>, I::CanonicalInput)
61where
62    D: SolverDelegate<Interner = I>,
63    I: Interner,
64{
65    let (orig_values, canonical) = Canonicalizer::canonicalize_input(
66        delegate,
67        QueryInput {
68            goal,
69            predefined_opaques_in_body: delegate.cx().mk_predefined_opaques_in_body(opaque_types),
70        },
71    );
72
73    let query_input = delegate.cx().mk_canonical_input(ty::CanonicalQueryInput {
74        canonical,
75        typing_mode: TypingModeEqWrapper(typing_mode),
76    });
77    (orig_values, query_input)
78}
79
80pub(super) fn canonicalize_response<D, I, T>(
81    delegate: &D,
82    max_input_universe: ty::UniverseIndex,
83    value: T,
84) -> ty::Canonical<I, T>
85where
86    D: SolverDelegate<Interner = I>,
87    I: Interner,
88    T: TypeFoldable<I>,
89{
90    Canonicalizer::canonicalize_response(delegate, max_input_universe, value)
91}
92
93/// After calling a canonical query, we apply the constraints returned
94/// by the query using this function.
95///
96/// If a quick early-return check fails, this happens in three steps:
97/// - we instantiate the bound variables of the query response
98/// - we unify the `var_values` of the response with the `original_values`
99/// - we apply the `external_constraints` returned by the query, returning
100///   the `normalization_nested_goals`
101pub(super) fn instantiate_and_apply_query_response<D, I>(
102    delegate: &D,
103    original_values: &[I::GenericArg],
104    response: CanonicalResponse<I>,
105    canonical_goal_var_kinds: I::CanonicalVarKinds,
106    span: I::Span,
107) -> (NestedNormalizationGoals<I>, Certainty)
108where
109    D: SolverDelegate<Interner = I>,
110    I: Interner,
111{
112    let certainty = response.value.certainty;
113
114    // If the response is an identity, and there are no external constraints, and the response var
115    // kinds match the canonical goal var kinds, this function is a no-op and we can return early.
116    if has_no_inference_or_external_constraints(response)
117        && response.var_kinds == canonical_goal_var_kinds
118    {
119        return (NestedNormalizationGoals::empty(), certainty);
120    }
121
122    let instantiation =
123        compute_query_response_instantiation_values(delegate, &original_values, &response, span);
124
125    // We could call `instantiate_canonical` on `response`, but it's more efficient to instantiate
126    // the fields within `response` separately. That way we can instantiate and unify `var_values`
127    // in a single step, rather than instantiating first (which creates an intermediate list) and
128    // then unifying afterwards.
129    let external_constraints =
130        delegate.instantiate_value(response.project(|r| r.external_constraints), instantiation);
131    instantiate_and_unify_query_var_values(
132        delegate,
133        &original_values,
134        response.project(|r| r.var_values),
135        instantiation,
136        span,
137    );
138
139    let ExternalConstraintsData { region_constraints, opaque_types, normalization_nested_goals } =
140        &*external_constraints;
141
142    match region_constraints {
143        ExternalRegionConstraints::Old(r) => register_region_constraints(
144            delegate,
145            r.iter().map(|(c, vis)| {
146                // FIXME: We should revisit and consider removing this after *assumptions on
147                // binders* is available, like once we had done in the stabilization of
148                // `-Znext-solver=coherence`(#121848).
149                // We ignore constraints from the nested goals in leak check. This is to match with
150                // the old solver's behavior, which has separated evaluation and fulfillment, and
151                // the former doesn't consider outlives obligations from the later.
152                (*c, vis.and(VisibleForLeakCheck::No))
153            }),
154            span,
155        ),
156        ExternalRegionConstraints::NextGen(r) => {
157            delegate.register_solver_region_constraint(r.clone(), span)
158        }
159    };
160    register_new_opaque_types(delegate, opaque_types, span);
161
162    (normalization_nested_goals.clone(), certainty)
163}
164
165/// This returns the canonical variable values to instantiate the bound variables of
166/// the canonical response. This depends on the `original_values` for the
167/// bound variables.
168fn compute_query_response_instantiation_values<D, I, T>(
169    delegate: &D,
170    original_values: &[I::GenericArg],
171    response: &Canonical<I, T>,
172    span: I::Span,
173) -> CanonicalVarValues<I>
174where
175    D: SolverDelegate<Interner = I>,
176    I: Interner,
177    T: ResponseT<I>,
178{
179    // FIXME: Longterm canonical queries should deal with all placeholders
180    // created inside of the query directly instead of returning them to the
181    // caller.
182    let prev_universe = delegate.universe();
183    let universes_created_in_query = response.max_universe.index();
184    for _ in 0..universes_created_in_query {
185        let new_universe = delegate.create_next_universe();
186        if delegate.cx().assumptions_on_binders() {
187            // FIXME(-Zassumptions-on-binders): Remove this temporary workaround once
188            // opaque types no longer escape query responses with query-created placeholders.
189            // Region constraints involving query-created placeholders were handled inside
190            // the query. However, the placeholders can still escape in other response
191            // fields, such as opaque type constraints. To avoid triggering
192            // assertions, we explicitly insert empty assumptions for the
193            // recreated universes here.
194            delegate.insert_placeholder_assumptions(
195                new_universe,
196                rustc_type_ir::region_constraint::Assumptions::empty(),
197            );
198        }
199    }
200
201    compute_query_response_instantiation_values_in_universe(
202        delegate,
203        original_values,
204        response,
205        span,
206        prev_universe,
207    )
208}
209
210fn compute_query_response_instantiation_values_in_universe<D, I, T>(
211    delegate: &D,
212    original_values: &[I::GenericArg],
213    response: &Canonical<I, T>,
214    span: I::Span,
215    prev_universe: ty::UniverseIndex,
216) -> CanonicalVarValues<I>
217where
218    D: SolverDelegate<Interner = I>,
219    I: Interner,
220    T: ResponseT<I>,
221{
222    let var_values = response.value.var_values();
223    {
    match (&original_values.len(), &var_values.len()) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
};assert_eq!(original_values.len(), var_values.len());
224
225    // `opt_values` below is expensive to build and rarely needed. Do a quick scan to see if it's
226    // needed. (This duplicates the test in the `instantiate` closure below.)
227    let has_root_existentials = response
228        .var_kinds
229        .iter()
230        .any(|kind| kind.universe() == ty::UniverseIndex::ROOT && kind.is_existential());
231
232    // Build it only if necessary.
233    let opt_values = has_root_existentials.then(|| {
234        // If the query did not make progress with constraining inference variables,
235        // we would normally create a new inference variables for bound existential variables
236        // only then unify this new inference variable with the inference variable from
237        // the input.
238        //
239        // We therefore instantiate the existential variable in the canonical response with the
240        // inference variable of the input right away, which is more performant.
241        let mut opt_values = IndexVec::from_elem_n(None, response.var_kinds.len());
242        for (original_value, result_value) in iter::zip(original_values, var_values.iter()) {
243            match result_value.kind() {
244                ty::GenericArgKind::Type(t) => {
245                    // We disable the instantiation guess for inference variables
246                    // and only use it for placeholders. We need to handle the
247                    // `sub_root` of type inference variables which would make this
248                    // more involved. They are also a lot rarer than region variables.
249                    if let ty::Bound(index_kind, b) = t.kind()
250                        && !#[allow(non_exhaustive_omitted_patterns)] match response.var_kinds.get(b.var().as_usize()).unwrap()
    {
    CanonicalVarKind::Ty { .. } => true,
    _ => false,
}matches!(
251                            response.var_kinds.get(b.var().as_usize()).unwrap(),
252                            CanonicalVarKind::Ty { .. }
253                        )
254                    {
255                        if !#[allow(non_exhaustive_omitted_patterns)] match index_kind {
            ty::BoundVarIndexKind::Canonical => true,
            _ => false,
        } {
    ::core::panicking::panic("assertion failed: matches!(index_kind, ty::BoundVarIndexKind::Canonical)")
};assert!(matches!(index_kind, ty::BoundVarIndexKind::Canonical));
256                        opt_values[b.var()] = Some(*original_value);
257                    }
258                }
259                ty::GenericArgKind::Lifetime(r) => {
260                    if let ty::ReBound(index_kind, br) = r.kind() {
261                        if !#[allow(non_exhaustive_omitted_patterns)] match index_kind {
            ty::BoundVarIndexKind::Canonical => true,
            _ => false,
        } {
    ::core::panicking::panic("assertion failed: matches!(index_kind, ty::BoundVarIndexKind::Canonical)")
};assert!(matches!(index_kind, ty::BoundVarIndexKind::Canonical));
262                        opt_values[br.var()] = Some(*original_value);
263                    }
264                }
265                ty::GenericArgKind::Const(c) => {
266                    if let ty::ConstKind::Bound(index_kind, bc) = c.kind() {
267                        if !#[allow(non_exhaustive_omitted_patterns)] match index_kind {
            ty::BoundVarIndexKind::Canonical => true,
            _ => false,
        } {
    ::core::panicking::panic("assertion failed: matches!(index_kind, ty::BoundVarIndexKind::Canonical)")
};assert!(matches!(index_kind, ty::BoundVarIndexKind::Canonical));
268                        opt_values[bc.var()] = Some(*original_value);
269                    }
270                }
271            }
272        }
273        opt_values
274    });
275
276    CanonicalVarValues::instantiate(delegate.cx(), response.var_kinds, |prev_var_values, kind| {
277        if kind.universe() != ty::UniverseIndex::ROOT {
278            // A variable from inside a binder of the query. While ideally these shouldn't
279            // exist at all (see the FIXME at the start of this method), we have to deal with
280            // them for now.
281            delegate.instantiate_canonical_var(kind, span, &prev_var_values, |idx| {
282                prev_universe + idx.index()
283            })
284        } else if kind.is_existential() {
285            // As an optimization we sometimes avoid creating a new inference variable here.
286            //
287            // All new inference variables we create start out in the current universe of the caller.
288            // This is conceptually wrong as these inference variables would be able to name
289            // more placeholders then they should be able to. However the inference variables have
290            // to "come from somewhere", so by equating them with the original values of the caller
291            // later on, we pull them down into their correct universe again.
292            if let Some(v) =
293                opt_values.as_ref().unwrap()[ty::BoundVar::from_usize(prev_var_values.len())]
294            {
295                v
296            } else {
297                delegate.instantiate_canonical_var(kind, span, &prev_var_values, |_| prev_universe)
298            }
299        } else {
300            // For placeholders which were already part of the input, we simply map this
301            // universal bound variable back the placeholder of the input.
302            //
303            // For `CanonicalVarKind::PlaceholderRegion`, this differs slightly: we
304            // canonicalize all free regions from the input into placeholders. This is
305            // unlike types or consts, where only input placeholders remain placeholders
306            // in the canonical form.
307            //
308            // We can still map these back to the original input regions, as we
309            // just instantiate the canonical variable with its corresponding
310            // `original_value`.
311            //
312            // For more information on why we canonicalize all input regions as
313            // placeholders, see the comment in `Canonicalizer::fold_region`.
314            original_values[kind.expect_placeholder_index()]
315        }
316    })
317}
318
319/// Enforce that `a` is equal to `b`.
320///
321/// In normal type relating, we don't structurally relate non-rigid aliases
322/// as they can be normalized to any type. So we emit projection obligations to
323/// defer the checks. E.g. in `infcx.eq` or `infcx.relate`.
324/// But when unifying query response with original vars, we want to directly
325/// set the original vars to values in response.
326///
327/// Therefore this type relation is created to **always** structurally relate
328/// aliases, or more specifically, structurally eq everything.
329struct ResponseRelating<'infcx, Infcx, I: Interner> {
330    infcx: &'infcx Infcx,
331    span: I::Span,
332}
333
334impl<'infcx, Infcx, I> ResponseRelating<'infcx, Infcx, I>
335where
336    Infcx: InferCtxtLike<Interner = I>,
337    I: Interner,
338{
339    fn new(infcx: &'infcx Infcx, span: I::Span) -> Self {
340        ResponseRelating { infcx, span }
341    }
342}
343
344impl<Infcx, I> TypeRelation<I> for ResponseRelating<'_, Infcx, I>
345where
346    Infcx: InferCtxtLike<Interner = I>,
347    I: Interner,
348{
349    fn cx(&self) -> I {
350        self.infcx.cx()
351    }
352
353    fn relate_ty_args(
354        &mut self,
355        a_ty: I::Ty,
356        _b_ty: I::Ty,
357        _def_id: I::DefId,
358        a_args: I::GenericArgs,
359        b_args: I::GenericArgs,
360        _: impl FnOnce(I::GenericArgs) -> I::Ty,
361    ) -> RelateResult<I, I::Ty> {
362        relate_args_invariantly(self, a_args, b_args)?;
363        Ok(a_ty)
364    }
365
366    fn relate_with_variance<T: Relate<I>>(
367        &mut self,
368        _variance: ty::Variance,
369        _info: VarianceDiagInfo<I>,
370        a: T,
371        b: T,
372    ) -> RelateResult<I, T> {
373        self.relate(a, b)
374    }
375
376    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("tys",
                                    "rustc_next_trait_solver::canonical",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/5f4effd579500175af844241eb179e756190f1e7/compiler/rustc_next_trait_solver/src/canonical/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(376u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::canonical"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("a")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("a");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("b")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("b");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: RelateResult<I, I::Ty> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if a == b { return Ok(a); }
            let infcx = self.infcx;
            let a = infcx.shallow_resolve(a);
            let b = infcx.shallow_resolve(b);
            match (a.kind(), b.kind()) {
                (ty::Infer(ty::TyVar(a_id)), ty::Infer(ty::TyVar(b_id))) => {
                    infcx.equate_ty_vids_raw(a_id, b_id);
                }
                (ty::Infer(ty::TyVar(a_vid)), _) => {
                    infcx.instantiate_ty_var_raw(a_vid, b);
                }
                (_, ty::Infer(ty::TyVar(b_vid))) => {
                    infcx.instantiate_ty_var_raw(b_vid, a);
                }
                (ty::Error(e), _) | (_, ty::Error(e)) => {
                    infcx.set_tainted_by_errors(e);
                    return Ok(Ty::new_error(infcx.cx(), e));
                }
                (ty::Infer(ty::IntVar(a_id)), ty::Infer(ty::IntVar(b_id))) =>
                    {
                    infcx.equate_int_vids_raw(a_id, b_id);
                }
                (ty::Infer(ty::IntVar(v_id)), ty::Int(v)) => {
                    infcx.instantiate_int_var_raw(v_id,
                        ty::IntVarValue::IntType(v));
                }
                (ty::Int(v), ty::Infer(ty::IntVar(v_id))) => {
                    infcx.instantiate_int_var_raw(v_id,
                        ty::IntVarValue::IntType(v));
                }
                (ty::Infer(ty::IntVar(v_id)), ty::Uint(v)) => {
                    infcx.instantiate_int_var_raw(v_id,
                        ty::IntVarValue::UintType(v));
                }
                (ty::Uint(v), ty::Infer(ty::IntVar(v_id))) => {
                    infcx.instantiate_int_var_raw(v_id,
                        ty::IntVarValue::UintType(v));
                }
                (ty::Infer(ty::FloatVar(a_id)), ty::Infer(ty::FloatVar(b_id)))
                    => {
                    infcx.equate_float_vids_raw(a_id, b_id);
                }
                (ty::Infer(ty::FloatVar(v_id)), ty::Float(v)) => {
                    infcx.instantiate_float_var_raw(v_id,
                        ty::FloatVarValue::Known(v));
                }
                (ty::Float(v), ty::Infer(ty::FloatVar(v_id))) => {
                    infcx.instantiate_float_var_raw(v_id,
                        ty::FloatVarValue::Known(v));
                }
                (_,
                    ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) |
                    ty::FreshFloatTy(_))) |
                    (ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) |
                    ty::FreshFloatTy(_)), _) => {
                    {
                        ::core::panicking::panic_fmt(format_args!("We do not expect to encounter `Fresh` variables in the new solver"));
                    }
                }
                _ => { relate::structurally_relate_tys(self, a, b)?; }
            }
            Ok(a)
        }
    }
}#[instrument(skip(self), level = "trace")]
377    fn tys(&mut self, a: I::Ty, b: I::Ty) -> RelateResult<I, I::Ty> {
378        if a == b {
379            return Ok(a);
380        }
381
382        let infcx = self.infcx;
383        let a = infcx.shallow_resolve(a);
384        let b = infcx.shallow_resolve(b);
385
386        match (a.kind(), b.kind()) {
387            (ty::Infer(ty::TyVar(a_id)), ty::Infer(ty::TyVar(b_id))) => {
388                infcx.equate_ty_vids_raw(a_id, b_id);
389            }
390
391            (ty::Infer(ty::TyVar(a_vid)), _) => {
392                infcx.instantiate_ty_var_raw(a_vid, b);
393            }
394
395            (_, ty::Infer(ty::TyVar(b_vid))) => {
396                infcx.instantiate_ty_var_raw(b_vid, a);
397            }
398
399            (ty::Error(e), _) | (_, ty::Error(e)) => {
400                infcx.set_tainted_by_errors(e);
401                return Ok(Ty::new_error(infcx.cx(), e));
402            }
403
404            // FIXME: Share the arms below with `super_combine_tys`.
405            // We can't use `super_combine_tys` here because we want to support
406            // values with escaping bound vars so that we can avoid
407            // instantiating binders when relating them.
408            //
409            // Relate integral variables to other types
410            (ty::Infer(ty::IntVar(a_id)), ty::Infer(ty::IntVar(b_id))) => {
411                infcx.equate_int_vids_raw(a_id, b_id);
412            }
413            (ty::Infer(ty::IntVar(v_id)), ty::Int(v)) => {
414                infcx.instantiate_int_var_raw(v_id, ty::IntVarValue::IntType(v));
415            }
416            (ty::Int(v), ty::Infer(ty::IntVar(v_id))) => {
417                infcx.instantiate_int_var_raw(v_id, ty::IntVarValue::IntType(v));
418            }
419            (ty::Infer(ty::IntVar(v_id)), ty::Uint(v)) => {
420                infcx.instantiate_int_var_raw(v_id, ty::IntVarValue::UintType(v));
421            }
422            (ty::Uint(v), ty::Infer(ty::IntVar(v_id))) => {
423                infcx.instantiate_int_var_raw(v_id, ty::IntVarValue::UintType(v));
424            }
425
426            // Relate floating-point variables to other types
427            (ty::Infer(ty::FloatVar(a_id)), ty::Infer(ty::FloatVar(b_id))) => {
428                infcx.equate_float_vids_raw(a_id, b_id);
429            }
430            (ty::Infer(ty::FloatVar(v_id)), ty::Float(v)) => {
431                infcx.instantiate_float_var_raw(v_id, ty::FloatVarValue::Known(v));
432            }
433            (ty::Float(v), ty::Infer(ty::FloatVar(v_id))) => {
434                infcx.instantiate_float_var_raw(v_id, ty::FloatVarValue::Known(v));
435            }
436
437            (_, ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)))
438            | (ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)), _) => {
439                panic!("We do not expect to encounter `Fresh` variables in the new solver")
440            }
441
442            _ => {
443                relate::structurally_relate_tys(self, a, b)?;
444            }
445        }
446
447        Ok(a)
448    }
449
450    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("regions",
                                    "rustc_next_trait_solver::canonical",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/5f4effd579500175af844241eb179e756190f1e7/compiler/rustc_next_trait_solver/src/canonical/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(450u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::canonical"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("a")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("a");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("b")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("b");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: RelateResult<I, Region<I>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.infcx.equate_regions(a, b, VisibleForLeakCheck::Yes,
                self.span);
            Ok(a)
        }
    }
}#[instrument(skip(self), level = "trace")]
451    fn regions(&mut self, a: Region<I>, b: Region<I>) -> RelateResult<I, Region<I>> {
452        self.infcx.equate_regions(a, b, VisibleForLeakCheck::Yes, self.span);
453
454        Ok(a)
455    }
456
457    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("consts",
                                    "rustc_next_trait_solver::canonical",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/5f4effd579500175af844241eb179e756190f1e7/compiler/rustc_next_trait_solver/src/canonical/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(457u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::canonical"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("a")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("a");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("b")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("b");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: RelateResult<I, Const<I>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            if a == b { return Ok(a); }
            let infcx = self.infcx;
            let a = infcx.shallow_resolve_const(a);
            let b = infcx.shallow_resolve_const(b);
            match (a.kind(), b.kind()) {
                (ty::ConstKind::Infer(ty::InferConst::Var(a_vid)),
                    ty::ConstKind::Infer(ty::InferConst::Var(b_vid))) => {
                    infcx.equate_const_vids_raw(a_vid, b_vid);
                }
                (ty::ConstKind::Infer(ty::InferConst::Var(a_vid)), _) => {
                    infcx.instantiate_const_var_raw(a_vid, b);
                }
                (_, ty::ConstKind::Infer(ty::InferConst::Var(b_vid))) => {
                    infcx.instantiate_const_var_raw(b_vid, a);
                }
                _ => { relate::structurally_relate_consts(self, a, b)?; }
            }
            Ok(a)
        }
    }
}#[instrument(skip(self), level = "trace")]
458    fn consts(&mut self, a: Const<I>, b: Const<I>) -> RelateResult<I, Const<I>> {
459        if a == b {
460            return Ok(a);
461        }
462
463        let infcx = self.infcx;
464        // Proof tree evaluation can unify inference variables in the original
465        // values without eagerly resolving them.
466        let a = infcx.shallow_resolve_const(a);
467        let b = infcx.shallow_resolve_const(b);
468        match (a.kind(), b.kind()) {
469            (
470                ty::ConstKind::Infer(ty::InferConst::Var(a_vid)),
471                ty::ConstKind::Infer(ty::InferConst::Var(b_vid)),
472            ) => {
473                infcx.equate_const_vids_raw(a_vid, b_vid);
474            }
475
476            (ty::ConstKind::Infer(ty::InferConst::Var(a_vid)), _) => {
477                infcx.instantiate_const_var_raw(a_vid, b);
478            }
479
480            (_, ty::ConstKind::Infer(ty::InferConst::Var(b_vid))) => {
481                infcx.instantiate_const_var_raw(b_vid, a);
482            }
483
484            _ => {
485                relate::structurally_relate_consts(self, a, b)?;
486            }
487        }
488
489        Ok(a)
490    }
491
492    fn binders<T>(
493        &mut self,
494        a: ty::Binder<I, T>,
495        b: ty::Binder<I, T>,
496    ) -> RelateResult<I, ty::Binder<I, T>>
497    where
498        T: Relate<I>,
499    {
500        if a == b {
501            return Ok(a);
502        }
503
504        if true {
    {
        match (&a.bound_vars(), &b.bound_vars()) {
            (left_val, right_val) => {
                if !(*left_val == *right_val) {
                    let kind = ::core::panicking::AssertKind::Eq;
                    ::core::panicking::assert_failed(kind, &*left_val,
                        &*right_val, ::core::option::Option::None);
                }
            }
        }
    };
};debug_assert_eq!(a.bound_vars(), b.bound_vars());
505        self.relate(a.skip_binder(), b.skip_binder())?;
506
507        Ok(a)
508    }
509}
510
511/// Instantiate `var_values` as returned by the canonical query and also unify it with
512/// `original_values`.
513///
514/// This assumes that this unification will always succeed. This is the case when
515/// applying a query response right away. However, calling a canonical query, doing any
516/// other kind of trait solving, and only then instantiating the result of the query
517/// can cause the instantiation to fail. This is not supported and we ICE in this case.
518///
519/// We always structurally instantiate aliases. Relating aliases needs to be different
520/// depending on whether the alias is *rigid* or not. We're only really able to tell
521/// whether an alias is rigid by using the trait solver. When instantiating a response
522/// from the solver we assume that the solver correctly handled aliases and therefore
523/// always relate them structurally here.
524{}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("instantiate_and_unify_query_var_values",
                                    "rustc_next_trait_solver::canonical",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/5f4effd579500175af844241eb179e756190f1e7/compiler/rustc_next_trait_solver/src/canonical/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(524u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::canonical"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("original_values")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("original_values");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("var_values")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("var_values");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("instantiation")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("instantiation");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("span")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("span");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&original_values)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&var_values)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instantiation)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            {
                match (&original_values.len(), &var_values.len()) {
                    (left_val, right_val) => {
                        if !(*left_val == *right_val) {
                            let kind = ::core::panicking::AssertKind::Eq;
                            ::core::panicking::assert_failed(kind, &*left_val,
                                &*right_val, ::core::option::Option::None);
                        }
                    }
                }
            };
            for (&orig, response) in
                iter::zip(original_values, var_values.iter()) {
                let response =
                    instantiate_generic_arg(delegate, response, instantiation);
                if orig == response { continue; }
                let mut must_eq = ResponseRelating::new(&**delegate, span);
                must_eq.relate(orig, response).unwrap();
            }
        }
    }
}#[instrument(level = "trace", skip(delegate))]
525fn instantiate_and_unify_query_var_values<D, I>(
526    delegate: &D,
527    original_values: &[I::GenericArg],
528    var_values: Canonicalized<I::GenericArgs>,
529    instantiation: CanonicalVarValues<I>,
530    span: I::Span,
531) where
532    D: SolverDelegate<Interner = I>,
533    I: Interner,
534{
535    assert_eq!(original_values.len(), var_values.len());
536
537    for (&orig, response) in iter::zip(original_values, var_values.iter()) {
538        let response = instantiate_generic_arg(delegate, response, instantiation);
539        if orig == response {
540            continue;
541        }
542
543        let mut must_eq = ResponseRelating::new(&**delegate, span);
544        must_eq.relate(orig, response).unwrap();
545    }
546}
547
548fn instantiate_generic_arg<D, I>(
549    delegate: &D,
550    arg: Canonicalized<I::GenericArg>,
551    instantiation: CanonicalVarValues<I>,
552) -> I::GenericArg
553where
554    D: SolverDelegate<Interner = I>,
555    I: Interner,
556{
557    // Canonical bound vars are very common here. `CanonicalInstantiator::fold_{ty,region,const}`'s
558    // handling of them is simple, and we replicate that handling here to avoid the cost of the
559    // surrounding machinery.
560    fn canonical_bound_var<I: Interner>(arg: Canonicalized<I::GenericArg>) -> Option<ty::BoundVar> {
561        match arg.into_uninstantiated().kind() {
562            ty::GenericArgKind::Type(t) => match t.kind() {
563                ty::Bound(ty::BoundVarIndexKind::Canonical, bt) => Some(bt.var()),
564                _ => None,
565            },
566            ty::GenericArgKind::Lifetime(r) => match r.kind() {
567                ty::ReBound(ty::BoundVarIndexKind::Canonical, br) => Some(br.var()),
568                _ => None,
569            },
570            ty::GenericArgKind::Const(c) => match c.kind() {
571                ty::ConstKind::Bound(ty::BoundVarIndexKind::Canonical, bc) => Some(bc.var()),
572                _ => None,
573            },
574        }
575    }
576
577    match canonical_bound_var::<I>(arg) {
578        Some(var) => instantiation[var],
579        None => delegate.instantiate_value(arg, instantiation),
580    }
581}
582
583fn register_region_constraints<D, I>(
584    delegate: &D,
585    constraints: impl IntoIterator<Item = (ty::RegionConstraint<I>, VisibleForLeakCheck)>,
586    span: I::Span,
587) where
588    D: SolverDelegate<Interner = I>,
589    I: Interner,
590{
591    for (constraint, vis) in constraints {
592        match constraint {
593            ty::RegionConstraint::Outlives(ty::OutlivesClause(lhs, rhs)) => match lhs.kind() {
594                ty::GenericArgKind::Lifetime(lhs) => delegate.sub_regions(rhs, lhs, vis, span),
595                ty::GenericArgKind::Type(lhs) => delegate.register_ty_outlives(lhs, rhs, span),
596                ty::GenericArgKind::Const(_) => {
    ::core::panicking::panic_fmt(format_args!("const outlives: {0:?}: {1:?}",
            lhs, rhs));
}panic!("const outlives: {lhs:?}: {rhs:?}"),
597            },
598            ty::RegionConstraint::Eq(ty::RegionEqPredicate(lhs, rhs)) => {
599                delegate.equate_regions(lhs, rhs, vis, span)
600            }
601        }
602    }
603}
604
605fn register_new_opaque_types<D, I>(
606    delegate: &D,
607    opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
608    span: I::Span,
609) where
610    D: SolverDelegate<Interner = I>,
611    I: Interner,
612{
613    for &(key, ty) in opaque_types {
614        let prev = delegate.register_hidden_type_in_storage(key, ty, span);
615        // We eagerly resolve inference variables when computing the query response.
616        // This can cause previously distinct opaque type keys to now be structurally equal.
617        //
618        // To handle this, we store any duplicate entries in a separate list to check them
619        // at the end of typeck/borrowck. We could alternatively eagerly equate the hidden
620        // types here. However, doing so is difficult as it may result in nested goals and
621        // any errors may make it harder to track the control flow for diagnostics.
622        if let Some(prev) = prev {
623            delegate.add_duplicate_opaque_type(key, prev, span);
624        }
625    }
626}
627
628/// Used by proof trees to be able to recompute intermediate actions while
629/// evaluating a goal. The `var_values` not only include the bound variables
630/// of the query input, but also contain all unconstrained inference vars
631/// created while evaluating this goal.
632pub fn make_canonical_state<D, I, T>(
633    delegate: &D,
634    var_values: &[I::GenericArg],
635    max_input_universe: ty::UniverseIndex,
636    data: T,
637) -> inspect::CanonicalState<I, T>
638where
639    D: SolverDelegate<Interner = I>,
640    I: Interner,
641    T: TypeFoldable<I>,
642{
643    let var_values = delegate.cx().mk_args(var_values);
644    let state = inspect::State { var_values, data };
645    let state = delegate.deeply_resolve_via_unification_table(state);
646    Canonicalizer::canonicalize_response(delegate, max_input_universe, state)
647}
648
649// FIXME: needs to be pub to be accessed by downstream
650// `rustc_trait_selection::solve::inspect::analyse`.
651pub fn instantiate_canonical_state<D, I, T>(
652    delegate: &D,
653    span: I::Span,
654    prev_universe: ty::UniverseIndex,
655    orig_values: &mut Vec<I::GenericArg>,
656    state: inspect::CanonicalState<I, T>,
657) -> T
658where
659    D: SolverDelegate<Interner = I>,
660    I: Interner,
661    T: TypeFoldable<I> + Copy,
662{
663    // In case any fresh inference variables have been created between `state`
664    // and the previous instantiation, extend `orig_values` for it.
665    let max_universe = prev_universe + state.max_universe.index();
666    while delegate.universe() < max_universe {
667        delegate.create_next_universe();
668    }
669    orig_values.extend(
670        state.value.var_values.as_slice()[orig_values.len()..]
671            .iter()
672            .map(|&arg| delegate.fresh_var_for_kind(arg, span, max_universe)),
673    );
674
675    let instantiation = compute_query_response_instantiation_values_in_universe(
676        delegate,
677        orig_values,
678        &state,
679        span,
680        prev_universe,
681    );
682
683    // We instantiate the fields within `state` separately. See the corresponding code in
684    // `instantiate_and_apply_query_response` for an explanation why.
685    let data = delegate.instantiate_value(state.project(|r| r.data), instantiation);
686    instantiate_and_unify_query_var_values(
687        delegate,
688        orig_values,
689        state.project(|r| r.var_values),
690        instantiation,
691        span,
692    );
693
694    data
695}
696
697pub fn response_no_constraints_raw<I: Interner>(
698    cx: I,
699    max_universe: ty::UniverseIndex,
700    var_kinds: I::CanonicalVarKinds,
701    certainty: Certainty,
702) -> CanonicalResponse<I> {
703    // Given a list of canonical variables, construct a set of values which are
704    // the identity response.
705    let var_values =
706        cx.mk_args_from_iter(var_kinds.iter().enumerate().map(|(i, kind)| -> I::GenericArg {
707            match kind {
708                CanonicalVarKind::Ty { .. }
709                | CanonicalVarKind::Int
710                | CanonicalVarKind::Float
711                | CanonicalVarKind::PlaceholderTy(_) => {
712                    Ty::new_canonical_bound(cx, ty::BoundVar::from_usize(i)).into()
713                }
714                CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
715                    Region::new_canonical_bound(cx, ty::BoundVar::from_usize(i)).into()
716                }
717                CanonicalVarKind::Const(_) | CanonicalVarKind::PlaceholderConst(_) => {
718                    Const::new_canonical_bound(cx, ty::BoundVar::from_usize(i)).into()
719                }
720            }
721        }));
722
723    ty::Canonical {
724        max_universe,
725        var_kinds,
726        value: Response {
727            certainty,
728            var_values,
729            var_values_is_identity: IsIdentity::Yes,
730            // FIXME: maybe we should store the "no response" version in cx, like
731            // we do for cx.types and stuff.
732            external_constraints: cx.mk_external_constraints(ExternalConstraintsData::new(cx)),
733        },
734    }
735}