1use std::fmt::Debug;
7use std::hash::Hash;
8
9use rustc_ast_ir::Mutability;
10
11use crate::elaborate::Elaboratable;
12use crate::fold::{TypeFoldable, TypeSuperFoldable};
13use crate::relate::Relate;
14use crate::solve::{AdtDestructorKind, SizedTraitKind};
15use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
16use crate::{
17 self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, UpcastFrom,
18};
19
20#[rust_analyzer::prefer_underscore_import]
21pub trait Ty<I: Interner<Ty = Self>>:
22 Copy
23 + Debug
24 + Hash
25 + Eq
26 + Into<I::GenericArg>
27 + Into<I::Term>
28 + IntoKind<Kind = ty::TyKind<I>>
29 + TypeSuperVisitable<I>
30 + TypeSuperFoldable<I>
31 + Relate<I>
32 + Flags
33{
34 fn new_unit(interner: I) -> Self;
35
36 fn new_bool(interner: I) -> Self;
37
38 fn new_u8(interner: I) -> Self;
39
40 fn new_usize(interner: I) -> Self;
41
42 fn new_infer(interner: I, var: ty::InferTy) -> Self;
43
44 fn new_var(interner: I, var: ty::TyVid) -> Self;
45
46 fn new_param(interner: I, param: I::ParamTy) -> Self;
47
48 fn new_placeholder(interner: I, param: ty::PlaceholderType<I>) -> Self;
49
50 fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundTy<I>) -> Self;
51
52 fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
53
54 fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self;
55
56 fn new_alias(interner: I, alias_ty: ty::AliasTy<I>) -> Self;
57
58 fn new_projection_from_args(
59 interner: I,
60 def_id: I::TraitAssocTyId,
61 args: I::GenericArgs,
62 ) -> Self {
63 Self::new_alias(
64 interner,
65 ty::AliasTy::new_from_args(interner, ty::AliasTyKind::Projection { def_id }, args),
66 )
67 }
68
69 fn new_projection(
70 interner: I,
71 def_id: I::TraitAssocTyId,
72 args: impl IntoIterator<Item: Into<I::GenericArg>>,
73 ) -> Self {
74 Self::new_alias(
75 interner,
76 ty::AliasTy::new(interner, ty::AliasTyKind::Projection { def_id }, args),
77 )
78 }
79
80 fn new_error(interner: I, guar: I::ErrorGuaranteed) -> Self;
81
82 fn new_adt(interner: I, adt_def: I::AdtDef, args: I::GenericArgs) -> Self;
83
84 fn new_foreign(interner: I, def_id: I::ForeignId) -> Self;
85
86 fn new_dynamic(interner: I, preds: I::BoundExistentialPredicates, region: I::Region) -> Self;
87
88 fn new_coroutine(interner: I, def_id: I::CoroutineId, args: I::GenericArgs) -> Self;
89
90 fn new_coroutine_closure(
91 interner: I,
92 def_id: I::CoroutineClosureId,
93 args: I::GenericArgs,
94 ) -> Self;
95
96 fn new_closure(interner: I, def_id: I::ClosureId, args: I::GenericArgs) -> Self;
97
98 fn new_coroutine_witness(interner: I, def_id: I::CoroutineId, args: I::GenericArgs) -> Self;
99
100 fn new_coroutine_witness_for_coroutine(
101 interner: I,
102 def_id: I::CoroutineId,
103 coroutine_args: I::GenericArgs,
104 ) -> Self;
105
106 fn new_ptr(interner: I, ty: Self, mutbl: Mutability) -> Self;
107
108 fn new_ref(interner: I, region: I::Region, ty: Self, mutbl: Mutability) -> Self;
109
110 fn new_array_with_const_len(interner: I, ty: Self, len: I::Const) -> Self;
111
112 fn new_slice(interner: I, ty: Self) -> Self;
113
114 fn new_tup(interner: I, tys: &[I::Ty]) -> Self;
115
116 fn new_tup_from_iter<It, T>(interner: I, iter: It) -> T::Output
117 where
118 It: Iterator<Item = T>,
119 T: CollectAndApply<Self, Self>;
120
121 fn new_fn_def(interner: I, def_id: I::FunctionId, args: I::GenericArgs) -> Self;
122
123 fn new_fn_ptr(interner: I, sig: ty::Binder<I, ty::FnSig<I>>) -> Self;
124
125 fn new_pat(interner: I, ty: Self, pat: I::Pat) -> Self;
126
127 fn new_unsafe_binder(interner: I, ty: ty::Binder<I, I::Ty>) -> Self;
128
129 fn tuple_fields(self) -> I::Tys;
130
131 fn to_opt_closure_kind(self) -> Option<ty::ClosureKind>;
132
133 fn from_closure_kind(interner: I, kind: ty::ClosureKind) -> Self;
134
135 fn from_coroutine_closure_kind(interner: I, kind: ty::ClosureKind) -> Self;
136
137 fn is_ty_var(self) -> bool {
138 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::Infer(ty::TyVar(_)) => true,
_ => false,
}matches!(self.kind(), ty::Infer(ty::TyVar(_)))
139 }
140
141 fn is_ty_error(self) -> bool {
142 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::Error(_) => true,
_ => false,
}matches!(self.kind(), ty::Error(_))
143 }
144
145 fn is_floating_point(self) -> bool {
146 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::Float(_) | ty::Infer(ty::FloatVar(_)) => true,
_ => false,
}matches!(self.kind(), ty::Float(_) | ty::Infer(ty::FloatVar(_)))
147 }
148
149 fn is_integral(self) -> bool {
150 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::Infer(ty::IntVar(_)) | ty::Int(_) | ty::Uint(_) => true,
_ => false,
}matches!(self.kind(), ty::Infer(ty::IntVar(_)) | ty::Int(_) | ty::Uint(_))
151 }
152
153 fn is_fn_ptr(self) -> bool {
154 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::FnPtr(..) => true,
_ => false,
}matches!(self.kind(), ty::FnPtr(..))
155 }
156
157 fn has_unsafe_fields(self) -> bool;
159
160 fn fn_sig(self, interner: I) -> ty::Binder<I, ty::FnSig<I>> {
161 self.kind().fn_sig(interner)
162 }
163
164 fn discriminant_ty(self, interner: I) -> I::Ty;
165
166 fn is_known_rigid(self) -> bool {
167 self.kind().is_known_rigid()
168 }
169
170 fn is_guaranteed_unsized_raw(self) -> bool {
171 match self.kind() {
172 ty::Dynamic(_, _) | ty::Slice(_) | ty::Str => true,
173 ty::Bool
174 | ty::Char
175 | ty::Int(_)
176 | ty::Uint(_)
177 | ty::Float(_)
178 | ty::Adt(_, _)
179 | ty::Foreign(_)
180 | ty::Array(_, _)
181 | ty::Pat(_, _)
182 | ty::RawPtr(_, _)
183 | ty::Ref(_, _, _)
184 | ty::FnDef(_, _)
185 | ty::FnPtr(_, _)
186 | ty::UnsafeBinder(_)
187 | ty::Closure(_, _)
188 | ty::CoroutineClosure(_, _)
189 | ty::Coroutine(_, _)
190 | ty::CoroutineWitness(_, _)
191 | ty::Never
192 | ty::Tuple(_)
193 | ty::Alias(_)
194 | ty::Param(_)
195 | ty::Bound(_, _)
196 | ty::Placeholder(_)
197 | ty::Infer(_)
198 | ty::Error(_) => false,
199 }
200 }
201}
202
203#[rust_analyzer::prefer_underscore_import]
204pub trait Tys<I: Interner<Tys = Self>>:
205 Copy + Debug + Hash + Eq + SliceLike<Item = I::Ty> + TypeFoldable<I> + Default
206{
207 fn inputs(self) -> I::FnInputTys;
208
209 fn output(self) -> I::Ty;
210}
211
212#[rust_analyzer::prefer_underscore_import]
213pub trait Safety<I: Interner<Safety = Self>>: Copy + Debug + Hash + Eq {
214 fn safe() -> Self;
216
217 fn unsafe_mode() -> Self;
219
220 fn is_safe(self) -> bool;
222
223 fn prefix_str(self) -> &'static str;
225}
226
227#[rust_analyzer::prefer_underscore_import]
228pub trait Region<I: Interner<Region = Self>>:
229 Copy
230 + Debug
231 + Hash
232 + Eq
233 + Into<I::GenericArg>
234 + IntoKind<Kind = ty::RegionKind<I>>
235 + Flags
236 + Relate<I>
237{
238 fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundRegion<I>) -> Self;
239
240 fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
241
242 fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self;
243
244 fn new_static(interner: I) -> Self;
245
246 fn new_placeholder(interner: I, var: ty::PlaceholderRegion<I>) -> Self;
247
248 fn is_bound(self) -> bool {
249 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::ReBound(..) => true,
_ => false,
}matches!(self.kind(), ty::ReBound(..))
250 }
251}
252
253#[rust_analyzer::prefer_underscore_import]
254pub trait Const<I: Interner<Const = Self>>:
255 Copy
256 + Debug
257 + Hash
258 + Eq
259 + Into<I::GenericArg>
260 + Into<I::Term>
261 + IntoKind<Kind = ty::ConstKind<I>>
262 + TypeSuperVisitable<I>
263 + TypeSuperFoldable<I>
264 + Relate<I>
265 + Flags
266{
267 fn new_infer(interner: I, var: ty::InferConst) -> Self;
268
269 fn new_var(interner: I, var: ty::ConstVid) -> Self;
270
271 fn new_bound(interner: I, debruijn: ty::DebruijnIndex, bound_const: ty::BoundConst<I>) -> Self;
272
273 fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
274
275 fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self;
276
277 fn new_placeholder(interner: I, param: ty::PlaceholderConst<I>) -> Self;
278
279 fn new_unevaluated(interner: I, uv: ty::UnevaluatedConst<I>) -> Self;
280
281 fn new_expr(interner: I, expr: I::ExprConst) -> Self;
282
283 fn new_error(interner: I, guar: I::ErrorGuaranteed) -> Self;
284
285 fn new_error_with_message(interner: I, msg: impl ToString) -> Self {
286 Self::new_error(interner, interner.delay_bug(msg))
287 }
288
289 fn is_ct_var(self) -> bool {
290 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::ConstKind::Infer(ty::InferConst::Var(_)) => true,
_ => false,
}matches!(self.kind(), ty::ConstKind::Infer(ty::InferConst::Var(_)))
291 }
292
293 fn is_ct_error(self) -> bool {
294 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::ConstKind::Error(_) => true,
_ => false,
}matches!(self.kind(), ty::ConstKind::Error(_))
295 }
296}
297
298#[rust_analyzer::prefer_underscore_import]
299pub trait ValueConst<I: Interner<ValueConst = Self>>: Copy + Debug + Hash + Eq {
300 fn ty(self) -> I::Ty;
301 fn valtree(self) -> I::ValTree;
302}
303
304#[rust_analyzer::prefer_underscore_import]
305pub trait ExprConst<I: Interner<ExprConst = Self>>: Copy + Debug + Hash + Eq + Relate<I> {
306 fn args(self) -> I::GenericArgs;
307}
308
309#[rust_analyzer::prefer_underscore_import]
310pub trait GenericsOf<I: Interner<GenericsOf = Self>> {
311 fn count(&self) -> usize;
312}
313
314#[rust_analyzer::prefer_underscore_import]
315pub trait GenericArg<I: Interner<GenericArg = Self>>:
316 Copy
317 + Debug
318 + Hash
319 + Eq
320 + IntoKind<Kind = ty::GenericArgKind<I>>
321 + TypeVisitable<I>
322 + Relate<I>
323 + From<I::Ty>
324 + From<I::Region>
325 + From<I::Const>
326 + From<I::Term>
327{
328 fn as_term(&self) -> Option<I::Term> {
329 match self.kind() {
330 ty::GenericArgKind::Lifetime(_) => None,
331 ty::GenericArgKind::Type(ty) => Some(ty.into()),
332 ty::GenericArgKind::Const(ct) => Some(ct.into()),
333 }
334 }
335
336 fn as_type(&self) -> Option<I::Ty> {
337 if let ty::GenericArgKind::Type(ty) = self.kind() { Some(ty) } else { None }
338 }
339
340 fn expect_ty(&self) -> I::Ty {
341 self.as_type().expect("expected a type")
342 }
343
344 fn as_const(&self) -> Option<I::Const> {
345 if let ty::GenericArgKind::Const(c) = self.kind() { Some(c) } else { None }
346 }
347
348 fn expect_const(&self) -> I::Const {
349 self.as_const().expect("expected a const")
350 }
351
352 fn as_region(&self) -> Option<I::Region> {
353 if let ty::GenericArgKind::Lifetime(c) = self.kind() { Some(c) } else { None }
354 }
355
356 fn expect_region(&self) -> I::Region {
357 self.as_region().expect("expected a const")
358 }
359
360 fn is_non_region_infer(self) -> bool {
361 match self.kind() {
362 ty::GenericArgKind::Lifetime(_) => false,
363 ty::GenericArgKind::Type(ty) => ty.is_ty_var(),
364 ty::GenericArgKind::Const(ct) => ct.is_ct_var(),
365 }
366 }
367}
368
369#[rust_analyzer::prefer_underscore_import]
370pub trait Term<I: Interner<Term = Self>>:
371 Copy + Debug + Hash + Eq + IntoKind<Kind = ty::TermKind<I>> + TypeFoldable<I> + Relate<I>
372{
373 fn as_type(&self) -> Option<I::Ty> {
374 if let ty::TermKind::Ty(ty) = self.kind() { Some(ty) } else { None }
375 }
376
377 fn expect_ty(&self) -> I::Ty {
378 self.as_type().expect("expected a type, but found a const")
379 }
380
381 fn as_const(&self) -> Option<I::Const> {
382 if let ty::TermKind::Const(c) = self.kind() { Some(c) } else { None }
383 }
384
385 fn expect_const(&self) -> I::Const {
386 self.as_const().expect("expected a const, but found a type")
387 }
388
389 fn is_infer(self) -> bool {
390 match self.kind() {
391 ty::TermKind::Ty(ty) => ty.is_ty_var(),
392 ty::TermKind::Const(ct) => ct.is_ct_var(),
393 }
394 }
395
396 fn is_error(self) -> bool {
397 match self.kind() {
398 ty::TermKind::Ty(ty) => ty.is_ty_error(),
399 ty::TermKind::Const(ct) => ct.is_ct_error(),
400 }
401 }
402
403 fn to_alias_term(self, interner: I) -> Option<ty::AliasTerm<I>> {
404 match self.kind() {
405 ty::TermKind::Ty(ty) => match ty.kind() {
406 ty::Alias(alias_ty) => Some(alias_ty.into()),
407 _ => None,
408 },
409 ty::TermKind::Const(ct) => match ct.kind() {
410 ty::ConstKind::Unevaluated(uv) => {
411 Some(ty::AliasTerm::from_unevaluated_const(interner, uv))
412 }
413 _ => None,
414 },
415 }
416 }
417}
418
419#[rust_analyzer::prefer_underscore_import]
420pub trait GenericArgs<I: Interner<GenericArgs = Self>>:
421 Copy + Debug + Hash + Eq + SliceLike<Item = I::GenericArg> + Default + Relate<I>
422{
423 fn rebase_onto(
424 self,
425 interner: I,
426 source_def_id: I::DefId,
427 target: I::GenericArgs,
428 ) -> I::GenericArgs;
429
430 fn type_at(self, i: usize) -> I::Ty;
431
432 fn region_at(self, i: usize) -> I::Region;
433
434 fn const_at(self, i: usize) -> I::Const;
435
436 fn identity_for_item(interner: I, def_id: I::DefId) -> I::GenericArgs;
437
438 fn extend_with_error(
439 interner: I,
440 def_id: I::DefId,
441 original_args: &[I::GenericArg],
442 ) -> I::GenericArgs;
443
444 fn split_closure_args(self) -> ty::ClosureArgsParts<I>;
445 fn split_coroutine_closure_args(self) -> ty::CoroutineClosureArgsParts<I>;
446 fn split_coroutine_args(self) -> ty::CoroutineArgsParts<I>;
447
448 fn as_closure(self) -> ty::ClosureArgs<I> {
449 ty::ClosureArgs { args: self }
450 }
451 fn as_coroutine_closure(self) -> ty::CoroutineClosureArgs<I> {
452 ty::CoroutineClosureArgs { args: self }
453 }
454 fn as_coroutine(self) -> ty::CoroutineArgs<I> {
455 ty::CoroutineArgs { args: self }
456 }
457}
458
459#[rust_analyzer::prefer_underscore_import]
460pub trait Predicate<I: Interner<Predicate = Self>>:
461 Copy
462 + Debug
463 + Hash
464 + Eq
465 + TypeSuperVisitable<I>
466 + TypeSuperFoldable<I>
467 + Flags
468 + UpcastFrom<I, ty::PredicateKind<I>>
469 + UpcastFrom<I, ty::Binder<I, ty::PredicateKind<I>>>
470 + UpcastFrom<I, ty::ClauseKind<I>>
471 + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
472 + UpcastFrom<I, I::Clause>
473 + UpcastFrom<I, ty::NormalizesTo<I>>
474 + UpcastFrom<I, ty::TraitRef<I>>
475 + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
476 + UpcastFrom<I, ty::TraitPredicate<I>>
477 + UpcastFrom<I, ty::OutlivesPredicate<I, I::Ty>>
478 + UpcastFrom<I, ty::OutlivesPredicate<I, I::Region>>
479 + IntoKind<Kind = ty::Binder<I, ty::PredicateKind<I>>>
480 + Elaboratable<I>
481{
482 fn as_clause(self) -> Option<I::Clause>;
483
484 fn as_normalizes_to(self) -> Option<ty::Binder<I, ty::NormalizesTo<I>>> {
485 let kind = self.kind();
486 match kind.skip_binder() {
487 ty::PredicateKind::NormalizesTo(pred) => Some(kind.rebind(pred)),
488 _ => None,
489 }
490 }
491
492 fn allow_normalization(self) -> bool {
493 match self.kind().skip_binder() {
494 PredicateKind::Clause(ClauseKind::WellFormed(_)) | PredicateKind::AliasRelate(..) => {
495 false
496 }
497 PredicateKind::Clause(ClauseKind::Trait(_))
498 | PredicateKind::Clause(ClauseKind::HostEffect(..))
499 | PredicateKind::Clause(ClauseKind::RegionOutlives(_))
500 | PredicateKind::Clause(ClauseKind::TypeOutlives(_))
501 | PredicateKind::Clause(ClauseKind::Projection(_))
502 | PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
503 | PredicateKind::Clause(ClauseKind::UnstableFeature(_))
504 | PredicateKind::DynCompatible(_)
505 | PredicateKind::Subtype(_)
506 | PredicateKind::Coerce(_)
507 | PredicateKind::Clause(ClauseKind::ConstEvaluatable(_))
508 | PredicateKind::ConstEquate(_, _)
509 | PredicateKind::NormalizesTo(..)
510 | PredicateKind::Ambiguous => true,
511 }
512 }
513}
514
515#[rust_analyzer::prefer_underscore_import]
516pub trait Clause<I: Interner<Clause = Self>>:
517 Copy
518 + Debug
519 + Hash
520 + Eq
521 + TypeFoldable<I>
522 + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
523 + UpcastFrom<I, ty::TraitRef<I>>
524 + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
525 + UpcastFrom<I, ty::TraitPredicate<I>>
526 + UpcastFrom<I, ty::Binder<I, ty::TraitPredicate<I>>>
527 + UpcastFrom<I, ty::ProjectionPredicate<I>>
528 + UpcastFrom<I, ty::Binder<I, ty::ProjectionPredicate<I>>>
529 + IntoKind<Kind = ty::Binder<I, ty::ClauseKind<I>>>
530 + Elaboratable<I>
531{
532 fn as_predicate(self) -> I::Predicate;
533
534 fn as_type_outlives_clause(self) -> Option<ty::Binder<I, ty::OutlivesPredicate<I, I::Ty>>> {
535 self.kind()
536 .map_bound(|clause| {
537 if let ty::ClauseKind::TypeOutlives(outlives) = clause {
538 Some(outlives)
539 } else {
540 None
541 }
542 })
543 .transpose()
544 }
545
546 fn as_trait_clause(self) -> Option<ty::Binder<I, ty::TraitPredicate<I>>> {
547 self.kind()
548 .map_bound(|clause| if let ty::ClauseKind::Trait(t) = clause { Some(t) } else { None })
549 .transpose()
550 }
551
552 fn as_host_effect_clause(self) -> Option<ty::Binder<I, ty::HostEffectPredicate<I>>> {
553 self.kind()
554 .map_bound(
555 |clause| if let ty::ClauseKind::HostEffect(t) = clause { Some(t) } else { None },
556 )
557 .transpose()
558 }
559
560 fn as_projection_clause(self) -> Option<ty::Binder<I, ty::ProjectionPredicate<I>>> {
561 self.kind()
562 .map_bound(
563 |clause| {
564 if let ty::ClauseKind::Projection(p) = clause { Some(p) } else { None }
565 },
566 )
567 .transpose()
568 }
569
570 fn instantiate_supertrait(self, cx: I, trait_ref: ty::Binder<I, ty::TraitRef<I>>) -> Self;
575}
576
577#[rust_analyzer::prefer_underscore_import]
578pub trait Clauses<I: Interner<Clauses = Self>>:
579 Copy
580 + Debug
581 + Hash
582 + Eq
583 + TypeSuperVisitable<I>
584 + TypeSuperFoldable<I>
585 + Flags
586 + SliceLike<Item = I::Clause>
587{
588}
589
590#[rust_analyzer::prefer_underscore_import]
591pub trait IntoKind {
592 type Kind;
593
594 fn kind(self) -> Self::Kind;
595}
596
597#[rust_analyzer::prefer_underscore_import]
598pub trait ParamLike: Copy + Debug + Hash + Eq {
599 fn index(self) -> u32;
600}
601
602#[rust_analyzer::prefer_underscore_import]
603pub trait AdtDef<I: Interner>: Copy + Debug + Hash + Eq {
604 fn def_id(self) -> I::AdtId;
605
606 fn is_struct(self) -> bool;
607
608 fn is_packed(self) -> bool;
609
610 fn struct_tail_ty(self, interner: I) -> Option<ty::EarlyBinder<I, I::Ty>>;
614
615 fn is_phantom_data(self) -> bool;
616
617 fn is_manually_drop(self) -> bool;
618
619 fn field_representing_type_info(
620 self,
621 interner: I,
622 args: I::GenericArgs,
623 ) -> Option<FieldInfo<I>>;
624
625 fn all_field_tys(self, interner: I) -> ty::EarlyBinder<I, impl IntoIterator<Item = I::Ty>>;
627
628 fn sizedness_constraint(
629 self,
630 interner: I,
631 sizedness: SizedTraitKind,
632 ) -> Option<ty::EarlyBinder<I, I::Ty>>;
633
634 fn is_fundamental(self) -> bool;
635
636 fn destructor(self, interner: I) -> Option<AdtDestructorKind>;
637}
638
639#[rust_analyzer::prefer_underscore_import]
640pub trait ParamEnv<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
641 fn caller_bounds(self) -> impl SliceLike<Item = I::Clause>;
642}
643
644#[rust_analyzer::prefer_underscore_import]
645pub trait Features<I: Interner>: Copy {
646 fn generic_const_exprs(self) -> bool;
647
648 fn generic_const_args(self) -> bool;
649
650 fn coroutine_clone(self) -> bool;
651
652 fn feature_bound_holds_in_crate(self, symbol: I::Symbol) -> bool;
653}
654
655#[rust_analyzer::prefer_underscore_import]
656pub trait DefId<I: Interner, Local = <I as Interner>::LocalDefId>:
657 Copy + Debug + Hash + Eq + TypeFoldable<I>
658{
659 fn is_local(self) -> bool;
660
661 fn as_local(self) -> Option<Local>;
662}
663
664pub trait SpecificDefId<I: Interner, Local = <I as Interner>::LocalDefId>:
665 DefId<I, Local> + Into<I::DefId> + TryFrom<I::DefId, Error: std::fmt::Debug>
666{
667}
668
669impl<
670 I: Interner,
671 T: DefId<I, Local> + Into<I::DefId> + TryFrom<I::DefId, Error: std::fmt::Debug>,
672 Local,
673> SpecificDefId<I, Local> for T
674{
675}
676
677#[rust_analyzer::prefer_underscore_import]
678pub trait BoundExistentialPredicates<I: Interner>:
679 Copy + Debug + Hash + Eq + Relate<I> + SliceLike<Item = ty::Binder<I, ty::ExistentialPredicate<I>>>
680{
681 fn principal_def_id(self) -> Option<I::TraitId>;
682
683 fn principal(self) -> Option<ty::Binder<I, ty::ExistentialTraitRef<I>>>;
684
685 fn auto_traits(self) -> impl IntoIterator<Item = I::TraitId>;
686
687 fn projection_bounds(
688 self,
689 ) -> impl IntoIterator<Item = ty::Binder<I, ty::ExistentialProjection<I>>>;
690}
691
692#[rust_analyzer::prefer_underscore_import]
693pub trait Span<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
694 fn dummy() -> Self;
695}
696
697#[rust_analyzer::prefer_underscore_import]
698pub trait OpaqueTypeStorageEntries: Debug + Copy + Default {
699 fn needs_reevaluation(self, canonicalized: usize) -> bool;
703}
704
705pub trait BoundVarKinds<I: Interner>:
706 Copy + Debug + Hash + Eq + SliceLike<Item = ty::BoundVariableKind<I>> + Default
707{
708 fn from_vars(cx: I, iter: impl IntoIterator<Item = ty::BoundVariableKind<I>>) -> Self;
709}
710
711pub trait SliceLike: Sized + Copy {
712 type Item: Copy;
713 type IntoIter: Iterator<Item = Self::Item> + DoubleEndedIterator;
714
715 fn iter(self) -> Self::IntoIter;
716
717 fn as_slice(&self) -> &[Self::Item];
718
719 fn get(self, idx: usize) -> Option<Self::Item> {
720 self.as_slice().get(idx).copied()
721 }
722
723 fn len(self) -> usize {
724 self.as_slice().len()
725 }
726
727 fn is_empty(self) -> bool {
728 self.len() == 0
729 }
730
731 fn contains(self, t: &Self::Item) -> bool
732 where
733 Self::Item: PartialEq,
734 {
735 self.as_slice().contains(t)
736 }
737
738 fn to_vec(self) -> Vec<Self::Item> {
739 self.as_slice().to_vec()
740 }
741
742 fn last(self) -> Option<Self::Item> {
743 self.as_slice().last().copied()
744 }
745
746 fn split_last(&self) -> Option<(&Self::Item, &[Self::Item])> {
747 self.as_slice().split_last()
748 }
749}
750
751impl<'a, T: Copy> SliceLike for &'a [T] {
752 type Item = T;
753 type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
754
755 fn iter(self) -> Self::IntoIter {
756 self.iter().copied()
757 }
758
759 fn as_slice(&self) -> &[Self::Item] {
760 *self
761 }
762}
763
764impl<'a, T: Copy, const N: usize> SliceLike for &'a [T; N] {
765 type Item = T;
766 type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
767
768 fn iter(self) -> Self::IntoIter {
769 self.into_iter().copied()
770 }
771
772 fn as_slice(&self) -> &[Self::Item] {
773 *self
774 }
775}
776
777impl<'a, S: SliceLike> SliceLike for &'a S {
778 type Item = S::Item;
779 type IntoIter = S::IntoIter;
780
781 fn iter(self) -> Self::IntoIter {
782 (*self).iter()
783 }
784
785 fn as_slice(&self) -> &[Self::Item] {
786 (*self).as_slice()
787 }
788}
789
790#[rust_analyzer::prefer_underscore_import]
791pub trait Symbol<I>: Copy + Hash + PartialEq + Eq + Debug {
792 fn is_kw_underscore_lifetime(self) -> bool;
793}