ra-ap-rustc_type_ir 0.166.0

Automatically published version of the package `rustc_type_ir` in the rust-lang/rust repository from commit ce89c898570852a1bb441d77570596e50bf362c2 The publishing script for this crate lives at: https://github.com/rust-analyzer/rustc-auto-publish
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
use std::borrow::Borrow;
use std::fmt::Debug;
use std::hash::Hash;
use std::ops::Deref;

use rustc_ast_ir::Movability;
use rustc_ast_ir::visit::VisitorResult;
use rustc_index::bit_set::DenseBitSet;

use crate::fold::TypeFoldable;
use crate::inherent::*;
use crate::ir_print::IrPrint;
use crate::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem};
use crate::relate::Relate;
use crate::solve::{
    AccessedOpaques, CanonicalInput, Certainty, ExternalConstraintsData, QueryResult, inspect,
};
use crate::visit::{Flags, TypeVisitable};
use crate::{self as ty, CanonicalParamEnvCacheEntry, search_graph};

#[cfg_attr(feature = "nightly", rustc_diagnostic_item = "type_ir_interner")]
pub trait Interner:
    Sized
    + Copy
    + IrPrint<ty::AliasTy<Self>>
    + IrPrint<ty::AliasTerm<Self>>
    + IrPrint<ty::TraitRef<Self>>
    + IrPrint<ty::TraitPredicate<Self>>
    + IrPrint<ty::HostEffectPredicate<Self>>
    + IrPrint<ty::ExistentialTraitRef<Self>>
    + IrPrint<ty::ExistentialProjection<Self>>
    + IrPrint<ty::ProjectionPredicate<Self>>
    + IrPrint<ty::NormalizesTo<Self>>
    + IrPrint<ty::SubtypePredicate<Self>>
    + IrPrint<ty::CoercePredicate<Self>>
    + IrPrint<ty::FnSig<Self>>
    + IrPrint<ty::PatternKind<Self>>
{
    fn next_trait_solver_globally(self) -> bool {
        true
    }

    type DefId: DefId<Self>;
    type LocalDefId: Copy + Debug + Hash + Eq + Into<Self::DefId> + TypeFoldable<Self>;
    // Various more specific `DefId`s.
    //
    // rustc just defines them all to be `DefId`, but rust-analyzer uses different types so this is convenient for it.
    //
    // Note: The `TryFrom<DefId>` always succeeds (in rustc), so don't use it to check if some `DefId`
    // is of some specific type!
    type TraitId: SpecificDefId<Self>;
    type ForeignId: SpecificDefId<Self>;
    type FunctionId: SpecificDefId<Self>;
    type ClosureId: SpecificDefId<Self>;
    type CoroutineClosureId: SpecificDefId<Self>;
    type CoroutineId: SpecificDefId<Self>;
    type AdtId: SpecificDefId<Self>;
    type ImplId: SpecificDefId<Self>;
    type UnevaluatedConstId: SpecificDefId<Self>;
    type TraitAssocTyId: SpecificDefId<Self>
        + Into<Self::TraitAssocTermId>
        + TryFrom<Self::TraitAssocTermId>;
    type TraitAssocConstId: SpecificDefId<Self>
        + Into<Self::TraitAssocTermId>
        + Into<Self::UnevaluatedConstId>
        + TryFrom<Self::TraitAssocTermId>;
    type TraitAssocTermId: SpecificDefId<Self>;
    type OpaqueTyId: SpecificDefId<Self, Self::LocalOpaqueTyId>;
    type LocalOpaqueTyId: Copy
        + Debug
        + Hash
        + Eq
        + Into<Self::OpaqueTyId>
        + Into<Self::LocalDefId>
        + Into<Self::DefId>
        + TypeFoldable<Self>;
    type FreeTyAliasId: SpecificDefId<Self> + Into<Self::FreeTermAliasId>;
    type FreeConstAliasId: SpecificDefId<Self>
        + Into<Self::UnevaluatedConstId>
        + Into<Self::FreeTermAliasId>;
    type FreeTermAliasId: SpecificDefId<Self>;
    type ImplOrTraitAssocTyId: SpecificDefId<Self> + Into<Self::ImplOrTraitAssocTermId>;
    type ImplOrTraitAssocConstId: SpecificDefId<Self>
        + Into<Self::UnevaluatedConstId>
        + Into<Self::ImplOrTraitAssocTermId>;
    type ImplOrTraitAssocTermId: SpecificDefId<Self>;
    type InherentAssocTyId: SpecificDefId<Self> + Into<Self::InherentAssocTermId>;
    type InherentAssocConstId: SpecificDefId<Self>
        + Into<Self::UnevaluatedConstId>
        + Into<Self::InherentAssocTermId>;
    type InherentAssocTermId: SpecificDefId<Self>;
    type Span: Span<Self>;

    type GenericArgs: GenericArgs<Self>;
    type GenericArgsSlice: Copy + Debug + Hash + Eq + SliceLike<Item = Self::GenericArg>;
    type GenericArg: GenericArg<Self>;
    type Term: Term<Self>;

    type BoundVarKinds: Copy
        + Debug
        + Hash
        + Eq
        + SliceLike<Item = ty::BoundVariableKind<Self>>
        + Default;

    type PredefinedOpaques: Copy
        + Debug
        + Hash
        + Eq
        + TypeFoldable<Self>
        + SliceLike<Item = (ty::OpaqueTypeKey<Self>, Self::Ty)>;
    fn mk_predefined_opaques_in_body(
        self,
        data: &[(ty::OpaqueTypeKey<Self>, Self::Ty)],
    ) -> Self::PredefinedOpaques;

    type LocalDefIds: Copy
        + Debug
        + Hash
        + Default
        + Eq
        + TypeVisitable<Self>
        + SliceLike<Item = Self::LocalDefId>;

    type CanonicalVarKinds: Copy
        + Debug
        + Hash
        + Eq
        + SliceLike<Item = ty::CanonicalVarKind<Self>>
        + Default;
    fn mk_canonical_var_kinds(
        self,
        kinds: &[ty::CanonicalVarKind<Self>],
    ) -> Self::CanonicalVarKinds;

    type ExternalConstraints: Copy
        + Debug
        + Hash
        + Eq
        + TypeFoldable<Self>
        + Deref<Target = ExternalConstraintsData<Self>>;
    fn mk_external_constraints(
        self,
        data: ExternalConstraintsData<Self>,
    ) -> Self::ExternalConstraints;

    type DepNodeIndex;
    type Tracked<T: Debug + Clone>: Debug;
    fn mk_tracked<T: Debug + Clone>(
        self,
        data: T,
        dep_node: Self::DepNodeIndex,
    ) -> Self::Tracked<T>;
    fn get_tracked<T: Debug + Clone>(self, tracked: &Self::Tracked<T>) -> T;
    fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, Self::DepNodeIndex);

    // Kinds of tys
    type Ty: Ty<Self>;
    type Tys: Tys<Self>;
    type FnInputTys: Copy + Debug + Hash + Eq + SliceLike<Item = Self::Ty> + TypeVisitable<Self>;
    type ParamTy: ParamLike;
    type Symbol: Symbol<Self>;

    // Things stored inside of tys
    type ErrorGuaranteed: Copy + Debug + Hash + Eq;
    type BoundExistentialPredicates: BoundExistentialPredicates<Self>;
    type AllocId: Copy + Debug + Hash + Eq;
    type Pat: Copy
        + Debug
        + Hash
        + Eq
        + Debug
        + Relate<Self>
        + Flags
        + IntoKind<Kind = ty::PatternKind<Self>>;
    type PatList: Copy
        + Debug
        + Hash
        + Default
        + Eq
        + TypeVisitable<Self>
        + SliceLike<Item = Self::Pat>;
    type Safety: Safety<Self>;

    // Kinds of consts
    type Const: Const<Self>;
    type Consts: Copy + Debug + Hash + Eq + SliceLike<Item = Self::Const> + Default;
    type ParamConst: Copy + Debug + Hash + Eq + ParamLike;
    type ValueConst: ValueConst<Self>;
    type ExprConst: ExprConst<Self>;
    type ValTree: Copy + Debug + Hash + Eq + IntoKind<Kind = ty::ValTreeKind<Self>>;
    type ScalarInt: Copy + Debug + Hash + Eq;

    // Kinds of regions
    type Region: Region<Self>;
    type EarlyParamRegion: ParamLike;
    type LateParamRegion: Copy + Debug + Hash + Eq;

    type RegionAssumptions: Copy
        + Debug
        + Hash
        + Eq
        + SliceLike<Item = ty::OutlivesPredicate<Self, Self::GenericArg>>
        + TypeFoldable<Self>;

    // Predicates
    type ParamEnv: ParamEnv<Self>;
    type Predicate: Predicate<Self>;
    type Clause: Clause<Self>;
    type Clauses: Clauses<Self>;

    fn with_global_cache<R>(self, f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R) -> R;

    fn canonical_param_env_cache_get_or_insert<R>(
        self,
        param_env: Self::ParamEnv,
        f: impl FnOnce() -> CanonicalParamEnvCacheEntry<Self>,
        from_entry: impl FnOnce(&CanonicalParamEnvCacheEntry<Self>) -> R,
    ) -> R;

    /// Useful for testing. If a cache entry is replaced, this should
    /// (in theory) only happen when concurrent.
    fn assert_evaluation_is_concurrent(&self);

    fn expand_abstract_consts<T: TypeFoldable<Self>>(self, t: T) -> T;

    type GenericsOf: GenericsOf<Self>;
    fn generics_of(self, def_id: Self::DefId) -> Self::GenericsOf;

    type VariancesOf: Copy + Debug + SliceLike<Item = ty::Variance>;
    fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf;

    fn opt_alias_variances(
        self,
        kind: impl Into<ty::AliasTermKind<Self>>,
    ) -> Option<Self::VariancesOf>;

    fn type_of(self, def_id: Self::DefId) -> ty::EarlyBinder<Self, Self::Ty>;
    fn type_of_opaque_hir_typeck(
        self,
        def_id: Self::LocalOpaqueTyId,
    ) -> ty::EarlyBinder<Self, Self::Ty>;
    fn is_type_const(self, def_id: Self::DefId) -> bool;
    fn const_of_item(self, def_id: Self::DefId) -> ty::EarlyBinder<Self, Self::Const>;
    fn anon_const_kind(self, def_id: Self::DefId) -> ty::AnonConstKind;

    type AdtDef: AdtDef<Self>;
    fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef;

    fn alias_ty_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTyKind<Self>;

    // FIXME: remove in favor of explicit construction
    fn alias_term_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTermKind<Self>;

    fn trait_ref_and_own_args_for_alias(
        self,
        def_id: Self::TraitAssocTermId,
        args: Self::GenericArgs,
    ) -> (ty::TraitRef<Self>, Self::GenericArgsSlice);

    fn mk_args(self, args: &[Self::GenericArg]) -> Self::GenericArgs;

    fn mk_args_from_iter<I, T>(self, args: I) -> T::Output
    where
        I: Iterator<Item = T>,
        T: CollectAndApply<Self::GenericArg, Self::GenericArgs>;

    fn check_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs) -> bool;

    fn debug_assert_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs);

    /// Assert that the args from an `ExistentialTraitRef` or `ExistentialProjection`
    /// are compatible with the `DefId`.
    fn debug_assert_existential_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs);

    fn mk_type_list_from_iter<I, T>(self, args: I) -> T::Output
    where
        I: Iterator<Item = T>,
        T: CollectAndApply<Self::Ty, Self::Tys>;

    fn projection_parent(self, def_id: Self::TraitAssocTermId) -> Self::TraitId;

    /// This can be an impl, or a trait if this is a defaulted term.
    fn impl_or_trait_assoc_term_parent(self, def_id: Self::ImplOrTraitAssocTermId) -> Self::DefId;

    fn inherent_alias_term_parent(self, def_id: Self::InherentAssocTermId) -> Self::ImplId;

    fn recursion_limit(self) -> usize;

    type Features: Features<Self>;
    fn features(self) -> Self::Features;

    fn coroutine_hidden_types(
        self,
        def_id: Self::CoroutineId,
    ) -> ty::EarlyBinder<Self, ty::Binder<Self, ty::CoroutineWitnessTypes<Self>>>;

    fn fn_sig(
        self,
        def_id: Self::FunctionId,
    ) -> ty::EarlyBinder<Self, ty::Binder<Self, ty::FnSig<Self>>>;

    fn coroutine_movability(self, def_id: Self::CoroutineId) -> Movability;

    fn coroutine_for_closure(self, def_id: Self::CoroutineClosureId) -> Self::CoroutineId;

    fn generics_require_sized_self(self, def_id: Self::DefId) -> bool;

    fn item_bounds(
        self,
        def_id: Self::DefId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;

    fn item_self_bounds(
        self,
        def_id: Self::DefId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;

    fn item_non_self_bounds(
        self,
        def_id: Self::DefId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;

    fn predicates_of(
        self,
        def_id: Self::DefId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;

    fn own_predicates_of(
        self,
        def_id: Self::DefId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;

    fn explicit_super_predicates_of(
        self,
        def_id: Self::TraitId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = (Self::Clause, Self::Span)>>;

    fn explicit_implied_predicates_of(
        self,
        def_id: Self::DefId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = (Self::Clause, Self::Span)>>;

    /// This is equivalent to computing the super-predicates of the trait for this impl
    /// and filtering them to the outlives predicates. This is purely for performance.
    fn impl_super_outlives(
        self,
        impl_def_id: Self::ImplId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;

    fn impl_is_const(self, def_id: Self::ImplId) -> bool;
    fn fn_is_const(self, def_id: Self::FunctionId) -> bool;
    fn closure_is_const(self, def_id: Self::ClosureId) -> bool;
    fn alias_has_const_conditions(self, def_id: Self::DefId) -> bool;
    fn const_conditions(
        self,
        def_id: Self::DefId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = ty::Binder<Self, ty::TraitRef<Self>>>>;
    fn explicit_implied_const_bounds(
        self,
        def_id: Self::DefId,
    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = ty::Binder<Self, ty::TraitRef<Self>>>>;

    fn impl_self_is_guaranteed_unsized(self, def_id: Self::ImplId) -> bool;

    fn has_target_features(self, def_id: Self::FunctionId) -> bool;

    fn require_projection_lang_item(
        self,
        lang_item: SolverProjectionLangItem,
    ) -> Self::TraitAssocTyId;

    fn require_trait_lang_item(self, lang_item: SolverTraitLangItem) -> Self::TraitId;

    fn require_adt_lang_item(self, lang_item: SolverAdtLangItem) -> Self::AdtId;

    fn is_projection_lang_item(
        self,
        def_id: Self::TraitAssocTyId,
        lang_item: SolverProjectionLangItem,
    ) -> bool;

    fn is_trait_lang_item(self, def_id: Self::TraitId, lang_item: SolverTraitLangItem) -> bool;

    fn is_adt_lang_item(self, def_id: Self::AdtId, lang_item: SolverAdtLangItem) -> bool;

    fn is_default_trait(self, def_id: Self::TraitId) -> bool;

    fn is_sizedness_trait(self, def_id: Self::TraitId) -> bool;

    fn as_projection_lang_item(
        self,
        def_id: Self::TraitAssocTyId,
    ) -> Option<SolverProjectionLangItem>;

    fn as_trait_lang_item(self, def_id: Self::TraitId) -> Option<SolverTraitLangItem>;

    fn as_adt_lang_item(self, def_id: Self::AdtId) -> Option<SolverAdtLangItem>;

    fn associated_type_def_ids(
        self,
        def_id: Self::TraitId,
    ) -> impl IntoIterator<Item = Self::DefId>;

    fn for_each_relevant_impl<R: VisitorResult>(
        self,
        trait_def_id: Self::TraitId,
        self_ty: Self::Ty,
        f: impl FnMut(Self::ImplId) -> R,
    ) -> R;
    fn for_each_blanket_impl<R: VisitorResult>(
        self,
        trait_def_id: Self::TraitId,
        f: impl FnMut(Self::ImplId) -> R,
    ) -> R;

    fn has_item_definition(self, def_id: Self::ImplOrTraitAssocTermId) -> bool;

    fn impl_specializes(self, impl_def_id: Self::ImplId, victim_def_id: Self::ImplId) -> bool;

    fn impl_is_default(self, impl_def_id: Self::ImplId) -> bool;

    fn impl_trait_ref(self, impl_def_id: Self::ImplId)
    -> ty::EarlyBinder<Self, ty::TraitRef<Self>>;

    fn impl_polarity(self, impl_def_id: Self::ImplId) -> ty::ImplPolarity;

    fn trait_is_auto(self, trait_def_id: Self::TraitId) -> bool;

    fn trait_is_coinductive(self, trait_def_id: Self::TraitId) -> bool;

    fn trait_is_alias(self, trait_def_id: Self::TraitId) -> bool;

    fn trait_is_dyn_compatible(self, trait_def_id: Self::TraitId) -> bool;

    fn trait_is_fundamental(self, def_id: Self::TraitId) -> bool;

    /// Returns `true` if this is an `unsafe trait`.
    fn trait_is_unsafe(self, trait_def_id: Self::TraitId) -> bool;

    fn is_impl_trait_in_trait(self, def_id: Self::DefId) -> bool;

    fn delay_bug(self, msg: impl ToString) -> Self::ErrorGuaranteed;

    fn is_general_coroutine(self, coroutine_def_id: Self::CoroutineId) -> bool;
    fn coroutine_is_async(self, coroutine_def_id: Self::CoroutineId) -> bool;
    fn coroutine_is_gen(self, coroutine_def_id: Self::CoroutineId) -> bool;
    fn coroutine_is_async_gen(self, coroutine_def_id: Self::CoroutineId) -> bool;

    type UnsizingParams: Deref<Target = DenseBitSet<u32>>;
    fn unsizing_params_for_adt(self, adt_def_id: Self::AdtId) -> Self::UnsizingParams;

    fn anonymize_bound_vars<T: TypeFoldable<Self>>(
        self,
        binder: ty::Binder<Self, T>,
    ) -> ty::Binder<Self, T>;

    fn opaque_types_defined_by(self, defining_anchor: Self::LocalDefId) -> Self::LocalDefIds;

    fn opaque_types_and_coroutines_defined_by(
        self,
        defining_anchor: Self::LocalDefId,
    ) -> Self::LocalDefIds;

    type Probe: Debug + Hash + Eq + Borrow<inspect::Probe<Self>>;
    fn mk_probe(self, probe: inspect::Probe<Self>) -> Self::Probe;
    fn evaluate_root_goal_for_proof_tree_raw(
        self,
        canonical_goal: CanonicalInput<Self>,
    ) -> (QueryResult<Self>, Self::Probe);

    fn item_name(self, item_index: Self::DefId) -> Self::Symbol;
}

/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter`
/// that produces `T` items. You could combine them with
/// `f(&iter.collect::<Vec<_>>())`, but this requires allocating memory for the
/// `Vec`.
///
/// This trait allows for faster implementations, intended for cases where the
/// number of items produced by the iterator is small. There is a blanket impl
/// for `T` items, but there is also a fallible impl for `Result<T, E>` items.
pub trait CollectAndApply<T, R>: Sized {
    type Output;

    /// Produce a result of type `Self::Output` from `iter`. The result will
    /// typically be produced by applying `f` on the elements produced by
    /// `iter`, though this may not happen in some impls, e.g. if an error
    /// occurred during iteration.
    fn collect_and_apply<I, F>(iter: I, f: F) -> Self::Output
    where
        I: Iterator<Item = Self>,
        F: FnOnce(&[T]) -> R;
}

/// The blanket impl that always collects all elements and applies `f`.
impl<T, R> CollectAndApply<T, R> for T {
    type Output = R;

    /// Equivalent to `f(&iter.collect::<Vec<_>>())`.
    fn collect_and_apply<I, F>(mut iter: I, f: F) -> R
    where
        I: Iterator<Item = T>,
        F: FnOnce(&[T]) -> R,
    {
        // This code is hot enough that it's worth specializing for the most
        // common length lists, to avoid the overhead of `Vec` creation.

        let Some(t0) = iter.next() else {
            return f(&[]);
        };

        let Some(t1) = iter.next() else {
            return f(&[t0]);
        };

        let Some(t2) = iter.next() else {
            return f(&[t0, t1]);
        };

        let Some(t3) = iter.next() else {
            return f(&[t0, t1, t2]);
        };

        let Some(t4) = iter.next() else {
            return f(&[t0, t1, t2, t3]);
        };

        let Some(t5) = iter.next() else {
            return f(&[t0, t1, t2, t3, t4]);
        };

        let Some(t6) = iter.next() else {
            return f(&[t0, t1, t2, t3, t4, t5]);
        };

        let Some(t7) = iter.next() else {
            return f(&[t0, t1, t2, t3, t4, t5, t6]);
        };

        let Some(t8) = iter.next() else {
            return f(&[t0, t1, t2, t3, t4, t5, t6, t7]);
        };

        f(&[t0, t1, t2, t3, t4, t5, t6, t7, t8].into_iter().chain(iter).collect::<Vec<_>>())
    }
}

/// A fallible impl that will fail, without calling `f`, if there are any
/// errors during collection.
impl<T, R, E> CollectAndApply<T, R> for Result<T, E> {
    type Output = Result<R, E>;

    /// Equivalent to `Ok(f(&iter.collect::<Result<Vec<_>>>()?))`.
    fn collect_and_apply<I, F>(mut iter: I, f: F) -> Result<R, E>
    where
        I: Iterator<Item = Result<T, E>>,
        F: FnOnce(&[T]) -> R,
    {
        // This code is hot enough that it's worth specializing for the most
        // common length lists, to avoid the overhead of `Vec` creation.

        let Some(t0) = iter.next() else {
            return Ok(f(&[]));
        };
        let t0 = t0?;

        let Some(t1) = iter.next() else {
            return Ok(f(&[t0]));
        };
        let t1 = t1?;

        let Some(t2) = iter.next() else {
            return Ok(f(&[t0, t1]));
        };
        let t2 = t2?;

        let Some(t3) = iter.next() else {
            return Ok(f(&[t0, t1, t2]));
        };
        let t3 = t3?;

        let Some(t4) = iter.next() else {
            return Ok(f(&[t0, t1, t2, t3]));
        };
        let t4 = t4?;

        let Some(t5) = iter.next() else {
            return Ok(f(&[t0, t1, t2, t3, t4]));
        };
        let t5 = t5?;

        let Some(t6) = iter.next() else {
            return Ok(f(&[t0, t1, t2, t3, t4, t5]));
        };
        let t6 = t6?;

        let Some(t7) = iter.next() else {
            return Ok(f(&[t0, t1, t2, t3, t4, t5, t6]));
        };
        let t7 = t7?;

        let Some(t8) = iter.next() else {
            return Ok(f(&[t0, t1, t2, t3, t4, t5, t6, t7]));
        };
        let t8 = t8?;

        Ok(f(&[Ok(t0), Ok(t1), Ok(t2), Ok(t3), Ok(t4), Ok(t5), Ok(t6), Ok(t7), Ok(t8)]
            .into_iter()
            .chain(iter)
            .collect::<Result<Vec<_>, _>>()?))
    }
}

impl<I: Interner> search_graph::Cx for I {
    type Input = CanonicalInput<I>;
    type Result = (QueryResult<I>, AccessedOpaques<I>);
    type AmbiguityInfo = Certainty;

    type DepNodeIndex = I::DepNodeIndex;
    type Tracked<T: Debug + Clone> = I::Tracked<T>;
    fn mk_tracked<T: Debug + Clone>(
        self,
        data: T,
        dep_node_index: I::DepNodeIndex,
    ) -> I::Tracked<T> {
        I::mk_tracked(self, data, dep_node_index)
    }
    fn get_tracked<T: Debug + Clone>(self, tracked: &I::Tracked<T>) -> T {
        I::get_tracked(self, tracked)
    }
    fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, I::DepNodeIndex) {
        I::with_cached_task(self, task)
    }
    fn with_global_cache<R>(self, f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R) -> R {
        I::with_global_cache(self, f)
    }
    fn assert_evaluation_is_concurrent(&self) {
        self.assert_evaluation_is_concurrent()
    }
}